Search in sources :

Example 1 with LogAction

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

the class DuplicateAtomURIFailureBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    EventListenerContext ctx = getEventListenerContext();
    EventBus bus = getEventBus();
    // create atoms every trigger execution until 2 atoms are created
    bus.subscribe(ActEvent.class, new ActionOnEventListener(ctx, new CreateAtomWithSocketsAction(// message
    new ConstantNewAtomURIDecorator(ctx, "constantAtomURI" + System.currentTimeMillis()), getBotContextWrapper().getAtomCreateListName()), 2));
    // log error if we can create 2 atoms
    bus.subscribe(AtomCreatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 2, new MultipleActions(ctx, new LogErrorAction(ctx, "Should not have been able to create 2 atoms with identical URI"), new PublishEventAction(ctx, new TestFailedEvent(this, "Should not have been able to create 2 atoms with identical URI")))));
    // log success if we could create 1 atom
    bus.subscribe(AtomCreatedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: could create one atom"), new PublishEventAction(ctx, new SuccessEvent()))));
    // log success if we got an error for 2nd atom
    bus.subscribe(AtomCreationFailedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: atom creation failed for 2nd atom."), new PublishEventAction(ctx, new SuccessEvent()))));
    // when we have 2 SuccessEvents, we're done. Deactivate the atoms 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 DeactivateAllAtomsAction(ctx))));
    // when we have a FailureEvent, we're done, too. Deactivate the atoms and signal
    // we're finished
    bus.subscribe(TestFailedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Test failed."), new DeactivateAllAtomsAction(ctx))));
    // wait for the atomDeactivated event, then say we're done.
    bus.subscribe(AtomDeactivatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new SignalWorkDoneAction(ctx, this)));
// TODO: fix: bot runs forever even if test fails.
// TODO: fix: atom 1 is not deactivated if test fails.
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) PublishEventAction(won.bot.framework.eventbot.action.impl.PublishEventAction) LogErrorAction(won.bot.framework.eventbot.action.impl.LogErrorAction) EventBus(won.bot.framework.eventbot.bus.EventBus) SignalWorkDoneAction(won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction) CreateAtomWithSocketsAction(won.bot.framework.eventbot.action.impl.atomlifecycle.CreateAtomWithSocketsAction) TestFailedEvent(won.bot.framework.eventbot.event.impl.test.TestFailedEvent) ActionOnFirstNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstNEventsListener) ConstantNewAtomURIDecorator(won.bot.integrationtest.failsim.ConstantNewAtomURIDecorator) TestPassedEvent(won.bot.framework.eventbot.event.impl.test.TestPassedEvent) MultipleActions(won.bot.framework.eventbot.action.impl.MultipleActions) LogAction(won.bot.framework.eventbot.action.impl.LogAction) DeactivateAllAtomsAction(won.bot.framework.eventbot.action.impl.atomlifecycle.DeactivateAllAtomsAction) SuccessEvent(won.bot.framework.eventbot.event.impl.test.SuccessEvent) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener)

Example 2 with LogAction

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

the class MatcherBehaviour method onActivate.

protected void onActivate(Optional<Object> message) {
    // register as matcher on node
    RegisterMatcherAction registerMatcher = new RegisterMatcherAction(context);
    subscribeWithAutoCleanup(ActEvent.class, new ActionOnEventListener(context, registerMatcher, 1));
    // retry in case of failed registering
    DelayedAction delayedRegistration = new DelayedAction(context, retryInterval, registerMatcher);
    subscribeWithAutoCleanup(MatcherExtensionRegisterFailedEvent.class, delayedRegistration);
    // optional action on successful registering
    subscribeWithAutoCleanup(MatcherExtensionRegisterSucceededEvent.class, new LogAction(context, "Successfully registered as Matcher"));
}
Also used : LogAction(won.bot.framework.eventbot.action.impl.LogAction) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) DelayedAction(won.bot.framework.eventbot.action.impl.DelayedAction)

Example 3 with LogAction

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

the class DuplicateMessageURIFailureBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    EventListenerContext ctx = getEventListenerContext();
    EventBus bus = getEventBus();
    // log error if we can create 2 atoms
    bus.subscribe(AtomCreatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 2, new MultipleActions(ctx, new LogErrorAction(ctx, "Should not have been able to create 2 atoms using message with identical URIs"), new PublishEventAction(ctx, new TestFailedEvent(this, "Should not have been able to create 2 atoms with identical URI")))));
    // log success if we could create 1 atom
    bus.subscribe(AtomCreatedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: could create one atom"), new PublishEventAction(ctx, new SuccessEvent()))));
    // log success if we got an error for 2nd atom
    bus.subscribe(AtomCreationFailedEvent.class, new ActionOnFirstNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Good: atom creation failed for 2nd atom."), new PublishEventAction(ctx, new SuccessEvent()))));
    // when we have 2 SuccessEvents, we're done. Deactivate the atoms 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 DeactivateAllAtomsAction(ctx))));
    // when we have a FailureEvent, we're done, too. Deactivate the atoms and signal
    // we're finished
    bus.subscribe(TestFailedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new MultipleActions(ctx, new LogAction(ctx, "Test failed."), new DeactivateAllAtomsAction(ctx))));
    // wait for the atomDeactivated event, then say we're done.
    bus.subscribe(AtomDeactivatedEvent.class, new ActionOnceAfterNEventsListener(ctx, 1, new SignalWorkDoneAction(ctx, this)));
// TODO: fix: bot runs forever even if test fails.
// TODO: fix: atom 1 is not deactivated if test fails.
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) PublishEventAction(won.bot.framework.eventbot.action.impl.PublishEventAction) LogErrorAction(won.bot.framework.eventbot.action.impl.LogErrorAction) 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) MultipleActions(won.bot.framework.eventbot.action.impl.MultipleActions) LogAction(won.bot.framework.eventbot.action.impl.LogAction) DeactivateAllAtomsAction(won.bot.framework.eventbot.action.impl.atomlifecycle.DeactivateAllAtomsAction) SuccessEvent(won.bot.framework.eventbot.event.impl.test.SuccessEvent)

Aggregations

LogAction (won.bot.framework.eventbot.action.impl.LogAction)3 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)2 LogErrorAction (won.bot.framework.eventbot.action.impl.LogErrorAction)2 MultipleActions (won.bot.framework.eventbot.action.impl.MultipleActions)2 PublishEventAction (won.bot.framework.eventbot.action.impl.PublishEventAction)2 DeactivateAllAtomsAction (won.bot.framework.eventbot.action.impl.atomlifecycle.DeactivateAllAtomsAction)2 SignalWorkDoneAction (won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction)2 EventBus (won.bot.framework.eventbot.bus.EventBus)2 SuccessEvent (won.bot.framework.eventbot.event.impl.test.SuccessEvent)2 TestFailedEvent (won.bot.framework.eventbot.event.impl.test.TestFailedEvent)2 TestPassedEvent (won.bot.framework.eventbot.event.impl.test.TestPassedEvent)2 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)2 ActionOnFirstNEventsListener (won.bot.framework.eventbot.listener.impl.ActionOnFirstNEventsListener)2 ActionOnceAfterNEventsListener (won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener)2 DelayedAction (won.bot.framework.eventbot.action.impl.DelayedAction)1 CreateAtomWithSocketsAction (won.bot.framework.eventbot.action.impl.atomlifecycle.CreateAtomWithSocketsAction)1 ConstantNewAtomURIDecorator (won.bot.integrationtest.failsim.ConstantNewAtomURIDecorator)1