use of won.bot.framework.eventbot.listener.impl.ActionOnEventListener in project webofneeds by researchstudio-sat.
the class AnalyzeBehaviour method onActivate.
@Override
protected void onActivate(Optional<Object> message) {
ActionOnEventListener analyzeAction = new ActionOnEventListener(context, new AnalyzeAction(context));
this.subscribeWithAutoCleanup(MessageFromOtherNeedEvent.class, analyzeAction);
this.subscribeWithAutoCleanup(OpenFromOtherNeedEvent.class, analyzeAction);
this.subscribeWithAutoCleanup(ConnectionMessageCommandSuccessEvent.class, analyzeAction);
}
use of won.bot.framework.eventbot.listener.impl.ActionOnEventListener in project webofneeds by researchstudio-sat.
the class BehaviourBarrier method onActivate.
@Override
protected void onActivate(Optional<Object> message) {
Set<BotBehaviour> deactivatedBehaviours = Collections.synchronizedSet(new HashSet<>());
subscribeWithAutoCleanup(BotBehaviourDeactivatedEvent.class, new ActionOnEventListener(context, new EventFilter() {
@Override
public boolean accept(Event event) {
if (!(event instanceof BotBehaviourDeactivatedEvent))
return false;
return behavioursToWaitFor.contains(((BotBehaviourDeactivatedEvent) event).getBehaviour());
}
}, new BaseEventBotAction(context) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
synchronized (behavioursToWaitFor) {
deactivatedBehaviours.add(((BotBehaviourDeactivatedEvent) event).getBehaviour());
if (deactivatedBehaviours.containsAll(behavioursToWaitFor)) {
behavioursToStart.forEach(behaviour -> behaviour.activate());
deactivate();
}
}
}
}));
}
use of won.bot.framework.eventbot.listener.impl.ActionOnEventListener in project webofneeds by researchstudio-sat.
the class CoordinationBehaviour method onActivate.
@Override
protected void onActivate(Optional<Object> message) {
EventBotAction actionToExecute = null;
if (typeB == CoordinationType.ACTIVATE) {
actionToExecute = new BaseEventBotAction(context) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
BotBehaviourEvent botBehaviourEvent = (BotBehaviourEvent) event;
behaviourB.activate(botBehaviourEvent.getMessage());
deactivate(botBehaviourEvent.getMessage());
}
};
} else {
actionToExecute = new BaseEventBotAction(context) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
BotBehaviourEvent botBehaviourEvent = (BotBehaviourEvent) event;
behaviourB.deactivate(botBehaviourEvent.getMessage());
deactivate(botBehaviourEvent.getMessage());
}
};
}
Class<? extends Event> eventClazz = null;
if (typeA == CoordinationType.ACTIVATE) {
eventClazz = BotBehaviourActivatedEvent.class;
} else {
eventClazz = BotBehaviourDeactivatedEvent.class;
}
subscribeWithAutoCleanup(eventClazz, new ActionOnEventListener(context, new EventFilter() {
@Override
public boolean accept(Event event) {
return ((BotBehaviourEvent) event).getBehaviour() == behaviourA;
}
}, actionToExecute));
}
use of won.bot.framework.eventbot.listener.impl.ActionOnEventListener in project webofneeds by researchstudio-sat.
the class EagerlyPopulateCacheBehaviour method onActivate.
@Override
protected void onActivate(Optional<Object> message) {
logger.debug("activating EagerlyPopulateCacheBehaviour");
ProcessResponseAction processResponseAction = new ProcessResponseAction(context);
ProcessIncomingMessageAction processIncomingMessageAction = new ProcessIncomingMessageAction(context);
this.subscribeWithAutoCleanup(MessageFromOtherNeedEvent.class, new ActionOnEventListener(context, processIncomingMessageAction));
this.subscribeWithAutoCleanup(SuccessResponseEvent.class, new ActionOnEventListener(context, processResponseAction));
this.subscribeWithAutoCleanup(FailureResponseEvent.class, new ActionOnEventListener(context, processResponseAction));
}
use of won.bot.framework.eventbot.listener.impl.ActionOnEventListener 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);
}
Aggregations