added code for handling messages that are only sent to the local WoN node
@@ -19,6 +19,7 @@ package won.bot.framework.eventbot.action.impl.wonmessage.execCommand;
import won.bot.framework.eventbot.EventListenerContext;
import won.bot.framework.eventbot.action.BaseEventBotAction;
import won.bot.framework.eventbot.action.EventBotActionUtils;
+import won.bot.framework.eventbot.event.ConnectionSpecificEvent;
import won.bot.framework.eventbot.event.Event;
import won.bot.framework.eventbot.event.NeedSpecificEvent;
import won.bot.framework.eventbot.event.RemoteNeedSpecificEvent;
@@ -34,13 +35,29 @@ import won.protocol.util.WonRdfUtils;
/**
* Action executing a MessageCommandEvent and publishing MessageCommandSuccess and MessageCommandFailure
* events indicating how well sending that message worked.
+ *
+ * The optional constructor parameter <code>messageIsSentToRemoteNode</code>, which defaults to true is used
+ * to determine if response listeners for a response from the remote node are to be registered
*/
public abstract class ExecuteSendMessageCommandAction<T extends MessageCommandEvent> extends BaseEventBotAction {
- public ExecuteSendMessageCommandAction(final EventListenerContext eventListenerContext) {
+ private boolean messageIsSentToRemoteNode = true;
+
+ protected ExecuteSendMessageCommandAction(EventListenerContext eventListenerContext, boolean messageIsSentToRemoteNode) {
super(eventListenerContext);
+ this.messageIsSentToRemoteNode = messageIsSentToRemoteNode;
+ }
+
+ public ExecuteSendMessageCommandAction(final EventListenerContext eventListenerContext) {
+ this(eventListenerContext, true);
}
+ /**
+ * Constructs the message via <code>createWonMessage</code> and registers a listener for the response from the
+ * local WoN node and, if <code>messageIsSenttoRemoteNode</code> is true, a listener for the response from the
+ * remote WoN node.
+ * @param event
+ */
@Override
public final void doRun(Event event) {
try {
@@ -73,6 +90,7 @@ public abstract class ExecuteSendMessageCommandAction<T extends MessageCommandEv
, getEventListenerContext());
//register listeners for the ResponseMessage generated by the remote WoN node
+ if (messageIsSentToRemoteNode) {
EventBotActionUtils.makeAndSubscribeRemoteResponseListener(message, responseEvent -> {
if (responseEvent instanceof SuccessResponseEvent) {
SuccessResponseEvent successEvent = (SuccessResponseEvent) responseEvent;
@@ -94,7 +112,7 @@ public abstract class ExecuteSendMessageCommandAction<T extends MessageCommandEv
}
}
, getEventListenerContext());
-
+ }
//send the message
getEventListenerContext().getWonMessageSender().sendWonMessage(message);
if (logger.isDebugEnabled()) {
@@ -144,6 +162,10 @@ public abstract class ExecuteSendMessageCommandAction<T extends MessageCommandEv
sb.append(" to need ")
.append(((RemoteNeedSpecificEvent) event).getRemoteNeedURI());
}
+ if (event instanceof ConnectionSpecificEvent) {
+ sb.append (" in connection " )
+ .append(((ConnectionSpecificEvent)event).getConnectionURI());
+ }
return sb.toString();
}
