use of won.bot.framework.eventbot.EventListenerContext in project webofneeds by researchstudio-sat.
the class CommentBot method initializeEventListeners.
@Override
protected void initializeEventListeners() {
EventListenerContext ctx = getEventListenerContext();
final EventBus bus = getEventBus();
CommentBotContextWrapper botContextWrapper = (CommentBotContextWrapper) getBotContextWrapper();
// create needs every trigger execution until 2 needs are created
this.needCreator = new ActionOnEventListener(ctx, new CreateNeedWithFacetsAction(ctx, botContextWrapper.getNeedCreateListName()), NO_OF_NEEDS);
bus.subscribe(ActEvent.class, this.needCreator);
// count until 1 need is created, then create a comment facet
this.commentFacetCreator = new ActionOnEventListener(ctx, new CreateNeedWithFacetsAction(ctx, botContextWrapper.getCommentListName(), FacetType.CommentFacet.getURI()), 1);
bus.subscribe(NeedCreatedEvent.class, this.commentFacetCreator);
this.needConnector = new ActionOnceAfterNEventsListener(ctx, 2, new ConnectFromListToListAction(ctx, botContextWrapper.getNeedCreateListName(), botContextWrapper.getCommentListName(), FacetType.OwnerFacet.getURI(), FacetType.CommentFacet.getURI(), MILLIS_BETWEEN_MESSAGES, "Hi, I am the " + "CommentBot."));
bus.subscribe(NeedCreatedEvent.class, this.needConnector);
this.autoOpener = new ActionOnEventListener(ctx, new OpenConnectionAction(ctx, "Hi!"));
bus.subscribe(OpenFromOtherNeedEvent.class, this.autoOpener);
bus.subscribe(ConnectFromOtherNeedEvent.class, this.autoOpener);
BaseEventListener assertionRunner = new ActionOnceAfterNEventsListener(ctx, 1, new BaseEventBotAction(ctx) {
@Override
protected void doRun(final Event event, EventListener executingListener) throws Exception {
executeAssertionsForEstablishedConnectionInternal(bus);
}
});
bus.subscribe(OpenFromOtherNeedEvent.class, assertionRunner);
// deactivate all needs when the assertion was executed
this.allNeedsDeactivator = new ActionOnEventListener(ctx, new DeactivateAllNeedsAction(ctx), 1);
bus.subscribe(AssertionsExecutedEvent.class, this.allNeedsDeactivator);
// add a listener that counts two NeedDeactivatedEvents and then tells the
// framework that the bot's work is done
this.workDoneSignaller = new ActionOnceAfterNEventsListener(ctx, 2, new SignalWorkDoneAction(ctx));
bus.subscribe(NeedDeactivatedEvent.class, this.workDoneSignaller);
}
use of won.bot.framework.eventbot.EventListenerContext in project webofneeds by researchstudio-sat.
the class ConversationBot method initializeEventListeners.
@Override
protected void initializeEventListeners() {
EventListenerContext ctx = getEventListenerContext();
EventBus bus = getEventBus();
// create needs every trigger execution until 2 needs are created
this.needCreator = new ActionOnEventListener(ctx, new CreateNeedWithFacetsAction(ctx, getBotContextWrapper().getNeedCreateListName()), NO_OF_NEEDS);
bus.subscribe(ActEvent.class, this.needCreator);
// count until 2 needs were created, then
// * connect the 2 needs
this.needConnector = new ActionOnceAfterNEventsListener(ctx, "needConnector", NO_OF_NEEDS, new ConnectFromListToListAction(ctx, ctx.getBotContextWrapper().getNeedCreateListName(), ctx.getBotContextWrapper().getNeedCreateListName(), FacetType.OwnerFacet.getURI(), FacetType.OwnerFacet.getURI(), MILLIS_BETWEEN_MESSAGES, "Hi, I am the ConversationBot."));
bus.subscribe(NeedCreatedEvent.class, this.needConnector);
// add a listener that is informed of the connect/open events and that auto-opens
// subscribe it to:
// * connect events - so it responds with open
// * open events - so it responds with open (if the open received was the first open, and we still need to accept the connection)
this.autoOpener = new ActionOnEventListener(ctx, new OpenConnectionAction(ctx, "Hi, I " + "am the ConversationBot, too!"));
bus.subscribe(ConnectFromOtherNeedEvent.class, this.autoOpener);
// add a listener that auto-responds to messages by a message
// after 10 messages, it unsubscribes from all events
// subscribe it to:
// * message events - so it responds
// * open events - so it initiates the chain reaction of responses
this.autoResponder = new AutomaticMessageResponderListener(ctx, NO_OF_MESSAGES, MILLIS_BETWEEN_MESSAGES);
bus.subscribe(OpenFromOtherNeedEvent.class, this.autoResponder);
bus.subscribe(MessageFromOtherNeedEvent.class, this.autoResponder);
// add a listener that closes the connection after it has seen 10 messages
this.connectionCloser = new ActionOnceAfterNEventsListener(ctx, NO_OF_MESSAGES, new CloseConnectionAction(ctx, "Bye!"));
bus.subscribe(MessageFromOtherNeedEvent.class, this.connectionCloser);
// add a listener that closes the connection when a failureEvent occurs
EventListener onFailureConnectionCloser = new ActionOnEventListener(ctx, new CloseConnectionAction(ctx, "Bye!"));
bus.subscribe(FailureResponseEvent.class, onFailureConnectionCloser);
// add a listener that auto-responds to a close message with a deactivation of both needs.
// subscribe it to:
// * close events
this.needDeactivator = new ActionOnEventListener(ctx, new DeactivateAllNeedsAction(ctx), 1);
bus.subscribe(CloseFromOtherNeedEvent.class, this.needDeactivator);
// add a listener that counts two NeedDeactivatedEvents and then tells the
// framework that the bot's work is done
this.workDoneSignaller = new ActionOnceAfterNEventsListener(ctx, NO_OF_NEEDS, new SignalWorkDoneAction(ctx));
bus.subscribe(NeedDeactivatedEvent.class, this.workDoneSignaller);
}
use of won.bot.framework.eventbot.EventListenerContext in project webofneeds by researchstudio-sat.
the class EchoBot method initializeEventListeners.
@Override
protected void initializeEventListeners() {
EventListenerContext ctx = getEventListenerContext();
EventBus bus = getEventBus();
// register with WoN nodes, be notified when new needs are created
RegisterMatcherAction registerMatcherAction = new RegisterMatcherAction(ctx);
this.matcherRegistrator = new ActionOnEventListener(ctx, registerMatcherAction, 1);
bus.subscribe(ActEvent.class, this.matcherRegistrator);
RandomDelayedAction delayedRegistration = new RandomDelayedAction(ctx, registrationMatcherRetryInterval, registrationMatcherRetryInterval, 0, registerMatcherAction);
ActionOnEventListener matcherRetryRegistrator = new ActionOnEventListener(ctx, delayedRegistration);
bus.subscribe(MatcherRegisterFailedEvent.class, matcherRetryRegistrator);
// create the echo need - if we're not reacting to the creation of our own echo need.
this.needCreator = new ActionOnEventListener(ctx, new NotFilter(new NeedUriInNamedListFilter(ctx, ctx.getBotContextWrapper().getNeedCreateListName())), prepareCreateNeedAction(ctx));
bus.subscribe(NeedCreatedEventForMatcher.class, this.needCreator);
// as soon as the echo need is created, connect to original
this.needConnector = new ActionOnEventListener(ctx, "needConnector", new RandomDelayedAction(ctx, 5000, 5000, 1, new ConnectWithAssociatedNeedAction(ctx, FacetType.OwnerFacet.getURI(), FacetType.OwnerFacet.getURI(), "Greetings! I am the EchoBot! I will repeat everything you say, which you might " + "find useful for testing purposes.")));
bus.subscribe(NeedCreatedEvent.class, this.needConnector);
// add a listener that auto-responds to messages by a message
// after 10 messages, it unsubscribes from all events
// subscribe it to:
// * message events - so it responds
// * open events - so it initiates the chain reaction of responses
this.autoResponder = new ActionOnEventListener(ctx, new RespondWithEchoToMessageAction(ctx));
bus.subscribe(OpenFromOtherNeedEvent.class, this.autoResponder);
bus.subscribe(MessageFromOtherNeedEvent.class, this.autoResponder);
bus.subscribe(CloseFromOtherNeedEvent.class, new ActionOnEventListener(ctx, new LogAction(ctx, "received close message from remote need.")));
}
use of won.bot.framework.eventbot.EventListenerContext in project webofneeds by researchstudio-sat.
the class Mail2WonBot method initializeEventListeners.
@Override
protected void initializeEventListeners() {
EventListenerContext ctx = getEventListenerContext();
mailGenerator.setEventListenerContext(ctx);
bus = getEventBus();
BotBehaviour connectBehaviour = new ConnectBehaviour(ctx);
connectBehaviour.activate();
BotBehaviour closeBehaviour = new CloseBevahiour(ctx);
closeBehaviour.activate();
BotBehaviour connectionMessageBehaviour = new ConnectionMessageBehaviour(ctx);
connectionMessageBehaviour.activate();
BotBehaviour deactivateNeedBehaviour = new DeactivateNeedBehaviour(ctx);
deactivateNeedBehaviour.activate();
// Mail initiated events
bus.subscribe(MailReceivedEvent.class, new ActionOnEventListener(ctx, "MailReceived", new MailParserAction(ctx, mailContentExtractor)));
bus.subscribe(CreateNeedFromMailEvent.class, new ActionOnEventListener(ctx, "CreateNeedFromMailEvent", new CreateNeedFromMailAction(ctx, mailContentExtractor)));
bus.subscribe(WelcomeMailEvent.class, new ActionOnEventListener(ctx, "WelcomeMailAction", new WelcomeMailAction(mailGenerator, sendEmailChannel)));
bus.subscribe(MailCommandEvent.class, new ActionOnEventListener(ctx, "MailCommandEvent", new MailCommandAction(ctx, mailContentExtractor)));
bus.subscribe(SubscribeUnsubscribeEvent.class, new ActionOnEventListener(ctx, "SubscribeUnsubscribeEvent", new SubscribeUnsubscribeAction(ctx)));
// WON initiated Events
bus.subscribe(HintFromMatcherEvent.class, new ActionOnEventListener(ctx, "HintReceived", new Hint2MailParserAction(mailGenerator, sendEmailChannel)));
bus.subscribe(ConnectFromOtherNeedEvent.class, new ActionOnEventListener(ctx, "ConnectReceived", new Connect2MailParserAction(mailGenerator, sendEmailChannel)));
bus.subscribe(MessageFromOtherNeedEvent.class, new ActionOnEventListener(ctx, "ReceivedTextMessage", new Message2MailAction(mailGenerator, sendEmailChannel)));
}
use of won.bot.framework.eventbot.EventListenerContext in project webofneeds by researchstudio-sat.
the class MatcherProtocolTestBot method initializeEventListeners.
@Override
protected void initializeEventListeners() {
EventListenerContext ctx = getEventListenerContext();
EventBus bus = getEventBus();
// subscribe this bot with the WoN nodes' 'new need' topic
RegisterMatcherAction registerMatcherAction = new RegisterMatcherAction(ctx);
this.matcherRegistrator = new ActionOnEventListener(ctx, registerMatcherAction, 1);
bus.subscribe(ActEvent.class, this.matcherRegistrator);
RandomDelayedAction delayedRegistration = new RandomDelayedAction(ctx, registrationMatcherRetryInterval, registrationMatcherRetryInterval, 0, registerMatcherAction);
ActionOnEventListener matcherRetryRegistrator = new ActionOnEventListener(ctx, delayedRegistration);
bus.subscribe(MatcherRegisterFailedEvent.class, matcherRetryRegistrator);
// create needs every trigger execution until 2 needs are created
this.needCreator = new ActionOnEventListener(ctx, new CreateNeedWithFacetsAction(ctx, getBotContextWrapper().getNeedCreateListName()), NO_OF_NEEDS);
bus.subscribe(MatcherRegisteredEvent.class, new ActionOnEventListener(ctx, new BaseEventBotAction(ctx) {
@Override
protected void doRun(final Event event, EventListener executingListener) throws Exception {
getEventListenerContext().getEventBus().subscribe(ActEvent.class, needCreator);
}
}, 1));
this.matcherNotifier = new ActionOnceAfterNEventsListener(ctx, 4, new LogAction(ctx, "Received all events for newly created needs."));
bus.subscribe(NeedCreatedEventForMatcher.class, matcherNotifier);
bus.subscribe(NeedCreatedEvent.class, matcherNotifier);
this.matcher = new ActionOnceAfterNEventsListener(ctx, NO_OF_NEEDS, new MatchNeedsAction(ctx));
// count until 1 need is created, then create a comment facet
bus.subscribe(NeedCreatedEvent.class, this.matcher);
this.allNeedsDeactivator = new ActionOnEventListener(ctx, new DeactivateAllNeedsAction(ctx), 1);
bus.subscribe(HintFromMatcherEvent.class, this.allNeedsDeactivator);
this.workDoneSignaller = new ActionOnceAfterNEventsListener(ctx, 4, new SignalWorkDoneAction(ctx));
bus.subscribe(NeedDeactivatedEvent.class, this.workDoneSignaller);
bus.subscribe(NeedDeactivatedEventForMatcher.class, this.workDoneSignaller);
}
Aggregations