/** * Creates a new ConversationMessage using an incoming message as a reference. * * @param inReplyTo * the incoming message. * * @return a ConversationMessage that will be routed to the MessageBus that * sent the {@code inReplyTo} message. */ public static ConversationMessage create(Message inReplyTo) { return new ConversationMessage(inReplyTo); }
@Override public MessageBuildSendable repliesTo(final MessageCallback callback) { reply = true; makeConversational(message, callback); return this; }
@Override public Message get() { return CommandMessage.create(); } };
/** * Creates a new ConversationMessage with the specified command type and * reference message. * * @param commandType * The command type for this message. Command is an optional * extension for creating services that can respond to different * specific commands. Must not be null. * @param inReplyTo * the incoming message. Must not be null. */ public static ConversationMessage create(String commandType, Message inReplyTo) { ConversationMessage message = new ConversationMessage(inReplyTo); message.command(commandType); return message; }
@Override public void sendNowWith(final MessageBus viaThis) { if (ConversationHelper.hasConversationCallback(this)) { ConversationHelper.createConversationService(viaThis, this); } viaThis.send(this); }
static void createConversationService(MessageBus bus, Message m) { if (m.isFlagSet(RoutingFlag.Conversational)) { final String replyService = m.getSubject() + ":" + count() + ":RespondTo:RPC"; bus.subscribe(replyService, new ServiceCanceller(bus.subscribe(replyService, m.getResource(MessageCallback.class, RES_NAME)))); m.set(MessageParts.ReplyTo, replyService); } }
/** * Creates a new CommandMessage with no parts and no provided parts. * * @return a new instance of CommandMessage. */ public static CommandMessage create() { return new CommandMessage(); }
@Override public <T> T getValue(Class<T> type) { return get(type, MessageParts.Value); }
@Override public Message copy(final Enum<?> part, final Message message) { set(part, message.get(Object.class, part)); return this; }
@Override public boolean isCommited() { return isFlagSet(RoutingFlag.Committed); }
@Override public String toString() { return buildDescription(); }
@Override public AsyncTask sendRepeatingWith(final RequestDispatcher viaThis, final TimeUnit unit, final int interval) { return _sendRepeatingWith(message, viaThis, unit, interval); }
@Override public AsyncTask sendDelayedWith(final RequestDispatcher viaThis, final TimeUnit unit, final int interval) { return _sendDelayedWith(message, viaThis, unit, interval); }
private Message getIncomingMessage() { return ((ConversationMessageWrapper) message).getIncomingMessage(); }
protected void maybeUnwrapAndThrowError(Throwable throwable) throws RuntimeException { while (throwable instanceof InvocationTargetException && throwable.getCause() != null) { throwable = throwable.getCause(); } throw (throwable instanceof RuntimeException) ? (RuntimeException) throwable : new MessageCallbackFailure(throwable); }
@Override public R done() { if (message.getErrorCallback() == null) { defaultErrorHandling(); } return (R) sendable; }
@Override public void sendNowWith(final MessageBus viaThis, final boolean fireMessageListener) { if (reply) createConversationService(viaThis, message); viaThis.send(message, false); }
@SuppressWarnings("unchecked") public static CommandMessage createWithPartsFromRawMap(final Map parts) { return new CommandMessage(parts); }
@Override @SuppressWarnings({ "UnusedDeclaration" }) public <T> T get(final Class<T> type, final Enum<?> part) { return get(type, part.toString()); }
@Override public Message copy(final String part, final Message message) { set(part, message.get(Object.class, part)); return this; }