Search in sources :

Example 1 with HintFromMatcherEvent

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

the class FactoryHintCheckAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    if (!(event instanceof HintFromMatcherEvent) || !(getEventListenerContext().getBotContextWrapper() instanceof FactoryBotContextWrapper)) {
        logger.error("FactoryHintCheckAction can only handle HintFromMatcherEvent with FactoryBotContextWrapper");
        return;
    }
    FactoryBotContextWrapper botContextWrapper = (FactoryBotContextWrapper) getEventListenerContext().getBotContextWrapper();
    Match match = ((HintFromMatcherEvent) event).getMatch();
    URI ownUri = match.getFromNeed();
    URI requesterUri = match.getToNeed();
    if (botContextWrapper.isFactoryNeed(ownUri)) {
        logger.debug("FactoryHint for factoryURI: " + ownUri + " from the requesterUri: " + requesterUri);
        EventBus bus = getEventListenerContext().getEventBus();
        bus.publish(new FactoryHintEvent(requesterUri, ownUri));
    } else {
        logger.warn("NON FactoryHint for URI: " + ownUri + " from the requesterUri: " + requesterUri + " ignore the hint");
    }
}
Also used : HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) FactoryHintEvent(won.bot.framework.eventbot.event.impl.factory.FactoryHintEvent) EventBus(won.bot.framework.eventbot.bus.EventBus) URI(java.net.URI) FactoryBotContextWrapper(won.bot.framework.bot.context.FactoryBotContextWrapper) Match(won.protocol.model.Match)

Example 2 with HintFromMatcherEvent

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

the class Hint2MailParserAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    EventListenerContext ctx = getEventListenerContext();
    if (event instanceof HintFromMatcherEvent && ctx.getBotContextWrapper() instanceof MailBotContextWrapper) {
        MailBotContextWrapper botContextWrapper = (MailBotContextWrapper) ctx.getBotContextWrapper();
        Match match = ((HintFromMatcherEvent) event).getMatch();
        WonMessage message = ((HintFromMatcherEvent) event).getWonMessage();
        URI responseTo = match.getFromNeed();
        URI remoteNeedUri = match.getToNeed();
        MimeMessage originalMail = botContextWrapper.getMimeMessageForURI(responseTo);
        logger.debug("Found a hint for URI: " + responseTo + " sending a mail to the creator: " + MailContentExtractor.getFromAddressString(originalMail));
        WonMimeMessage answerMessage = mailGenerator.createHintMail(originalMail, remoteNeedUri);
        botContextWrapper.addMailIdWonURIRelation(answerMessage.getMessageID(), new WonURI(message.getReceiverURI(), UriType.CONNECTION));
        sendChannel.send(new GenericMessage<>(answerMessage));
    }
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) MailBotContextWrapper(won.bot.framework.bot.context.MailBotContextWrapper) MimeMessage(javax.mail.internet.MimeMessage) WonMessage(won.protocol.message.WonMessage) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI) Match(won.protocol.model.Match)

Example 3 with HintFromMatcherEvent

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

the class SendFeedbackForHintAction method doRun.

@Override
public void doRun(final Event event, EventListener executingListener) throws Exception {
    if (event instanceof HintFromMatcherEvent) {
        // TODO: the hint with a match object is not really suitable here. Would be better to
        // use connection object instead
        HintFromMatcherEvent hintEvent = (HintFromMatcherEvent) event;
        hintEvent.getWonMessage().getReceiverURI();
        boolean feedbackValue = random.nextBoolean();
        WonMessage message = createFeedbackMessage(hintEvent.getWonMessage().getReceiverURI(), feedbackValue);
        logger.debug("sending {} feedback for hint {} in message {}", new Object[] { (feedbackValue ? "positive" : "negative"), event, message.getMessageURI() });
        getEventListenerContext().getWonMessageSender().sendWonMessage(message);
    }
}
Also used : HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) WonMessage(won.protocol.message.WonMessage)

Example 4 with HintFromMatcherEvent

use of won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent 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("needHintFullRoundtrip");
    if (event instanceof NeedCreatedEvent) {
        Split split = stopwatch.start();
        needSplits.put(((NeedCreatedEvent) event).getNeedURI().toString(), split);
        logger.info("RECEIVED EVENT {} for uri {}", event, ((NeedCreatedEvent) event).getNeedURI().toString());
        long startTime = System.currentTimeMillis();
        String needUri = ((NeedCreatedEvent) event).getNeedURI().toString();
        needEventStartTime.put(needUri, startTime);
    } else if (event instanceof HintFromMatcherEvent) {
        logger.info("RECEIVED EVENT {} for uri {}", event, ((HintFromMatcherEvent) event).getMatch().getFromNeed().toString());
        long hintReceivedTime = System.currentTimeMillis();
        String needUri = ((HintFromMatcherEvent) event).getMatch().getFromNeed().toString();
        needSplits.get(((HintFromMatcherEvent) event).getMatch().getFromNeed().toString()).stop();
        if (hintEventReceivedTime.get(needUri) == null) {
            hintEventReceivedTime.put(needUri, new LinkedList<Long>());
        }
        hintEventReceivedTime.get(needUri).add(hintReceivedTime);
    }
    if (startTestTime == -1) {
        startTestTime = System.currentTimeMillis();
    }
    logger.info("Number of Needs: {}", needEventStartTime.size());
    logger.info("Number of Hints: {}", getTotalHints());
    logger.info("Number of Needs with Hints: {}", getNeedsWithHints());
    logger.info("Average Duration: {}", getAverageHintDuration());
    logger.info("Minimum Duration: {}", getMinHintDuration());
    logger.info("Maximum Duration: {}", getMaxHintDuration());
    logger.info("Needs with Hints per Second: {}", getNeedsWithNeedsPerSecond(startTestTime));
    logger.info("Hints per Second: {}", getHintsPerSecondThroughput(startTestTime));
}
Also used : HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) Stopwatch(org.javasimon.Stopwatch) Split(org.javasimon.Split) NeedCreatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent)

Example 5 with HintFromMatcherEvent

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

the class Hint2TelegramAction method doRun.

@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
    EventListenerContext ctx = getEventListenerContext();
    if (event instanceof HintFromMatcherEvent && ctx.getBotContextWrapper() instanceof TelegramBotContextWrapper) {
        TelegramBotContextWrapper botContextWrapper = (TelegramBotContextWrapper) ctx.getBotContextWrapper();
        Match match = ((HintFromMatcherEvent) event).getMatch();
        WonMessage wonMessage = ((HintFromMatcherEvent) event).getWonMessage();
        URI yourNeedUri = match.getFromNeed();
        URI remoteNeedUri = match.getToNeed();
        Long chatId = botContextWrapper.getChatIdForURI(yourNeedUri);
        if (chatId == null) {
            logger.error("No chatId found for the specified needUri");
            return;
        }
        try {
            Message message = wonTelegramBotHandler.sendMessage(wonTelegramBotHandler.getTelegramMessageGenerator().getHintMessage(chatId, remoteNeedUri, yourNeedUri));
            botContextWrapper.addMessageIdWonURIRelation(message.getMessageId(), new WonURI(wonMessage.getReceiverURI(), UriType.CONNECTION));
        } catch (TelegramApiException te) {
            logger.error(te.getMessage());
        }
    }
}
Also used : TelegramApiException(org.telegram.telegrambots.exceptions.TelegramApiException) EventListenerContext(won.bot.framework.eventbot.EventListenerContext) HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) TelegramBotContextWrapper(won.bot.framework.bot.context.TelegramBotContextWrapper) Message(org.telegram.telegrambots.api.objects.Message) WonMessage(won.protocol.message.WonMessage) WonMessage(won.protocol.message.WonMessage) WonURI(won.bot.framework.eventbot.action.impl.mail.model.WonURI) URI(java.net.URI) Match(won.protocol.model.Match)

Aggregations

HintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent)6 URI (java.net.URI)4 WonMessage (won.protocol.message.WonMessage)3 Match (won.protocol.model.Match)3 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)2 WonURI (won.bot.framework.eventbot.action.impl.mail.model.WonURI)2 MimeMessage (javax.mail.internet.MimeMessage)1 Split (org.javasimon.Split)1 Stopwatch (org.javasimon.Stopwatch)1 Message (org.telegram.telegrambots.api.objects.Message)1 TelegramApiException (org.telegram.telegrambots.exceptions.TelegramApiException)1 FactoryBotContextWrapper (won.bot.framework.bot.context.FactoryBotContextWrapper)1 MailBotContextWrapper (won.bot.framework.bot.context.MailBotContextWrapper)1 TelegramBotContextWrapper (won.bot.framework.bot.context.TelegramBotContextWrapper)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 ConnectionSpecificEvent (won.bot.framework.eventbot.event.ConnectionSpecificEvent)1 FactoryHintEvent (won.bot.framework.eventbot.event.impl.factory.FactoryHintEvent)1 NeedCreatedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent)1 ConnectFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent)1 OpenFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.OpenFromOtherNeedEvent)1