Sending UsageCommentEvent on ConnectCommandSuccessEvent uses wrong connection
Describe the bug
When a user requests a connection to a service atom, the connection needs to be accepted by responding with a ConnectCommandEvent. To subscribe to the ConnectCommandSuccessEvent for a single event using ActionOnFirstEventListener, the connection in the BaseEventBotAction is always the first one connected since the bot started and not the one that just connected.
To Reproduce Steps to reproduce the behavior:
- Create a new bot using the bot-skeleton
- Add a connect from other atom event handler
bus.subscribe(ConnectFromOtherAtomEvent.class, noInternalServiceAtomEventFilter, new OpenConnectionAction(ctx));
- In the class
OpenConnectionActionsend aConnectCommandEventas a response
final ConnectCommandEvent connectCommandEvent = new ConnectCommandEvent(
connectFromOtherAtomEvent.getRecipientSocket(),
connectFromOtherAtomEvent.getSenderSocket(), message);
- Await for connection result
bus.subscribe(ConnectCommandSuccessEvent.class, new ActionOnFirstEventListener(ctx, new CommandResultFilter(connectCommandEvent),
new BaseEventBotAction(ctx) {
@Override
protected void doRun(Event event, EventListener executingListener) {
...
}
}));
- Inside the
doRunsend theUsageCommandEventto the newly created connection
final ConnectCommandSuccessEvent successEvent = (ConnectCommandSuccessEvent) event;
logger.info(successEvent.getCon().toString());
UsageCommandEvent usageCommandEvent = new UsageCommandEvent(successEvent.getCon());
ctx.getEventBus().publish(usageCommandEvent);
Expected behavior
when sending the UsageCommandEvent, it should send it to the newly connected atom.
Screenshots Not available
Desktop (please complete the following information):
- OS: macOS Mojave 10.14.6
- Browser Google Chrome
- Version 77.0.3865.120
Smartphone (please complete the following information):
- Device: none
- OS: none
- Browser none
- Version none
Additional context We actually found this in the WoN-Hackathon 2019 when working on our PollVoteBot in the following branch:
https://github.com/WoN-Hackathon-2019/won-pollvotebot/tree/vote-service-atom-commands