Search in sources :

Example 16 with ActionOnEventListener

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);
}
Also used : ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener)

Example 17 with ActionOnEventListener

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();
                }
            }
        }
    }));
}
Also used : Event(won.bot.framework.eventbot.event.Event) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) EventListener(won.bot.framework.eventbot.listener.EventListener) EventFilter(won.bot.framework.eventbot.filter.EventFilter)

Example 18 with ActionOnEventListener

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));
}
Also used : BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) Event(won.bot.framework.eventbot.event.Event) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) EventListener(won.bot.framework.eventbot.listener.EventListener) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) EventFilter(won.bot.framework.eventbot.filter.EventFilter) EventBotAction(won.bot.framework.eventbot.action.EventBotAction) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction)

Example 19 with ActionOnEventListener

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));
}
Also used : ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener)

Example 20 with ActionOnEventListener

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);
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) BaseEventListener(won.bot.framework.eventbot.listener.BaseEventListener) EventBus(won.bot.framework.eventbot.bus.EventBus) OpenConnectionAction(won.bot.framework.eventbot.action.impl.wonmessage.OpenConnectionAction) SignalWorkDoneAction(won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction) DeactivateAllNeedsAction(won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsAction) ConnectFromListToListAction(won.bot.framework.eventbot.action.impl.wonmessage.ConnectFromListToListAction) CommentBotContextWrapper(won.bot.framework.bot.context.CommentBotContextWrapper) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) BaseEvent(won.bot.framework.eventbot.event.BaseEvent) NeedDeactivatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent) ConnectFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent) OpenFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.OpenFromOtherNeedEvent) Event(won.bot.framework.eventbot.event.Event) ActEvent(won.bot.framework.eventbot.event.impl.lifecycle.ActEvent) NeedCreatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) BaseEventListener(won.bot.framework.eventbot.listener.BaseEventListener) EventListener(won.bot.framework.eventbot.listener.EventListener)

Aggregations

ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)28 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)22 EventBus (won.bot.framework.eventbot.bus.EventBus)19 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)17 EventListener (won.bot.framework.eventbot.listener.EventListener)17 Event (won.bot.framework.eventbot.event.Event)16 CreateNeedWithFacetsAction (won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction)15 SignalWorkDoneAction (won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction)14 ActionOnceAfterNEventsListener (won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener)14 ActEvent (won.bot.framework.eventbot.event.impl.lifecycle.ActEvent)11 BaseEventListener (won.bot.framework.eventbot.listener.BaseEventListener)11 ConnectFromListToListAction (won.bot.framework.eventbot.action.impl.wonmessage.ConnectFromListToListAction)10 NeedCreatedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent)9 OpenConnectionAction (won.bot.framework.eventbot.action.impl.wonmessage.OpenConnectionAction)8 URI (java.net.URI)6 DeactivateAllNeedsAction (won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsAction)6 ConnectFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.ConnectFromOtherNeedEvent)6 OpenFromOtherNeedEvent (won.bot.framework.eventbot.event.impl.wonmessage.OpenFromOtherNeedEvent)6 DeactivateAllNeedsOfListAction (won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsOfListAction)5 CloseConnectionAction (won.bot.framework.eventbot.action.impl.wonmessage.CloseConnectionAction)5