Search in sources :

Example 1 with MessageDispatchStartedEvent

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());
    }
}
Also used : SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) MessageFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent) Stopwatch(org.javasimon.Stopwatch) CrawlDoneEvent(won.bot.framework.eventbot.event.impl.monitor.CrawlDoneEvent) MessageSpecificEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageSpecificEvent) URI(java.net.URI) DeliveryResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.DeliveryResponseEvent) CrawlReadyEvent(won.bot.framework.eventbot.event.impl.monitor.CrawlReadyEvent) MessageDispatchedEvent(won.bot.framework.eventbot.event.impl.monitor.MessageDispatchedEvent) MessageDispatchStartedEvent(won.bot.framework.eventbot.event.impl.monitor.MessageDispatchStartedEvent) WonMessage(won.protocol.message.WonMessage) Split(org.javasimon.Split) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)

Example 2 with MessageDispatchStartedEvent

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));
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) MessageDispatchedEvent(won.bot.framework.eventbot.event.impl.monitor.MessageDispatchedEvent) WonMessage(won.protocol.message.WonMessage) MessageDispatchStartedEvent(won.bot.framework.eventbot.event.impl.monitor.MessageDispatchStartedEvent) URI(java.net.URI) WonMessageBuilderException(won.protocol.exception.WonMessageBuilderException) Date(java.util.Date)

Aggregations

URI (java.net.URI)2 MessageDispatchStartedEvent (won.bot.framework.eventbot.event.impl.monitor.MessageDispatchStartedEvent)2 MessageDispatchedEvent (won.bot.framework.eventbot.event.impl.monitor.MessageDispatchedEvent)2 WonMessage (won.protocol.message.WonMessage)2 Date (java.util.Date)1 Split (org.javasimon.Split)1 Stopwatch (org.javasimon.Stopwatch)1 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 CrawlDoneEvent (won.bot.framework.eventbot.event.impl.monitor.CrawlDoneEvent)1 CrawlReadyEvent (won.bot.framework.eventbot.event.impl.monitor.CrawlReadyEvent)1 DeliveryResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.DeliveryResponseEvent)1 FailureResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent)1 MessageFromOtherAtomEvent (won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherAtomEvent)1 MessageSpecificEvent (won.bot.framework.eventbot.event.impl.wonmessage.MessageSpecificEvent)1 SuccessResponseEvent (won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent)1 WonMessageBuilderException (won.protocol.exception.WonMessageBuilderException)1