/** * Send a message to an address. The message is either an {@link IEnvelope} which contains an * {@link IInternalMessage} or a {@link Map} with an "address" parameter. This makes it easier to * support both dynamic Javascript messages and more type safe Java messages. * * <p>Send attaches a "replyTo" address and a correlationId to them message so that it returns the * the {@link IBpmScriptEngine} */ @SuppressWarnings("unchecked") public void send( final String fromPid, final String fromBranch, final String fromVersion, final String queueId, Object message) throws BpmScriptException { String correlationId = correlationIdFormatter.format(fromPid, fromBranch, fromVersion, queueId); if (message instanceof IEnvelope) { IEnvelope envelope = (IEnvelope) message; InvocationMessage invocationMessage = ((InvocationMessage) envelope.getMessage()); invocationMessage.setReplyTo(replyTo); invocationMessage.setCorrelationId(correlationId); String address = (String) envelope.getAddress(); sender.send(address, invocationMessage); } else { Map<String, Object> map = (Map<String, Object>) message; map.put("correlationId", correlationId); map.put("replyTo", replyTo); String address = (String) map.get("address"); MapInvocationMessage result = new MapInvocationMessage(map); if (address == null) { log.warn("address for message " + result.toString() + " is null"); } sender.send(address, result); } }
public void send(long timeout, IJavaMessageHandler<?> handler, Object... args) throws BpmScriptException { InvocationMessage invocationMessage = new InvocationMessage(); invocationMessage.setMethodName("sendFirst"); invocationMessage.setArgs(args); Envelope envelope = new Envelope("bpmscript-first", invocationMessage); this.channel.send(envelope, timeout, handler); }
/** * Sends a timeout message address to the {@link TimeoutAdapter} * * <p>Send attaches a "replyTo" address and a correlationId to them message so that it returns the * the {@link IBpmScriptEngine} */ public void sendTimeout( String fromPid, String fromBranch, String fromVersion, String queueId, long duration) throws BpmScriptException { InvocationMessage message = new InvocationMessage(); message.setArgs(duration); message.setReplyTo(replyTo); message.setCorrelationId( correlationIdFormatter.format(fromPid, fromBranch, fromVersion, queueId)); sender.send(timeoutAddress, message); }
/** * @see org.bpmscript.channel.ISendChannel#createCallback(java.lang.String, java.lang.String, * java.lang.String, java.lang.String, java.lang.Object) */ @SuppressWarnings("unchecked") public Object createCallback( String fromPid, String fromBranch, String fromVersion, String queueId, Object message) throws BpmScriptException { String correlationId = correlationIdFormatter.format(fromPid, fromBranch, fromVersion, queueId); if (message instanceof InvocationMessage) { InvocationMessage invocationMessage = ((InvocationMessage) message); invocationMessage.setReplyTo(replyTo); invocationMessage.setCorrelationId(correlationId); return invocationMessage; } else { Map<String, Object> map = (Map<String, Object>) message; map.put("correlationId", correlationId); map.put("replyTo", replyTo); MapInvocationMessage result = new MapInvocationMessage(map); return result; } }