Search in sources :

Example 1 with MatchingLoadTestMonitorAction

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

the class NeedCreatorBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    final EventListenerContext ctx = getEventListenerContext();
    final EventBus bus = getEventBus();
    final Counter needCreationSuccessfulCounter = new CounterImpl("needsCreated");
    final Counter needCreationFailedCounter = new CounterImpl("needCreationFailed");
    final Counter needCreationStartedCounter = new CounterImpl("creationStarted");
    // create a targeted counter that will publish an event when the target is reached
    // in this case, 0 unfinished need creations means that all needs were created
    final Counter creationUnfinishedCounter = new TargetCounterDecorator(ctx, new CounterImpl("creationUnfinished"), 0);
    // create needs every trigger execution until the need producer is exhausted
    this.groupMemberCreator = new ActionOnEventListener(ctx, "groupMemberCreator", new MultipleActions(ctx, new IncrementCounterAction(ctx, needCreationStartedCounter), new IncrementCounterAction(ctx, creationUnfinishedCounter), new CreateNeedWithFacetsAction(ctx, getBotContextWrapper().getNeedCreateListName())), -1);
    bus.subscribe(ActEvent.class, this.groupMemberCreator);
    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 >= 1) {
                logger.info("started creation of {} needs, creation not yet finished for {}. Successful: {}, failed: {}", new Object[] { cnt, unfinishedCount, successCnt, failedCnt });
                lastOutput = cnt;
            }
        }
    }));
    // When the needproducer is exhausted, stop the creator.
    getEventBus().subscribe(NeedProducerExhaustedEvent.class, new ActionOnEventListener(ctx, new UnsubscribeListenerAction(ctx, groupMemberCreator)));
    // 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)));
    // when a need is created (or it failed), decrement the halfCreatedNeed counter
    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);
    EventListener loadTestMonitor = new ActionOnEventListener(ctx, "loadTestMonitor", new MatchingLoadTestMonitorAction(ctx));
    bus.subscribe(NeedCreatedEvent.class, loadTestMonitor);
    bus.subscribe(HintFromMatcherEvent.class, loadTestMonitor);
// wait for the targetCountReached event of the finishedCounter. We don't use
// another target counter, so we don't need to do more filtering.
// this.workDoneSignaller = new ActionOnEventListener(
// ctx, "workDoneSignaller",
// new SignalWorkDoneAction(ctx));
// bus.subscribe(TargetCountReachedEvent.class, this.workDoneSignaller);
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) EventBus(won.bot.framework.eventbot.bus.EventBus) MatchingLoadTestMonitorAction(won.bot.framework.eventbot.action.impl.monitor.MatchingLoadTestMonitorAction) BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) NeedCreationFailedEvent(won.bot.framework.eventbot.event.NeedCreationFailedEvent) HintFromMatcherEvent(won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent) 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) NeedCreatedEvent(won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent) UnsubscribeListenerAction(won.bot.framework.eventbot.action.impl.listener.UnsubscribeListenerAction) 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

EventListenerContext (won.bot.framework.eventbot.EventListenerContext)1 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)1 UnsubscribeListenerAction (won.bot.framework.eventbot.action.impl.listener.UnsubscribeListenerAction)1 MatchingLoadTestMonitorAction (won.bot.framework.eventbot.action.impl.monitor.MatchingLoadTestMonitorAction)1 CreateNeedWithFacetsAction (won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction)1 EventBus (won.bot.framework.eventbot.bus.EventBus)1 Event (won.bot.framework.eventbot.event.Event)1 NeedCreationFailedEvent (won.bot.framework.eventbot.event.NeedCreationFailedEvent)1 ActEvent (won.bot.framework.eventbot.event.impl.lifecycle.ActEvent)1 NeedCreatedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedCreatedEvent)1 NeedProducerExhaustedEvent (won.bot.framework.eventbot.event.impl.needlifecycle.NeedProducerExhaustedEvent)1 HintFromMatcherEvent (won.bot.framework.eventbot.event.impl.wonmessage.HintFromMatcherEvent)1 BaseEventListener (won.bot.framework.eventbot.listener.BaseEventListener)1 EventListener (won.bot.framework.eventbot.listener.EventListener)1 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)1