protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) { if (result instanceof Observable) { final Observable<?> obs = (Observable<?>)result; final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); obs.subscribe(v -> asyncResponse.resume(v), t -> handleThrowable(asyncResponse, t)); return asyncResponse; } return null; }
protected AsyncResponseImpl checkFutureResponse(Message inMessage, Object result) { if (result instanceof CompletionStage) { final CompletionStage<?> stage = (CompletionStage<?>)result; final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); stage.whenComplete((v, t) -> { if (t instanceof CancellationException) { asyncResponse.cancel(); } else { asyncResponse.resume(v != null ? v : t); } }); return asyncResponse; } return null; }
@Override public boolean cancel() { return doCancel(null); }
private boolean isCancelledOrNotSuspended() { return isCancelled() || !isSuspended(); }
protected AsyncResponseImpl handleSingle(Message inMessage, Single<?> single) { final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); Disposable d = single.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse, t)); if (d == null) { throw new IllegalStateException("Subscribe did not return a Disposable"); } return asyncResponse; }
if (asyncResp != null) { AsyncResponseImpl asyncImpl = (AsyncResponseImpl)asyncResp; asyncImpl.prepareContinuation(); asyncImpl.handleTimeout(); return handleAsyncResponse(exchange, asyncImpl.getResponseObject());
if (!asyncResponse.isSuspended() && !asyncResponse.isResumedByApplication()) { asyncResponse.suspendContinuation(); providerFactory.clearThreadLocalProxies(); } else { result = handleAsyncResponse(exchange, asyncResponse.getResponseObject());
private Object handleThrowable(AsyncResponseImpl asyncResponse, Throwable t) { //TODO: if it is a Cancelation exception => asyncResponse.cancel(); asyncResponse.resume(t); return null; } }
if (asyncResp != null) { AsyncResponseImpl asyncImpl = (AsyncResponseImpl)asyncResp; asyncImpl.prepareContinuation(); try { asyncImpl.handleTimeout(); return handleAsyncResponse(exchange, asyncImpl); } catch (Throwable t) {
public void prepareContinuation() { initContinuation(); }
@Override public void resume(Object response) throws IllegalStateException { doResume(response); }
private synchronized void doCancel(String retryAfterHeader) { checkSuspended(); ResponseBuilder rb = Response.status(503); if (retryAfterHeader != null) { rb.header(HttpHeaders.RETRY_AFTER, retryAfterHeader); } doResume(rb.build()); cancelled = true; }
private boolean doCancel(String retryAfterHeader) { if (cancelled) { return true; } if (!isSuspended()) { return false; } cancelled = true; ResponseBuilder rb = Response.status(503); if (retryAfterHeader != null) { rb.header(HttpHeaders.RETRY_AFTER, retryAfterHeader); } doResumeFinal(rb.build()); return cancelled; }
private void checkSuspended() { if (!initialSuspend && !isSuspended()) { throw new IllegalStateException(); } }
private Object handleAsyncResponse(Exchange exchange, AsyncResponseImpl ar) { Object asyncObj = ar.getResponseObject(); if (asyncObj instanceof Throwable) { return handleAsyncFault(exchange, ar, (Throwable)asyncObj); } setResponseContentTypeIfNeeded(exchange.getInMessage(), asyncObj); return new MessageContentsList(asyncObj); }
protected AsyncResponseImpl handleFlowable(Message inMessage, Flowable<?> f) { final AsyncResponseImpl asyncResponse = new AsyncResponseImpl(inMessage); if (!isStreamingSubscriberUsed(f, asyncResponse, inMessage)) { Disposable d = f.subscribe(asyncResponse::resume, t -> handleThrowable(asyncResponse, t)); if (d == null) { throw new IllegalStateException("Subscribe did not return a Disposable"); } } return asyncResponse; }
private Object handleThrowable(AsyncResponseImpl asyncResponse, Throwable t) { //TODO: if it is a Cancelation exception => asyncResponse.cancel(); asyncResponse.resume(t); return null; } }
public void prepareContinuation() { initContinuation(); }