public synchronized boolean suspendContinuationIfNeeded() { if (!cont.isPending() && !resumedByApplication) { initialSuspend = false; cont.suspend(AsyncResponse.NO_TIMEOUT); return true; } else { return false; } }
private synchronized boolean doResumeFinal(Object response) { inMessage.getExchange().put(AsyncResponse.class, this); cont.setObject(response); resumedByApplication = true; if (!initialSuspend) { cont.resume(); } else { initialSuspend = false; } return true; }
public synchronized void handleTimeout() { if (!resumedByApplication) { if (pendingTimeout != null) { setAsyncResponseOnExchange(); cont.suspend(pendingTimeout); pendingTimeout = null; } else if (timeoutHandler != null) { timeoutHandler.handleTimeout(this); } else { cont.setObject(new ServiceUnavailableException()); } } }
public synchronized Object getResponseObject() { Object obj = cont.getObject(); if (!(obj instanceof Response) && !(obj instanceof Throwable)) { obj = Response.ok().entity(obj).build(); } return obj; }
@Override public synchronized boolean setTimeout(long time, TimeUnit unit) throws IllegalStateException { if (isCancelledOrNotSuspended()) { return false; } setAsyncResponseOnExchange(); long timeout = TimeUnit.MILLISECONDS.convert(time, unit); initialSuspend = false; if (!cont.isPending()) { cont.suspend(timeout); } else { pendingTimeout = timeout; cont.resume(); } return true; }
@Override public synchronized boolean isSuspended() { if (cancelled || resumedByApplication) { return false; } return initialSuspend || cont.isPending(); }
public void reset() { cont.reset(); }