use of won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener in project webofneeds by researchstudio-sat.
the class EventBotActionUtils method makeAndSubscribeResponseListener.
// ************************************************ EventListener ***************************************************
/**
* Creates a listener that waits for the response to the specified message. If a SuccessResponse is received,
* the successCallback is executed, if a FailureResponse is received, the failureCallback is executed.
* @param outgoingMessage
* @param successCallback
* @param failureCallback
* @param context
* @return
*/
public static EventListener makeAndSubscribeResponseListener(final WonMessage outgoingMessage, final EventListener successCallback, final EventListener failureCallback, EventListenerContext context) {
// create an event listener that processes the response to the wonMessage we're about to send
EventListener listener = new ActionOnFirstEventListener(context, OriginalMessageUriResponseEventFilter.forWonMessage(outgoingMessage), new BaseEventBotAction(context) {
@Override
protected void doRun(final Event event, EventListener executingListener) throws Exception {
if (event instanceof SuccessResponseEvent) {
successCallback.onEvent(event);
} else if (event instanceof FailureResponseEvent) {
failureCallback.onEvent(event);
}
}
});
context.getEventBus().subscribe(SuccessResponseEvent.class, listener);
context.getEventBus().subscribe(FailureResponseEvent.class, listener);
return listener;
}
use of won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener in project webofneeds by researchstudio-sat.
the class BotTrigger method activate.
public synchronized void activate() {
if (active.get())
return;
// make the stop listener
this.stopListener = new ActionOnFirstEventListener(this.context, new BotTriggerFilter(this), new BaseEventBotAction(BotTrigger.this.context) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
// unregister all listeners
BotTrigger.this.context.getEventBus().unsubscribe(BotTrigger.this.startListener);
BotTrigger.this.context.getEventBus().unsubscribe(BotTrigger.this.stopListener);
BotTrigger.this.cancelableTask.cancel(true);
BotTrigger.this.active.set(false);
}
});
// make the start listener
this.startListener = new ActionOnFirstEventListener(this.context, new BotTriggerFilter(this), new BaseEventBotAction(BotTrigger.this.context) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
reschedule();
}
});
// register both listeners
context.getEventBus().subscribe(StopBotTriggerCommandEvent.class, stopListener);
context.getEventBus().subscribe(StartBotTriggerCommandEvent.class, startListener);
active.set(true);
}
Aggregations