/** * Sends a unicast message to the target defined by msg.getDest() and returns a future * @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 * @return CompletableFuture<T> A future from which the result can be fetched, or null if the call was asynchronous * @throws Exception If there was problem sending the request, processing it at the receiver, or processing * it at the sender. {@link java.util.concurrent.Future#get()} will throw this exception */ public <T> CompletableFuture<T> sendMessageWithFuture(Address dest, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return sendMessageWithFuture(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 opts The options (e.g. blocking, timeout etc) * @return A future from which the result can be fetched. If the callee threw an invocation, an ExecutionException * will be thrown on calling Future.get(). If the invocation was asynchronous, null will be returned. * @throws Exception Thrown if the method invocation threw an exception */ public <T> CompletableFuture<T> callRemoteMethodWithFuture(Address dest, MethodCall call, RequestOptions opts) throws Exception { if(log.isTraceEnabled()) log.trace("dest=%s, method_call=%s, options=%s", dest, call, opts); Buffer buf=methodCallToBuffer(call, marshaller); return super.sendMessageWithFuture(dest, buf, opts); }
/** * Sends a unicast message to the target defined by msg.getDest() and returns a future * @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 * @return CompletableFuture<T> A future from which the result can be fetched, or null if the call was asynchronous * @throws Exception If there was problem sending the request, processing it at the receiver, or processing * it at the sender. {@link java.util.concurrent.Future#get()} will throw this exception */ public <T> CompletableFuture<T> sendMessageWithFuture(Address dest, byte[] data, int offset, int length, RequestOptions opts) throws Exception { return sendMessageWithFuture(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 opts The options (e.g. blocking, timeout etc) * @return A future from which the result can be fetched. If the callee threw an invocation, an ExecutionException * will be thrown on calling Future.get(). If the invocation was asynchronous, null will be returned. * @throws Exception Thrown if the method invocation threw an exception */ public <T> CompletableFuture<T> callRemoteMethodWithFuture(Address dest, MethodCall call, RequestOptions opts) throws Exception { if(log.isTraceEnabled()) log.trace("dest=%s, method_call=%s, options=%s", dest, call, opts); Buffer buf=methodCallToBuffer(call, marshaller); return super.sendMessageWithFuture(dest, buf, opts); }
@Override public <R> CommandResponse<R> execute(Command<R, C> command, Member member) throws Exception { Message message = this.createMessage(((AddressMember) member).getAddress(), command); // Use sendMessageWithFuture(...) instead of sendMessage(...) since we want to differentiate between sender exceptions and receiver exceptions Future<R> future = this.dispatcher.sendMessageWithFuture(message, this.createRequestOptions()); try { return new SimpleCommandResponse<>(future.get()); } catch (InterruptedException e) { return new ExceptionCommandResponse<>(new ExecutionException(e)); } catch (ExecutionException e) { return new ExceptionCommandResponse<>(e); } }