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");
}
}
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));
}
}
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);
}
}
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));
}
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());
}
}
}
Aggregations