Search in sources :

Example 1 with TwoPhaseCommitNoVoteDeactivateAllNeedsAction

use of won.bot.framework.eventbot.action.impl.facet.TwoPhaseCommitNoVoteDeactivateAllNeedsAction in project webofneeds by researchstudio-sat.

the class StandardTwoPhaseCommitNoVoteBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    EventListenerContext ctx = getEventListenerContext();
    EventBus bus = getEventBus();
    ParticipantCoordinatorBotContextWrapper botContextWrapper = (ParticipantCoordinatorBotContextWrapper) getBotContextWrapper();
    // create needs every trigger execution until noOfNeeds are created
    this.participantNeedCreator = new ActionOnEventListener(ctx, "participantCreator", new CreateNeedWithFacetsAction(ctx, botContextWrapper.getParticipantListName(), FacetType.ParticipantFacet.getURI()), noOfNeeds - 1);
    bus.subscribe(ActEvent.class, this.participantNeedCreator);
    // when done, create one coordinator need
    this.coordinatorNeedCreator = new ActionOnEventListener(ctx, "coordinatorCreator", new FinishedEventFilter(participantNeedCreator), new CreateNeedWithFacetsAction(ctx, botContextWrapper.getCoordinatorListName(), FacetType.CoordinatorFacet.getURI()), 1);
    bus.subscribe(FinishedEvent.class, this.coordinatorNeedCreator);
    // when done, connect the participants to the coordinator
    this.needConnector = new ActionOnceAfterNEventsListener(ctx, "needConnector", noOfNeeds, new ConnectFromListToListAction(ctx, botContextWrapper.getCoordinatorListName(), botContextWrapper.getParticipantListName(), FacetType.CoordinatorFacet.getURI(), FacetType.ParticipantFacet.getURI(), MILLIS_BETWEEN_MESSAGES, "Hi!"));
    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, "autoOpener", new OpenConnectionAction(ctx, "Hi!"));
    bus.subscribe(OpenFromOtherNeedEvent.class, this.autoOpener);
    bus.subscribe(ConnectFromOtherNeedEvent.class, this.autoOpener);
    this.autoCloser = new ActionOnceAfterNEventsListener(ctx, "autoCloser", noOfNeeds - 3, new CloseConnectionAction(ctx, "Bye!"));
    bus.subscribe(ConnectFromOtherNeedEvent.class, this.autoCloser);
    // after the last connect event, all connections are closed!
    this.needDeactivator = new ActionOnEventListener(ctx, new TwoPhaseCommitNoVoteDeactivateAllNeedsAction(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, noOfNeeds, 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) CloseConnectionAction(won.bot.framework.eventbot.action.impl.wonmessage.CloseConnectionAction) ConnectFromListToListAction(won.bot.framework.eventbot.action.impl.wonmessage.ConnectFromListToListAction) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) EventBus(won.bot.framework.eventbot.bus.EventBus) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) OpenConnectionAction(won.bot.framework.eventbot.action.impl.wonmessage.OpenConnectionAction) TwoPhaseCommitNoVoteDeactivateAllNeedsAction(won.bot.framework.eventbot.action.impl.facet.TwoPhaseCommitNoVoteDeactivateAllNeedsAction) SignalWorkDoneAction(won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction) FinishedEventFilter(won.bot.framework.eventbot.filter.impl.FinishedEventFilter) ParticipantCoordinatorBotContextWrapper(won.bot.framework.bot.context.ParticipantCoordinatorBotContextWrapper)

Aggregations

ParticipantCoordinatorBotContextWrapper (won.bot.framework.bot.context.ParticipantCoordinatorBotContextWrapper)1 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 TwoPhaseCommitNoVoteDeactivateAllNeedsAction (won.bot.framework.eventbot.action.impl.facet.TwoPhaseCommitNoVoteDeactivateAllNeedsAction)1 SignalWorkDoneAction (won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction)1 CreateNeedWithFacetsAction (won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction)1 CloseConnectionAction (won.bot.framework.eventbot.action.impl.wonmessage.CloseConnectionAction)1 ConnectFromListToListAction (won.bot.framework.eventbot.action.impl.wonmessage.ConnectFromListToListAction)1 OpenConnectionAction (won.bot.framework.eventbot.action.impl.wonmessage.OpenConnectionAction)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 FinishedEventFilter (won.bot.framework.eventbot.filter.impl.FinishedEventFilter)1 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)1 ActionOnceAfterNEventsListener (won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener)1