@Override public void onThrowable(Throwable t) { if (decoratedAsyncHandler != null) { decoratedAsyncHandler.onThrowable(t); } else { logger.debug("", t); } }
public final void abort(final Throwable t) { if (terminateAndExit()) return; future.completeExceptionally(t); if (ON_THROWABLE_CALLED_FIELD.compareAndSet(this, 0, 1)) { try { asyncHandler.onThrowable(t); } catch (Throwable te) { LOGGER.debug("asyncHandler.onThrowable", te); } } }
protected AsyncHandler.State abort() { if (!delegateTerminated.getAndSet(true)) { // send a terminal event to the delegate // e.g. to trigger cleanup logic delegate().onThrowable(new UnsubscribedException()); } return State.ABORT; }
private <T> ListenableFuture<T> execute(Request request, final AsyncHandler<T> asyncHandler) { try { return requestSender.sendRequest(request, asyncHandler, null); } catch (Exception e) { asyncHandler.onThrowable(e); return new ListenableFuture.CompletedFailure<>(e); } }
@Override public void onThrowable(Throwable t) { if (delegateTerminated.getAndSet(true)) { return; } Throwable error = t; try { delegate().onThrowable(t); } catch (final Throwable x) { error = new CompositeException(Arrays.asList(t, x)); } emitOnError(error); }
/** * {@inheritDoc} * <p> * <p> * The exception will first be propagated to the wrapped {@code AsyncHandler}, then emitted via RxJava. If the * invocation of the delegate itself throws an exception, both the original exception and the follow-up exception * will be wrapped into RxJava's {@code CompositeException} and then be emitted. * </p> */ @Override public final void onThrowable(Throwable t) { if (delegateTerminated.getAndSet(true)) { return; } Throwable error = t; try { delegate().onThrowable(t); } catch (final Throwable x) { error = new CompositeException(Arrays.asList(t, x)); } emitOnError(error); }
private void loadContent() throws ExecutionException { if (future.isDone()) { try { future.get(); } catch (InterruptedException e) { throw new RuntimeException("unreachable", e); } } // No more retry CURRENT_RETRY_UPDATER.set(this, maxRetry); if (CONTENT_PROCESSED_FIELD.getAndSet(this, 1) == 0) { try { future.complete(asyncHandler.onCompleted()); } catch (Throwable ex) { if (ON_THROWABLE_CALLED_FIELD.getAndSet(this, 1) == 0) { try { try { asyncHandler.onThrowable(ex); } catch (Throwable t) { LOGGER.debug("asyncHandler.onThrowable", t); } } finally { cancelTimeouts(); } } future.completeExceptionally(ex); } } future.getNow(null); }
@Override public boolean cancel(boolean force) { releasePartitionKeyLock(); cancelTimeouts(); if (IS_CANCELLED_FIELD.getAndSet(this, 1) != 0) return false; // cancel could happen before channel was attached if (channel != null) { Channels.setDiscard(channel); Channels.silentlyCloseChannel(channel); } if (ON_THROWABLE_CALLED_FIELD.getAndSet(this, 1) == 0) { try { asyncHandler.onThrowable(new CancellationException()); } catch (Throwable t) { LOGGER.warn("cancel", t); } } future.cancel(false); return true; }
/** * Called to indicate that request processing is to be aborted because the linked Rx stream has been disposed. If * the {@link #delegate() delegate} didn't already receive a terminal event, * {@code AsyncHandler#onThrowable(Throwable) onThrowable} will be called with a {@link DisposedException}. * * @return always {@link State#ABORT} */ protected final AsyncHandler.State disposed() { if (!delegateTerminated.getAndSet(true)) { DisposedException disposed = sharedDisposed; if (disposed == null) { disposed = new DisposedException("Subscription has been disposed."); final StackTraceElement[] stackTrace = disposed.getStackTrace(); if (stackTrace.length > 0) { disposed.setStackTrace(new StackTraceElement[]{stackTrace[0]}); } sharedDisposed = disposed; } delegate().onThrowable(disposed); } return State.ABORT; }
@Test public void testCancel() { AsyncHandler<?> asyncHandler = mock(AsyncHandler.class); NettyResponseFuture<?> nettyResponseFuture = new NettyResponseFuture<>(null, asyncHandler, null, 3, null, null, null); boolean result = nettyResponseFuture.cancel(false); verify(asyncHandler).onThrowable(anyObject()); assertTrue(result, "Cancel should return true if the Future was cancelled successfully"); assertTrue(nettyResponseFuture.isCancelled(), "isCancelled should return true for a cancelled Future"); }
@Override public <T> ListenableFuture<T> executeRequest(Request request, AsyncHandler<T> handler) { if (config.getCookieStore() != null) { try { List<Cookie> cookies = config.getCookieStore().get(request.getUri()); if (!cookies.isEmpty()) { RequestBuilder requestBuilder = new RequestBuilder(request); for (Cookie cookie : cookies) { requestBuilder.addOrReplaceCookie(cookie); } request = requestBuilder.build(); } } catch (Exception e) { handler.onThrowable(e); return new ListenableFuture.CompletedFailure<>("Failed to set cookies of request", e); } } if (noRequestFilters) { return execute(request, handler); } else { FilterContext<T> fc = new FilterContext.FilterContextBuilder<T>().asyncHandler(handler).request(request).build(); try { fc = preProcessRequest(fc); } catch (Exception e) { handler.onThrowable(e); return new ListenableFuture.CompletedFailure<>("preProcessRequest failed", e); } return execute(fc.getRequest(), fc.getAsyncHandler()); } }
/** * {@inheritDoc} */ @Override public void onThrowable(Throwable t) { if (decoratedAsyncHandler != null) { decoratedAsyncHandler.onThrowable(t); } else { logger.debug("", t); } }
/** * {@inheritDoc} */ @Override public void onThrowable(Throwable t) { try { asyncHandler.onThrowable(t); } finally { complete(); } }
public final void abort(final Throwable t) { exEx.compareAndSet(null, new ExecutionException(t)); if (terminateAndExit()) return; if (onThrowableCalled.compareAndSet(false, true)) { try { asyncHandler.onThrowable(t); } catch (Throwable te) { LOGGER.debug("asyncHandler.onThrowable", te); } } latch.countDown(); runListeners(); }
public final void abort(final Throwable t) { exEx.compareAndSet(null, new ExecutionException(t)); if (terminateAndExit()) return; if (onThrowableCalled.compareAndSet(false, true)) { try { asyncHandler.onThrowable(t); } catch (Throwable te) { LOGGER.debug("asyncHandler.onThrowable", te); } } latch.countDown(); runListeners(); }
public final void abort(final Throwable t) { exEx.compareAndSet(null, new ExecutionException(t)); if (terminateAndExit()) return; if (onThrowableCalled.compareAndSet(false, true)) { try { asyncHandler.onThrowable(t); } catch (Throwable te) { LOGGER.debug("asyncHandler.onThrowable", te); } } latch.countDown(); runListeners(); }
@Override public <T> ListenableFuture<T> execute(Request request, final AsyncHandler<T> asyncHandler) { try { return requestSender.sendRequest(request, asyncHandler, null, false); } catch (Exception e) { asyncHandler.onThrowable(e); return new ListenableFuture.CompletedFailure<>(e); } }
@Override public <T> ListenableFuture<T> execute(Request request, final AsyncHandler<T> asyncHandler) { try { return requestSender.sendRequest(request, asyncHandler, null, false); } catch (Exception e) { asyncHandler.onThrowable(e); return new ListenableFuture.CompletedFailure<>(e); } }
@Override public <T> ListenableFuture<T> execute(Request request, final AsyncHandler<T> asyncHandler) { try { return requestSender.sendRequest(request, asyncHandler, null, false); } catch (Exception e) { asyncHandler.onThrowable(e); return new ListenableFuture.CompletedFailure<>(e); } }
@Override public <T> ListenableFuture<T> execute(Request request, final AsyncHandler<T> asyncHandler) { try { return requestSender.sendRequest(request, asyncHandler, null, false); } catch (Exception e) { asyncHandler.onThrowable(e); return new ListenableFuture.CompletedFailure<>(e); } }