public void transportClosed() { if(isDone()) return; completeExceptionally(new IllegalStateException("transport was closed")); corrDone(); }
public T join() { return around(super::join); }
/** * <b>Callback</b> (called by RequestCorrelator or Transport). * Adds a response to the response table. When all responses have been received, {@code execute()} returns. */ public void receiveResponse(Object response_value, Address sender, boolean is_exception) { if(isDone()) return; if(is_exception && response_value instanceof Throwable) completeExceptionally((Throwable)response_value); else complete((T)response_value); corrDone(); }
protected T getResult(Callable<T> supplier) throws Exception { try { T result=supplier.call(); if(result == null && !isDone()) throw new TimeoutException("timeout waiting for response from " + target + ", request: " + toString()); return result; } catch(ExecutionException ex) { Throwable exception=ex.getCause(); if(exception instanceof Error) throw (Error)exception; else if(exception instanceof RuntimeException) throw (RuntimeException)exception; else if(exception instanceof Exception) throw (Exception)exception; else throw new RuntimeException(exception); } finally { corrDone(); } } }
/** * 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 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, Buffer data, RequestOptions opts) throws Exception { if(dest == null) throw new IllegalArgumentException("message destination is null, cannot send message"); if(opts == null) { log.warn("request options were null, using default of sync"); opts=RequestOptions.SYNC(); } rpc_stats.add(RpcStats.Type.UNICAST, dest, opts.mode() != ResponseMode.GET_NONE, 0); if(opts.mode() == ResponseMode.GET_NONE) { corr.sendUnicastRequest(dest, data, null, opts); return null; } // if we get here, the RPC is synchronous UnicastRequest<T> req=new UnicastRequest<>(corr, dest, opts); req.execute(data, false); return req; }
@Override public T get() throws InterruptedException, ExecutionException { try { // Wait at most for the configured timeout // If the message was dropped by the receiver, this would otherwise block forever return super.get(super.options.timeout(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { // Auto-cancel on timeout this.cancel(true); throw new CancellationException(e.getLocalizedMessage()); } }
protected T around(Supplier<T> supplier) { try {return supplier.get();} finally {corrDone();} }
@Override public boolean completeExceptionally(Throwable exception) { return super.completeExceptionally((exception instanceof SuspectedException) ? new CancellationException() : exception); }
@GuardedBy("lock") public boolean responsesComplete() { return options.mode() == ResponseMode.GET_NONE || isDone(); }
public T waitForCompletion() throws Exception { return getResult(this::get); }
/** * <b>Callback</b> (called by RequestCorrelator or Transport). * Adds a response to the response table. When all responses have been received, {@code execute()} returns. */ public void receiveResponse(Object response_value, Address sender, boolean is_exception) { if(isDone()) return; if(is_exception && response_value instanceof Throwable) completeExceptionally((Throwable)response_value); else complete((T)response_value); corrDone(); }
protected T getResult(Callable<T> supplier) throws Exception { try { T result=supplier.call(); if(result == null && !isDone()) throw new TimeoutException("timeout waiting for response from " + target + ", request: " + toString()); return result; } catch(ExecutionException ex) { Throwable exception=ex.getCause(); if(exception instanceof Error) throw (Error)exception; else if(exception instanceof RuntimeException) throw (RuntimeException)exception; else if(exception instanceof Exception) throw (Exception)exception; else throw new RuntimeException(exception); } finally { corrDone(); } } }
UnicastRequest<T> req=new UnicastRequest<>(corr, dest, opts); long start=!rpc_stats.extendedStats()? 0 : System.nanoTime(); try { return req.execute(data, true);
@Override public T get() throws InterruptedException, ExecutionException { try { // Wait at most for the configured timeout // If the message was dropped by the receiver, this would otherwise block forever return super.get(super.options.timeout(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { // Auto-cancel on timeout this.cancel(true); throw new CancellationException(e.getLocalizedMessage()); } }
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { try { return super.get(timeout, unit); } finally { corrDone(); } }
@Override public boolean completeExceptionally(Throwable exception) { return super.completeExceptionally((exception instanceof SuspectedException) ? new CancellationException() : exception); }
@GuardedBy("lock") public boolean responsesComplete() { return options.mode() == ResponseMode.GET_NONE || isDone(); }
public T waitForCompletion() throws Exception { return getResult(this::get); }
/** * If the target address is not a member of the new view, we'll mark the response as suspected and unblock * the caller of execute() */ public void viewChange(View view) { if(view == null) return; // SiteAddresses are not checked as they might be in a different cluster if(!(target instanceof SiteAddress) && !view.containsMember(target) && !isDone()) { completeExceptionally(new SuspectedException(target)); corrDone(); } }