/** * Sends a unicast message and - depending on the options - returns a result * @param dest the target to which to send the unicast message. Must not be null. * @param data the payload to send * @param offset the offset at which the data starts * @param length the number of bytes to send * @param opts the options to be used * @return T the result. Null if the call is asynchronous (non-blocking) or if the response is null * @throws Exception If there was problem sending the request, processing it at the receiver, or processing * it at the sender. * @throws TimeoutException If the call didn't succeed within the timeout defined in options (if set) */ public <T> T sendMessage(Address dest, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return sendMessage(dest, new Buffer(data, offset, length), opts); }
/** * Invokes a method in a cluster member and - if blocking - returns the result * @param dest The target member on which to invoke the method * @param call The call to be invoked, including method are arguments * @param options The options (e.g. blocking, timeout etc) * @return The result. Null if the call is asynchronous (non-blocking) or if the method returns void * @throws Exception Thrown if the method invocation threw an exception, either at the caller or the callee */ public <T> T callRemoteMethod(Address dest, MethodCall call, RequestOptions options) throws Exception { Buffer buf=methodCallToBuffer(call, marshaller); T retval=super.sendMessage(dest, buf, options); if(log.isTraceEnabled()) log.trace("dest=%s, method_call=%s, options=%s, retval: %s", dest, call, options, retval); return retval; }
/** * Sends a unicast message and - depending on the options - returns a result * @param dest the target to which to send the unicast message. Must not be null. * @param data the payload to send * @param offset the offset at which the data starts * @param length the number of bytes to send * @param opts the options to be used * @return T the result. Null if the call is asynchronous (non-blocking) or if the response is null * @throws Exception If there was problem sending the request, processing it at the receiver, or processing * it at the sender. * @throws TimeoutException If the call didn't succeed within the timeout defined in options (if set) */ public <T> T sendMessage(Address dest, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return sendMessage(dest, new Buffer(data, offset, length), opts); }
public Object callRemoteMethod(Address dest, MethodCall method_call, int mode, long timeout, boolean oob) throws Throwable { byte[] buf=null; Message msg=null; Object retval=null; if(log.isTraceEnabled()) log.trace("dest=" + dest + ", method_call=" + method_call + ", mode=" + mode + ", timeout=" + timeout); buf=req_marshaller != null? req_marshaller.objectToByteBuffer(method_call) : Util.objectToByteBuffer(method_call); msg=new Message(dest, null, buf); if(oob) msg.setFlag(Message.OOB); retval=super.sendMessage(msg, mode, timeout); if(log.isTraceEnabled()) log.trace("retval: " + retval); if(retval instanceof Throwable) throw (Throwable)retval; return retval; }
/** * Invokes a method in a cluster member and - if blocking - returns the result * @param dest The target member on which to invoke the method * @param call The call to be invoked, including method are arguments * @param options The options (e.g. blocking, timeout etc) * @return The result. Null if the call is asynchronous (non-blocking) or if the method returns void * @throws Exception Thrown if the method invocation threw an exception, either at the caller or the callee */ public <T> T callRemoteMethod(Address dest, MethodCall call, RequestOptions options) throws Exception { Buffer buf=methodCallToBuffer(call, marshaller); T retval=super.sendMessage(dest, buf, options); if(log.isTraceEnabled()) log.trace("dest=%s, method_call=%s, options=%s, retval: %s", dest, call, options, retval); return retval; }
private Response send(Address address, Command command, long timeout) throws MessageException { try { Address sourceAddress = domainChannel.getAddress(); byte[] payload = helper.serialize(command); Message message = new Message(address, sourceAddress, payload); RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, timeout); Object val = domainDispatcher.sendMessage(message, options); assert val instanceof byte[] : " expected byte[] for response"; return (Response) helper.deserialize(((byte[]) val)); } catch (Exception e) { throw new MessageException("Error sending message to: " + runtimeName, e); } }
try { RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, timeout); Object o = dispatcher.sendMessage(message, options); if (o instanceof Exception) {
public Response sendSynchronous(String runtimeName, ResponseCommand command, long timeout) throws MessageException { try { byte[] payload = helper.serialize(command); View view = domainChannel.getView(); if (view == null) { throw new MessageException("Federation channel closed or not connected when sending message to: " + runtimeName); } Address address = helper.getRuntimeAddress(runtimeName, view); Message message = new Message(address, domainChannel.getAddress(), payload); RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, timeout); Object o = dispatcher.sendMessage(message, options); assert o instanceof byte[] : "Expected byte[] but was " + o; return (Response) helper.deserialize((byte[]) o); } catch (Exception e) { throw new MessageException("Error sending message to runtime: " + runtimeName, e); } }