Search in sources :

Example 1 with SocketHintFromMatcherEvent

use of won.bot.framework.eventbot.event.impl.wonmessage.SocketHintFromMatcherEvent in project webofneeds by researchstudio-sat.

the class OpenConnectionAction method doRun.

@Override
public void doRun(final Event event, EventListener executingListener) throws Exception {
    if (event instanceof ConnectFromOtherAtomEvent) {
        ConnectFromOtherAtomEvent connectEvent = (ConnectFromOtherAtomEvent) event;
        logger.debug("auto-replying to connect for connection {}", connectEvent.getConnectionURI());
        getEventListenerContext().getWonMessageSender().prepareAndSendMessage(createConnectWonMessage(connectEvent.getAtomURI(), connectEvent.getTargetAtomURI(), connectEvent.getRecipientSocket(), connectEvent.getSenderSocket()));
    } else if (event instanceof AtomHintFromMatcherEvent) {
        // TODO: the hint with a match object is not really suitable here. Would be
        // better to
        // use connection object instead
        AtomHintFromMatcherEvent hintEvent = (AtomHintFromMatcherEvent) event;
        logger.debug("ignore opening connection based on atom hint {} not possible", hintEvent);
    } else if (event instanceof SocketHintFromMatcherEvent) {
        // TODO: the hint with a match object is not really suitable here. Would be
        // better to
        // use connection object instead
        SocketHintFromMatcherEvent hintEvent = (SocketHintFromMatcherEvent) event;
        Optional<URI> recipientAtom = Optional.of(hintEvent.getRecipientAtom());
        Optional<URI> hintTargetAtom = Optional.of(hintEvent.getHintTargetAtom());
        if (!recipientAtom.isPresent()) {
            logger.info("could not get recipient atom for hint event {}, cannot connect", event);
            return;
        }
        if (!hintTargetAtom.isPresent()) {
            logger.info("could not get target atom for hint event {}, cannot connect", event);
            return;
        }
        logger.debug("opening connection based on hint {}", event);
        getEventListenerContext().getWonMessageSender().prepareAndSendMessage(createConnectWonMessage(recipientAtom.get(), hintTargetAtom.get(), hintEvent.getRecipientSocket(), (hintEvent.getHintTargetSocket())));
    }
}
Also used : ConnectFromOtherAtomEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent) SocketHintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.SocketHintFromMatcherEvent) URI(java.net.URI) AtomHintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.AtomHintFromMatcherEvent)

Example 2 with SocketHintFromMatcherEvent

use of won.bot.framework.eventbot.event.impl.wonmessage.SocketHintFromMatcherEvent in project webofneeds by researchstudio-sat.

the class MatchingLoadTestMonitorAction method doRun.

@Override
protected void doRun(final Event event, EventListener executingListener) throws Exception {
    Stopwatch stopwatch = SimonManager.getStopwatch("atomHintFullRoundtrip");
    if (event instanceof AtomCreatedEvent) {
        Split split = stopwatch.start();
        atomSplits.put(((AtomCreatedEvent) event).getAtomURI().toString(), split);
        logger.info("RECEIVED EVENT {} for uri {}", event, ((AtomCreatedEvent) event).getAtomURI().toString());
        long startTime = System.currentTimeMillis();
        String atomUri = ((AtomCreatedEvent) event).getAtomURI().toString();
        atomEventStartTime.put(atomUri, startTime);
    } else if (event instanceof AtomHintFromMatcherEvent) {
        String atomUri = ((AtomHintFromMatcherEvent) event).getRecipientAtom().toString();
        logger.info("RECEIVED EVENT {} for uri {}", event, atomUri);
        long hintReceivedTime = System.currentTimeMillis();
        atomSplits.get(atomUri).stop();
        hintEventReceivedTime.computeIfAbsent(atomUri, k -> new LinkedList<>());
        hintEventReceivedTime.get(atomUri).add(hintReceivedTime);
    } else if (event instanceof SocketHintFromMatcherEvent) {
        String atomUri = ((SocketHintFromMatcherEvent) event).getRecipientSocket().toString();
        logger.info("RECEIVED EVENT {} for uri {}", event, atomUri);
        long hintReceivedTime = System.currentTimeMillis();
        atomSplits.get(atomUri).stop();
        hintEventReceivedTime.computeIfAbsent(atomUri, k -> new LinkedList<>());
        hintEventReceivedTime.get(atomUri).add(hintReceivedTime);
    }
    if (startTestTime == -1) {
        startTestTime = System.currentTimeMillis();
    }
    logger.info("Number of Atoms: {}", atomEventStartTime.size());
    logger.info("Number of Hints: {}", getTotalHints());
    logger.info("Number of Atoms with Hints: {}", getAtomsWithHints());
    logger.info("Average Duration: {}", getAverageHintDuration());
    logger.info("Minimum Duration: {}", getMinHintDuration());
    logger.info("Maximum Duration: {}", getMaxHintDuration());
    logger.info("Atoms with Hints per Second: {}", getAtomsWithAtomsPerSecond(startTestTime));
    logger.info("Hints per Second: {}", getHintsPerSecondThroughput(startTestTime));
}
Also used : AtomCreatedEvent(won.bot.framework.eventbot.event.impl.atomlifecycle.AtomCreatedEvent) java.util(java.util) Logger(org.slf4j.Logger) Split(org.javasimon.Split) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) SocketHintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.SocketHintFromMatcherEvent) Stopwatch(org.javasimon.Stopwatch) SimonManager(org.javasimon.SimonManager) Event(won.bot.framework.eventbot.event.Event) EventListener(won.bot.framework.eventbot.listener.EventListener) AtomHintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.AtomHintFromMatcherEvent) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) SocketHintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.SocketHintFromMatcherEvent) Stopwatch(org.javasimon.Stopwatch) Split(org.javasimon.Split) AtomCreatedEvent(won.bot.framework.eventbot.event.impl.atomlifecycle.AtomCreatedEvent) AtomHintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.AtomHintFromMatcherEvent)

Aggregations

AtomHintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.AtomHintFromMatcherEvent)2 SocketHintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.SocketHintFromMatcherEvent)2 MethodHandles (java.lang.invoke.MethodHandles)1 URI (java.net.URI)1 java.util (java.util)1 SimonManager (org.javasimon.SimonManager)1 Split (org.javasimon.Split)1 Stopwatch (org.javasimon.Stopwatch)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)1 Event (won.bot.framework.eventbot.event.Event)1 AtomCreatedEvent (won.bot.framework.eventbot.event.impl.atomlifecycle.AtomCreatedEvent)1 ConnectFromOtherAtomEvent (won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherAtomEvent)1 EventListener (won.bot.framework.eventbot.listener.EventListener)1