Search in sources :

Example 11 with EventBus

use of won.bot.framework.eventbot.bus.EventBus in project webofneeds by researchstudio-sat.

the class LastSeenNeedsMatcherBot 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);
    bus.subscribe(NeedCreatedEventForMatcher.class, new ActionOnEventListener(ctx, "lastSeenNeedsMatcher", new BaseEventBotAction(ctx) {

        @Override
        protected void doRun(final Event event, EventListener executingListener) throws Exception {
            NeedCreatedEventForMatcher needCreatedEvent = (NeedCreatedEventForMatcher) event;
            URI currentNeedURI = needCreatedEvent.getNeedURI();
            URI lastNeedURI = lastNeedUriReference.getAndSet(currentNeedURI);
            URI originator = matcherUri;
            if (lastNeedURI == null) {
                logger.info("First invocation. Remembering {} for matching it later", currentNeedURI);
                return;
            } else {
                logger.info("Sending hint for {} and {}", currentNeedURI, lastNeedURI);
            }
            ctx.getMatcherProtocolNeedServiceClient().hint(currentNeedURI, lastNeedURI, 0.5, originator, null, createWonMessage(currentNeedURI, lastNeedURI, 0.5, originator));
            ctx.getMatcherProtocolNeedServiceClient().hint(lastNeedURI, currentNeedURI, 0.5, originator, null, createWonMessage(lastNeedURI, currentNeedURI, 0.5, originator));
        }
    }));
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) RegisterMatcherAction(won.bot.framework.eventbot.action.impl.matcher.RegisterMatcherAction) NeedCreatedEventForMatcher(won.bot.framework.eventbot.event.impl.matcher.NeedCreatedEventForMatcher) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) Event(won.bot.framework.eventbot.event.Event) ActEvent(won.bot.framework.eventbot.event.impl.lifecycle.ActEvent) MatcherRegisterFailedEvent(won.bot.framework.eventbot.event.impl.matcher.MatcherRegisterFailedEvent) EventBus(won.bot.framework.eventbot.bus.EventBus) 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) RandomDelayedAction(won.bot.framework.eventbot.action.impl.RandomDelayedAction) URI(java.net.URI)

Example 12 with EventBus

use of won.bot.framework.eventbot.bus.EventBus in project webofneeds by researchstudio-sat.

the class RandomSimulatorBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    final EventListenerContext ctx = getEventListenerContext();
    EventBus bus = getEventBus();
    final Counter needCreationSuccessfulCounter = new CounterImpl("needsCreated");
    final Counter needCreationFailedCounter = new CounterImpl("needCreationFailed");
    final Counter needCreationStartedCounter = new CounterImpl("creationStarted");
    final Counter creationUnfinishedCounter = new CounterImpl("creationUnfinished");
    // create the first need when the first actEvent happens
    this.groupMemberCreator = new ActionOnceAfterNEventsListener(ctx, "groupMemberCreator", 1, new MultipleActions(ctx, new IncrementCounterAction(ctx, needCreationStartedCounter), new IncrementCounterAction(ctx, creationUnfinishedCounter), new CreateNeedWithFacetsAction(ctx, getBotContextWrapper().getNeedCreateListName())));
    bus.subscribe(ActEvent.class, this.groupMemberCreator);
    // when a need is created (or it failed), decrement the creationUnfinishedCounter
    EventListener downCounter = new ActionOnEventListener(ctx, "downCounter", new DecrementCounterAction(ctx, creationUnfinishedCounter));
    // count a successful need creation
    bus.subscribe(NeedCreatedEvent.class, downCounter);
    // if a creation failed, we don't want to keep us from keeping the correct count
    bus.subscribe(NeedCreationFailedEvent.class, downCounter);
    // we count the one execution when the creator realizes that the producer is exhausted, we have to count down
    // once for that, too.
    bus.subscribe(NeedProducerExhaustedEvent.class, downCounter);
    // also, keep track of what worked and what didn't
    bus.subscribe(NeedCreationFailedEvent.class, new ActionOnEventListener(ctx, new IncrementCounterAction(ctx, needCreationFailedCounter)));
    bus.subscribe(NeedCreatedEvent.class, new ActionOnEventListener(ctx, new IncrementCounterAction(ctx, needCreationSuccessfulCounter)));
    // print a logging message every N needs
    bus.subscribe(NeedCreatedEvent.class, new ActionOnEventListener(ctx, "logger", new BaseEventBotAction(ctx) {

        int lastOutput = 0;

        @Override
        protected void doRun(final Event event, EventListener executingListener) throws Exception {
            int cnt = needCreationStartedCounter.getCount();
            int unfinishedCount = creationUnfinishedCounter.getCount();
            int successCnt = needCreationSuccessfulCounter.getCount();
            int failedCnt = needCreationFailedCounter.getCount();
            if (cnt - lastOutput >= 200) {
                logger.info("started creation of {} needs, creation not yet finished for {}. Successful: {}, failed: {}", new Object[] { cnt, unfinishedCount, successCnt, failedCnt });
                lastOutput = cnt;
            }
        }
    }));
    // each time a need was created, wait for a random interval, then create another one
    bus.subscribe(NeedCreatedEvent.class, new ActionOnEventListener(ctx, new RandomDelayedAction(ctx, MIN_NEXT_CREATION_TIMEOUT_MILLIS, MAX_NEXT_CREATION_TIMEOUT_MILLIS, this.hashCode(), new CreateNeedWithFacetsAction(ctx, getBotContextWrapper().getNeedCreateListName()))));
    // when a hint is received, connect fraction of the cases after a random timeout
    bus.subscribe(HintFromMatcherEvent.class, new ActionOnEventListener(ctx, "hint-reactor", new RandomDelayedAction(ctx, MIN_RECATION_TIMEOUT_MILLIS, MAX_REACTION_TIMEOUT_MILLIS, (long) this.hashCode(), new MultipleActions(ctx, new SendFeedbackForHintAction(ctx), new ProbabilisticSelectionAction(ctx, PROB_OPEN_ON_HINT, (long) this.hashCode(), new OpenConnectionAction(ctx, "Hi!"), new CloseConnectionAction(ctx, "Bye!"))))));
    // when an open or connect is received, send message or close randomly after a random timeout
    EventListener opener = new ActionOnEventListener(ctx, "open-reactor", new RandomDelayedAction(ctx, MIN_RECATION_TIMEOUT_MILLIS, MAX_REACTION_TIMEOUT_MILLIS, (long) this.hashCode(), new ProbabilisticSelectionAction(ctx, PROB_MESSAGE_ON_OPEN, (long) this.hashCode(), new OpenConnectionAction(ctx, "Hi!"), new CloseConnectionAction(ctx, "Bye!"))));
    bus.subscribe(OpenFromOtherNeedEvent.class, opener);
    bus.subscribe(ConnectFromOtherNeedEvent.class, opener);
    // when an open is received, send message or close randomly after a random timeout
    EventListener replyer = new ActionOnEventListener(ctx, "message-reactor", new RandomDelayedAction(ctx, MIN_RECATION_TIMEOUT_MILLIS, MAX_REACTION_TIMEOUT_MILLIS, (long) this.hashCode(), new ProbabilisticSelectionAction(ctx, PROB_MESSAGE_ON_MESSAGE, (long) this.hashCode(), new SendMessageAction(ctx), new CloseConnectionAction(ctx, "Bye!"))));
    bus.subscribe(MessageFromOtherNeedEvent.class, replyer);
    bus.subscribe(OpenFromOtherNeedEvent.class, replyer);
    // When the needproducer is exhausted, stop.
    this.workDoneSignaller = new ActionOnEventListener(ctx, "workDoneSignaller", new SignalWorkDoneAction(ctx), 1);
    bus.subscribe(NeedProducerExhaustedEvent.class, this.workDoneSignaller);
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) SendMessageAction(won.bot.framework.eventbot.action.impl.wonmessage.SendMessageAction) CloseConnectionAction(won.bot.framework.eventbot.action.impl.wonmessage.CloseConnectionAction) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) 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) CounterImpl(won.bot.framework.eventbot.action.impl.counter.CounterImpl) Counter(won.bot.framework.eventbot.action.impl.counter.Counter) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) MessageFromOtherNeedEvent(won.bot.framework.eventbot.event.impl.wonmessage.MessageFromOtherNeedEvent) NeedCreatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent) NeedCreationFailedEvent(won.bot.framework.eventbot.event.NeedCreationFailedEvent) HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) 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) NeedProducerExhaustedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedProducerExhaustedEvent) BaseEventListener(won.bot.framework.eventbot.listener.BaseEventListener) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) EventListener(won.bot.framework.eventbot.listener.EventListener) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) SendFeedbackForHintAction(won.bot.framework.eventbot.action.impl.wonmessage.SendFeedbackForHintAction) IncrementCounterAction(won.bot.framework.eventbot.action.impl.counter.IncrementCounterAction) DecrementCounterAction(won.bot.framework.eventbot.action.impl.counter.DecrementCounterAction)

Example 13 with EventBus

use of won.bot.framework.eventbot.bus.EventBus in project webofneeds by researchstudio-sat.

the class StandardTwoPhaseCommitBot 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);
    // wait for N NeedCreatedEvents
    creationWaiter = new WaitForNEventsListener(ctx, noOfNeeds);
    bus.subscribe(NeedCreatedEvent.class, creationWaiter);
    // when done, connect the participants to the coordinator
    this.needConnector = new ActionOnEventListener(ctx, "needConnector", new FinishedEventFilter(creationWaiter), new ConnectFromListToListAction(ctx, botContextWrapper.getCoordinatorListName(), botContextWrapper.getParticipantListName(), FacetType.CoordinatorFacet.getURI(), FacetType.ParticipantFacet.getURI(), MILLIS_BETWEEN_MESSAGES, "Hi!"), 1);
    bus.subscribe(FinishedEvent.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 NeedUriInNamedListFilter(ctx, botContextWrapper.getParticipantListName()), new OpenConnectionAction(ctx, "Hi!"));
    bus.subscribe(ConnectFromOtherNeedEvent.class, this.autoOpener);
    // after the last connect event, all connections are closed!
    this.participantDeactivator = new ActionOnEventListener(ctx, "participantDeactivator", new NeedUriInNamedListFilter(ctx, botContextWrapper.getParticipantListName()), new TwoPhaseCommitDeactivateOnCloseAction(ctx), noOfNeeds - 1);
    bus.subscribe(CloseFromOtherNeedEvent.class, this.participantDeactivator);
    coordinatorDeactivator = new ActionOnEventListener(ctx, "coordinatorDeactivator", new FinishedEventFilter(participantDeactivator), new DeactivateAllNeedsOfListAction(ctx, botContextWrapper.getCoordinatorListName()), 1);
    bus.subscribe(FinishedEvent.class, coordinatorDeactivator);
    // 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) TwoPhaseCommitDeactivateOnCloseAction(won.bot.framework.eventbot.action.impl.facet.TwoPhaseCommitDeactivateOnCloseAction) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) NeedUriInNamedListFilter(won.bot.framework.eventbot.filter.impl.NeedUriInNamedListFilter) 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) DeactivateAllNeedsOfListAction(won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsOfListAction) ConnectFromListToListAction(won.bot.framework.eventbot.action.impl.wonmessage.ConnectFromListToListAction) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) WaitForNEventsListener(won.bot.framework.eventbot.listener.impl.WaitForNEventsListener) FinishedEventFilter(won.bot.framework.eventbot.filter.impl.FinishedEventFilter) ParticipantCoordinatorBotContextWrapper(won.bot.framework.bot.context.ParticipantCoordinatorBotContextWrapper)

Example 14 with EventBus

use of won.bot.framework.eventbot.bus.EventBus in project webofneeds by researchstudio-sat.

the class DuplicateMessageSendingConversationBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    EventListenerContext ctx = getDuplicateMessageSenderDecorator(getEventListenerContext());
    final EventBus bus = getEventBus();
    // we're not expecting any failure messages in this test:
    bus.subscribe(FailureResponseEvent.class, new ActionOnEventListener(ctx, new BaseEventBotAction(ctx) {

        @Override
        protected void doRun(Event event, EventListener executingListener) throws Exception {
            FailureResponseEvent failureResponseEvent = (FailureResponseEvent) event;
            bus.publish(new TestFailedEvent(DuplicateMessageSendingConversationBot.this, "Message failed: " + failureResponseEvent.getOriginalMessageURI() + ": " + WonRdfUtils.MessageUtils.getTextMessage(failureResponseEvent.getFailureMessage())));
        }
    }));
    // create needs every trigger execution until 2 needs are created
    bus.subscribe(ActEvent.class, new ActionOnEventListener(ctx, new CreateNeedWithFacetsAction(ctx, getBotContextWrapper().getNeedCreateListName()), NO_OF_NEEDS));
    // connect needs
    bus.subscribe(NeedCreatedEvent.class, new ActionOnceAfterNEventsListener(ctx, "needConnector", NO_OF_NEEDS * 2, new ConnectFromListToListAction(ctx, getBotContextWrapper().getNeedCreateListName(), getBotContextWrapper().getNeedCreateListName(), FacetType.OwnerFacet.getURI(), FacetType.OwnerFacet.getURI(), MILLIS_BETWEEN_MESSAGES, "Hi!")));
    // 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)
    bus.subscribe(ConnectFromOtherNeedEvent.class, new ActionOnEventListener(ctx, new OpenConnectionAction(ctx, "Hi!")));
    // 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
    BaseEventListener autoResponder = new AutomaticMessageResponderListener(ctx, NO_OF_MESSAGES, MILLIS_BETWEEN_MESSAGES);
    bus.subscribe(OpenFromOtherNeedEvent.class, autoResponder);
    bus.subscribe(MessageFromOtherNeedEvent.class, autoResponder);
    // add a listener that closes the connection after it has seen 10 messages
    bus.subscribe(MessageFromOtherNeedEvent.class, new ActionOnceAfterNEventsListener(ctx, NO_OF_MESSAGES, new CloseConnectionAction(ctx, "Bye!")));
    // 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
    bus.subscribe(CloseFromOtherNeedEvent.class, new ActionOnEventListener(ctx, new MultipleActions(ctx, new DeactivateAllNeedsAction(ctx), new PublishEventAction(ctx, new TestPassedEvent(this))), 1));
    // add a listener that counts two NeedDeactivatedEvents and then tells the
    // framework that the bot's work is done
    bus.subscribe(NeedDeactivatedEvent.class, new ActionOnceAfterNEventsListener(ctx, NO_OF_NEEDS, new SignalWorkDoneAction(ctx)));
}
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) 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) TestFailedEvent(won.bot.framework.eventbot.event.impl.test.TestFailedEvent) TestPassedEvent(won.bot.framework.eventbot.event.impl.test.TestPassedEvent) DeactivateAllNeedsAction(won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsAction) ConnectFromListToListAction(won.bot.framework.eventbot.action.impl.wonmessage.ConnectFromListToListAction) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) NeedDeactivatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedDeactivatedEvent) TestFailedEvent(won.bot.framework.eventbot.event.impl.test.TestFailedEvent) NeedCreatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent) TestPassedEvent(won.bot.framework.eventbot.event.impl.test.TestPassedEvent) Event(won.bot.framework.eventbot.event.Event) ActEvent(won.bot.framework.eventbot.event.impl.lifecycle.ActEvent) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) BaseEventListener(won.bot.framework.eventbot.listener.BaseEventListener) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) EventListener(won.bot.framework.eventbot.listener.EventListener) AutomaticMessageResponderListener(won.bot.framework.eventbot.listener.impl.AutomaticMessageResponderListener)

Example 15 with EventBus

use of won.bot.framework.eventbot.bus.EventBus in project webofneeds by researchstudio-sat.

the class DuplicateMessageURIFailureBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    EventListenerContext ctx = getEventListenerContext();
    EventBus bus = getEventBus();
    // create needs every trigger execution until 2 needs are created
    bus.subscribe(ActEvent.class, new ActionOnEventListener(ctx, new CreateNeedWithFacetsAction(// use a decorator that will cause the same need URI to be used in each create message
    new ConstantNewEventURIDecorator(ctx, "constantMsgURI" + System.currentTimeMillis()), getBotContextWrapper().getNeedCreateListName()), 2));
    // log error if we can create 2 needs
    bus.subscribe(NeedCreatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 2, new MultipleActions(ctx, new LogErrorAction(ctx, "Should not have been able to create 2 needs using message with identical URIs"), new PublishEventAction(ctx, new TestFailedEvent(this, "Should not have been able to create 2 needs with identical URI")))));
    // log success if we could create 1 need
    bus.subscribe(NeedCreatedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: could create one need"), new PublishEventAction(ctx, new SuccessEvent()))));
    // log success if we got an error for 2nd need
    bus.subscribe(NeedCreationFailedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: need creation failed for 2nd need."), new PublishEventAction(ctx, new SuccessEvent()))));
    // when we have 2 SuccessEvents, we're done. Deacivate the needs and signal we're finished
    bus.subscribe(SuccessEvent.class, new ActionOnceAfterNEventsListener(ctx, 2, new MultipleActions(ctx, new LogAction(ctx, "Test passed."), new PublishEventAction(ctx, new TestPassedEvent(this)), new DeactivateAllNeedsAction(ctx))));
    // when we have a FailureEvent, we're done, too. Deacivate the needs and signal we're finished
    bus.subscribe(TestFailedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Test failed."), new DeactivateAllNeedsAction(ctx))));
    // wait for the needDeactivated event, then say we're done.
    bus.subscribe(NeedDeactivatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new SignalWorkDoneAction(ctx, this)));
// TODO: fix: bot runs forever even if test fails.
// TODO: fix: need 1 is not deactivated if test fails.
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) ConstantNewEventURIDecorator(won.bot.integrationtest.failsim.ConstantNewEventURIDecorator) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) EventBus(won.bot.framework.eventbot.bus.EventBus) SignalWorkDoneAction(won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction) TestFailedEvent(won.bot.framework.eventbot.event.impl.test.TestFailedEvent) ActionOnFirstNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstNEventsListener) TestPassedEvent(won.bot.framework.eventbot.event.impl.test.TestPassedEvent) SuccessEvent(won.bot.framework.eventbot.event.impl.test.SuccessEvent) DeactivateAllNeedsAction(won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsAction) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener)

Aggregations

EventBus (won.bot.framework.eventbot.bus.EventBus)31 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)28 EventListener (won.bot.framework.eventbot.listener.EventListener)19 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)19 Event (won.bot.framework.eventbot.event.Event)18 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)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 URI (java.net.URI)12 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)10 OpenConnectionAction (won.bot.framework.eventbot.action.impl.wonmessage.OpenConnectionAction)8 DeactivateAllNeedsAction (won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsAction)6 Dataset (org.apache.jena.query.Dataset)5 DeactivateAllNeedsOfListAction (won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsOfListAction)5 CloseConnectionAction (won.bot.framework.eventbot.action.impl.wonmessage.CloseConnectionAction)5 FinishedEventFilter (won.bot.framework.eventbot.filter.impl.FinishedEventFilter)5