Search in sources :

Example 6 with ActionOnFirstEventListener

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;
}
Also used : SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) SuccessResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.SuccessResponseEvent) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent) Event(won.bot.framework.eventbot.event.Event) ActionOnFirstEventListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener) EventListener(won.bot.framework.eventbot.listener.EventListener) ActionOnFirstEventListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener) FailureResponseEvent(won.bot.framework.eventbot.event.impl.wonmessage.FailureResponseEvent) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException)

Example 7 with ActionOnFirstEventListener

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);
}
Also used : BaseEventBotAction(won.bot.framework.eventbot.action.BaseEventBotAction) Event(won.bot.framework.eventbot.event.Event) ActionOnFirstEventListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener) EventListener(won.bot.framework.eventbot.listener.EventListener) ActionOnFirstEventListener(won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener)

Aggregations

Event (won.bot.framework.eventbot.event.Event)7 EventListener (won.bot.framework.eventbot.listener.EventListener)7 ActionOnFirstEventListener (won.bot.framework.eventbot.listener.impl.ActionOnFirstEventListener)7 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)5 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)4 InitializeEvent (won.bot.framework.eventbot.event.impl.lifecycle.InitializeEvent)3 IOException (java.io.IOException)2 URI (java.net.URI)2 MessagingException (javax.mail.MessagingException)2 Dataset (org.apache.jena.query.Dataset)2 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)2 CreateNeedCommandEvent (won.bot.framework.eventbot.event.impl.command.create.CreateNeedCommandEvent)2 InitFactoryFinishedEvent (won.bot.framework.eventbot.event.impl.factory.InitFactoryFinishedEvent)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Resource (org.apache.jena.rdf.model.Resource)1 PrefixMapping (org.apache.jena.shared.PrefixMapping)1 PrefixMappingImpl (org.apache.jena.shared.impl.PrefixMappingImpl)1 Path (org.apache.jena.sparql.path.Path)1 FactoryBotContextWrapper (won.bot.framework.bot.context.FactoryBotContextWrapper)1