use of won.bot.framework.eventbot.event.impl.monitor.CrawlReadyEvent in project webofneeds by researchstudio-sat.
the class ConversationBotMonitored 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, "Hello," + "I am the ConversationBot, a simple bot that will exchange " + "messages and deactivate its needs after some time."));
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 ConverssationBot."));
bus.subscribe(ConnectFromOtherNeedEvent.class, this.autoOpener);
// add a listener that auto-responds to messages by a message and at different stages of messages processing fires
// different monitoring events. After specified number of 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 AutomaticMonitoredMessageResponderListener(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, "Farewell!"));
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, "Farewell!"));
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 messaging work is done and connection messages linked data can be crawled
this.crawlReadySignaller = new ActionOnceAfterNEventsListener(ctx, NO_OF_NEEDS, new BaseEventBotAction(ctx) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
bus.publish(new CrawlReadyEvent());
}
});
bus.subscribe(NeedDeactivatedEvent.class, this.crawlReadySignaller);
// add a listener that, when crawl is done, tells the
// framework that the bot's work is done
this.workDoneSignaller = new ActionOnEventListener(ctx, new SignalWorkDoneAction(ctx));
bus.subscribe(CrawlDoneEvent.class, this.workDoneSignaller);
// add a listener that reacts to monitoring events
this.monitor = new ActionOnEventListener(ctx, "msgMonitor", new MessageLifecycleMonitoringAction(ctx));
bus.subscribe(MessageDispatchStartedEvent.class, this.monitor);
bus.subscribe(MessageDispatchedEvent.class, this.monitor);
bus.subscribe(SuccessResponseEvent.class, this.monitor);
bus.subscribe(MessageFromOtherNeedEvent.class, this.monitor);
bus.subscribe(CrawlReadyEvent.class, this.monitor);
}
Aggregations