/** * <p>Returns whether or not this Request has been cancelled. This can be thought of as the {@link * Thread#isInterrupted()} of Requests - it does not enforce anything in ways of blocking the Request, it is simply * a signal to allow the developer to break early if the Request has already been dropped.</p> * * <p>This method will also return <em>true</em> if the Request has a non-null timeout, and that timeout has * expired.</p> * * <p>Finally, this method will also return <em>true</em> if this Request has a parent Request that has been * cancelled.</p> * * @return True if this Request has timed out or been cancelled. * @see #cancel() * @see #setTimeout(long, TimeUnit) */ public boolean isCancelled() { if (cancel) { return true; } if (timeout != null && timeRemaining(TimeUnit.MILLISECONDS) <= 0) { return true; } if (parent != null && parent.isCancelled()) { return true; } return false; }
@Override public ContentChannel handleRequest(final Request request, final ResponseHandler handler) { if (!(request instanceof MbusRequest)) { throw new RequestDeniedException(request); } final Message msg = ((MbusRequest)request).getMessage(); msg.getTrace().trace(6, "Request received by MbusClient."); msg.pushHandler(null); // save user context final Long timeout = request.timeRemaining(TimeUnit.MILLISECONDS); if (timeout != null) { msg.setTimeReceivedNow(); msg.setTimeRemaining(Math.max(1, timeout)); // negative or zero timeout has semantics } msg.setContext(handler); msg.pushHandler(this); queue.add((MbusRequest)request); return null; }