/** * <p>This is a convenience method for calling {@link CallStack#pop(Routable)} on the {@link CallStack} of this * Routable. It equals calling <code>routable.getCallStack().pop(routable)</code>.</p> * * @return The handler that was popped. * @see CallStack#pop(Routable) */ public ReplyHandler popHandler() { return callStack.pop(this); }
/** * Pushes the given reply handler onto the call stack of this routable, also storing the current context. * * @param handler The handler to push. */ public void pushHandler(ReplyHandler handler) { callStack.push(handler, context); }
/** * Discards this routable. Invoking this prevents the auto-generation of replies if you later discard the routable. * This is a required step to ensure safe shutdown if you need destroy a message bus instance while there are still * messages and replies alive in your application. */ public void discard() { context = null; callStack.clear(); trace.clear(); }
/** * Swaps the state that makes this routable unique to another routable. The state is what identifies a routable for * message bus, so only one message can ever have the same state. This function must be called explicitly when * cloning and copying messages. * * @param rhs The routable to swap state with. */ public void swapState(Routable rhs) { Object context = this.context; this.context = rhs.context; rhs.context = context; callStack.swap(rhs.getCallStack()); trace.swap(rhs.getTrace()); }
@Override public void handleReply(Reply reply) { if (reply.getContext() instanceof RequestMonitor) { ((RequestMonitor)reply.getContext()).replied(reply); } else { ReplyHandler handler = reply.getCallStack().pop(reply); handler.handleReply(reply); // not there yet } }