use of won.bot.framework.eventbot.event.impl.monitor.MessageDispatchStartedEvent in project webofneeds by researchstudio-sat.
the class MessageLifecycleMonitoringAction method doRun.
@Override
protected void doRun(final Event event, EventListener executingListener) throws Exception {
Stopwatch stopwatchB = SimonManager.getStopwatch("messageTripB");
Stopwatch stopwatchBC = SimonManager.getStopwatch("messageTripBC");
Stopwatch stopwatchBCD = SimonManager.getStopwatch("messageTripBCD");
Stopwatch stopwatchBCDE = SimonManager.getStopwatch("messageTripBCDE");
if (event instanceof MessageSpecificEvent) {
MessageSpecificEvent msgEvent = (MessageSpecificEvent) event;
URI msgURI = msgEvent.getMessageURI();
logger.debug("RECEIVED EVENT {} for uri {}", event, msgURI);
if (event instanceof MessageDispatchStartedEvent) {
Split splitB = stopwatchB.start();
Split splitBC = stopwatchBC.start();
Split splitBCD = stopwatchBCD.start();
Split splitBCDE = stopwatchBCDE.start();
msgSplitsB.put(msgURI.toString(), splitB);
msgSplitsBC.put(msgURI.toString(), splitBC);
msgSplitsBCD.put(msgURI.toString(), splitBCD);
msgSplitsBCDE.put(msgURI.toString(), splitBCDE);
connectionMsgUris.put(msgURI, msgEvent.getAtomURI());
} else if (event instanceof MessageDispatchedEvent) {
msgSplitsB.get(msgURI.toString()).stop();
}
} else if (event instanceof SuccessResponseEvent || event instanceof FailureResponseEvent) {
DeliveryResponseEvent responseEvent = (DeliveryResponseEvent) event;
if (connectionMsgUris.containsKey(responseEvent.getOriginalMessageURI())) {
responseMsgUris.put(responseEvent.getMessage().getMessageURI(), responseEvent.getAtomURI());
}
if (msgSplitsBC.get(responseEvent.getOriginalMessageURI().toString()) != null) {
logger.debug("RECEIVED RESPONSE EVENT {} for uri {}", event, responseEvent.getOriginalMessageURI());
msgSplitsBC.get(responseEvent.getOriginalMessageURI().toString()).stop();
}
} else if (event instanceof MessageFromOtherAtomEvent) {
WonMessage msg = ((MessageFromOtherAtomEvent) event).getWonMessage();
msgSplitsBCD.get(msg.getMessageURI()).stop();
connectionMsgUris.put(msg.getMessageURI(), msg.getRecipientAtomURI());
} else if (event instanceof CrawlReadyEvent) {
reportMessageSizes(connectionMsgUris, "Connection Messages");
reportMessageSizes(responseMsgUris, "Delivery Responses");
getEventListenerContext().getEventBus().publish(new CrawlDoneEvent());
}
}
use of won.bot.framework.eventbot.event.impl.monitor.MessageDispatchStartedEvent in project webofneeds by researchstudio-sat.
the class AutomaticMonitoredMessageResponderListener method handleMessageEvent.
private void handleMessageEvent(final ConnectionSpecificEvent messageEvent) {
getEventListenerContext().getTaskScheduler().schedule(() -> {
EventListenerContext ctx = getEventListenerContext();
String message = createMessage();
URI connectionUri = messageEvent.getConnectionURI();
WonMessage wonMessage = createWonMessage(connectionUri, message);
wonMessage = ctx.getWonMessageSender().prepareMessage(wonMessage);
logger.debug("sending message " + message);
try {
// fire start message sending monitor event (message sending includes signing)
ctx.getEventBus().publish(new MessageDispatchStartedEvent(wonMessage));
ctx.getWonMessageSender().sendMessage(wonMessage);
// fire message is sent monitor event
ctx.getEventBus().publish(new MessageDispatchedEvent(wonMessage));
} catch (Exception e) {
logger.warn("could not send message via connection {}", connectionUri, e);
}
}, new Date(System.currentTimeMillis() + this.millisTimeoutBeforeReply));
}
Aggregations