boolean notifyIfExpired() { if (msg.isExpired()) { Error error = new Error(ErrorCode.TIMEOUT, "Timed out in sendQ"); notifyComplete(new Result(error)); replyHandler.handleReply(createSendTimedoutReply(msg, error)); return true; } return false; }
Reply createSendTimedoutReply(Message msg, Error error) { Reply reply = new EmptyReply(); reply.setMessage(msg); reply.addError(error); msg.swapState(reply); return reply; }
/** * This method may only be invoked on a root node, as it passes the current reply to the member {@link * ReplyHandler}. */ private void notifySender() { reply.getTrace().swap(trace); handler.handleReply(reply); reply = null; }
/** * Internal method for forwarding a sequenced message to the underlying sender. * * @param msg The message to forward. */ private void sequencedSend(Message msg) { if (msg.getTrace().shouldTrace(TraceLevel.COMPONENT)) { msg.getTrace().trace(TraceLevel.COMPONENT, "Sequencer sending message with sequence id '" + msg.getContext() + "'."); } msg.pushHandler(this); sender.handleMessage(msg); }
/** * <p>Constructs and schedules a Reply containing an error to the handler of the given Message.</p> * * @param msg The message to reply to. * @param errCode The code of the error to set. * @param errMsg The message of the error to set. */ private void deliverError(Message msg, int errCode, String errMsg) { Reply reply = new EmptyReply(); reply.swapState(msg); reply.addError(new Error(errCode, errMsg)); deliverReply(reply, reply.popHandler()); }
public Builder(Routingtable config) { protocol(config.protocol()); for (Hop h : config.hop()) { hop(new Hop.Builder(h)); } for (Route r : config.route()) { route(new Route.Builder(r)); } }
public Builder(Hop config) { name(config.name()); selector(config.selector()); recipient(config.recipient()); ignoreresult(config.ignoreresult()); }
/** * <p>This is a convenience method to call {@link * #createSourceSession(SourceSessionParams)} with default values for the * {@link SourceSessionParams} object.</p> * * @param handler The reply handler to receive the replies for the session. * @return The created session. */ public SourceSession createSourceSession(ReplyHandler handler) { return createSourceSession(new SourceSessionParams().setReplyHandler(handler)); }
/** * Forwards a routable to the next hop in its route. This method will never block. * @param routable the routable to forward. */ public void forward(Routable routable) { if (routable instanceof Reply) { Reply reply = (Reply)routable; ReplyHandler handler = reply.popHandler(); handler.handleReply(reply); } else { routable.pushHandler(this); mbus.handleMessage((Message)routable); } }
/** * Sends a reply to a message. The reply will propagate back to the original sender, prefering the same route as it * used to reach the detination. * * @param reply The reply, created from the message this is a reply to. */ public void reply(Reply reply) { ReplyHandler handler = reply.popHandler(); handler.handleReply(reply); }
public Builder(MessagebusConfig config) { for (Routingtable r : config.routingtable()) { routingtable(new Routingtable.Builder(r)); } }
@Override public void processReply(Reply reply) { super.processReply(reply); if ( ! reply.hasErrors()) { ++numOk; } }
@Override public void handleMessage(Message msg) { if (resender != null && msg.hasBucketSequence()) { deliverError(msg, ErrorCode.SEQUENCE_ERROR, "Bucket sequences not supported when resender is enabled."); return; } SendProxy proxy = new SendProxy(this, net, resender); msn.deliverMessage(msg, proxy); }
boolean sendOrExpire() { if ( ! notifyIfExpired() ) { Result res = sendInternal(msg); if ( ! isSendQFull(res) ) { notifyComplete(res); } else { return false; } } return true; }
/** * 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()); }
/** * <p>Convenience method to post a {@link Task} that delivers a {@link * Reply} to a {@link ReplyHandler} to the queue of tasks to be * executed.</p> * * @param reply The reply to return. * @param handler The handler to return to. */ public void deliverReply(final Reply reply, final ReplyHandler handler) { enqueue(new ReplyTask(reply, handler)); }
/** * 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(); }
/** * <p>This is a convenience method to call {@link * #createSourceSession(SourceSessionParams)} by first assigning the reply * handler to the parameter object.</p> * * @param handler The reply handler to receive the replies for the session. * @param params The parameters to control the session. * @return The created session. */ public SourceSession createSourceSession(ReplyHandler handler, SourceSessionParams params) { return createSourceSession(new SourceSessionParams(params).setReplyHandler(handler)); }