Search in sources :

Example 6 with BATestBotScript

use of won.bot.framework.eventbot.listener.baStateBots.BATestBotScript in project webofneeds by researchstudio-sat.

the class BAAtomicCCBot method getFirstPhaseScripts.

protected List<BATestBotScript> getFirstPhaseScripts() {
    List<BATestBotScript> scripts = new ArrayList<BATestBotScript>(2);
    // Coordination message is sent as TEXT
    scripts.add(new CompletingBlockingFPBot());
    scripts.add(new CompletedBlockedFPBot());
    return scripts;
}
Also used : CompletingBlockingFPBot(won.bot.framework.eventbot.listener.baStateBots.baCCMessagingBots.atomicBots.coordinationMessageAsTextBot.CompletingBlockingFPBot) ArrayList(java.util.ArrayList) CompletedBlockedFPBot(won.bot.framework.eventbot.listener.baStateBots.baCCMessagingBots.atomicBots.coordinationMessageAsTextBot.CompletedBlockedFPBot) BATestBotScript(won.bot.framework.eventbot.listener.baStateBots.BATestBotScript)

Example 7 with BATestBotScript

use of won.bot.framework.eventbot.listener.baStateBots.BATestBotScript in project webofneeds by researchstudio-sat.

the class BAAtomicCCBot method getSecondPhaseScripts.

protected List<BATestBotScript> getSecondPhaseScripts() {
    List<BATestBotScript> scripts = new ArrayList<BATestBotScript>(2);
    scripts.add(new CompletingBlockingSPBot());
    scripts.add(new CompletedBlockedSPBot());
    return scripts;
}
Also used : CompletedBlockedSPBot(won.bot.framework.eventbot.listener.baStateBots.baCCMessagingBots.atomicBots.coordinationMessageAsTextBot.CompletedBlockedSPBot) CompletingBlockingSPBot(won.bot.framework.eventbot.listener.baStateBots.baCCMessagingBots.atomicBots.coordinationMessageAsTextBot.CompletingBlockingSPBot) ArrayList(java.util.ArrayList) BATestBotScript(won.bot.framework.eventbot.listener.baStateBots.BATestBotScript)

Example 8 with BATestBotScript

use of won.bot.framework.eventbot.listener.baStateBots.BATestBotScript in project webofneeds by researchstudio-sat.

the class AutomaticBAMessageResponderListener method handleMessageEvent.

private void handleMessageEvent(final MessageFromOtherNeedEvent messageEvent) {
    logger.debug("handleMessage: got message event for need: {}, connection state is: {}", messageEvent.getCon().getNeedURI(), messageEvent.getCon().getState());
    if (messageEvent.getCon().getState() != ConnectionState.CONNECTED) {
        logger.warn("connection state must be CONNECTED when open is received. We don't expect open of connections created through hints.");
    }
    logger.debug("replying to open with message");
    // register a WS-BA state machine for this need-need combination:
    boolean weAreOnCoordinatorSide = areWeOnCoordinatorSide(messageEvent.getCon());
    // now, getGeneric the action from the state machine and make the right need send the message
    BATestBotScript script = getStateMachine(messageEvent.getCon(), weAreOnCoordinatorSide);
    if (isScriptFinished(script))
        return;
    BATestScriptAction action = script.getNextAction();
    // decide from which need to send the initial WS-BA protocol message
    URI connectionToSendMessageFrom = determineConnectionToSendFrom(messageEvent.getCon(), weAreOnCoordinatorSide, action);
    // 2   sendMessageFromConnection(action, connectionToSendMessageFrom);
    sendModelFromConnection(action, connectionToSendMessageFrom);
}
Also used : BATestScriptAction(won.bot.framework.eventbot.listener.baStateBots.BATestScriptAction) URI(java.net.URI) BATestBotScript(won.bot.framework.eventbot.listener.baStateBots.BATestBotScript)

Example 9 with BATestBotScript

use of won.bot.framework.eventbot.listener.baStateBots.BATestBotScript in project webofneeds by researchstudio-sat.

the class AutomaticBAMessageResponderListener method setupStateMachine.

private BATestBotScript setupStateMachine(OpenFromOtherNeedEvent openEvent, boolean weAreOnCoordinatorSide) {
    // create a key for the state machine manager:
    URI localNeedUri = openEvent.getCon().getNeedURI();
    URI remoteNeedUri = openEvent.getCon().getRemoteNeedURI();
    URI coordinatorUri = weAreOnCoordinatorSide ? localNeedUri : remoteNeedUri;
    URI participantUri = weAreOnCoordinatorSide ? remoteNeedUri : localNeedUri;
    // decide which state machine to use for this combination:
    ParticipantCoordinatorBotContextWrapper botContextWrapper = (ParticipantCoordinatorBotContextWrapper) getEventListenerContext().getBotContextWrapper();
    List<URI> participants = botContextWrapper.getParticipants();
    logger.debug("participants:{}", participants);
    logger.debug("participant URI to look for:{}", participantUri);
    // let's hard-code this for now:
    BATestBotScript stateMachine = null;
    stateMachine = scripts.get(participants.indexOf(participantUri));
    scriptManager.setStateForNeedUri(stateMachine, coordinatorUri, participantUri);
    return stateMachine;
}
Also used : URI(java.net.URI) ParticipantCoordinatorBotContextWrapper(won.bot.framework.bot.context.ParticipantCoordinatorBotContextWrapper) BATestBotScript(won.bot.framework.eventbot.listener.baStateBots.BATestBotScript)

Example 10 with BATestBotScript

use of won.bot.framework.eventbot.listener.baStateBots.BATestBotScript in project webofneeds by researchstudio-sat.

the class BABaseBot method initializeEventListeners.

@Override
protected void initializeEventListeners() {
    final EventListenerContext ctx = getEventListenerContext();
    final 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(), getParticipantFacetType().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(), getCoordinatorFacetType().getURI()), 1);
    bus.subscribe(FinishedEvent.class, this.coordinatorNeedCreator);
    final Iterator<BATestBotScript> scriptIterator = scripts.iterator();
    // make a composite filter, with one filter for each testScriptListener that wait
    // for the FinishedEvents the they emit. That filter will be used to shut
    // down all needs after all the scriptListeners have finished.
    final OrFilter mainScriptListenerFilter = new OrFilter();
    // create a callback that gets called immediately before the connection is established
    ConnectFromListToListAction.ConnectHook scriptConnectHook = new ConnectFromListToListAction.ConnectHook() {

        @Override
        public void onConnect(final URI fromNeedURI, final URI toNeedURI) {
            // create the listener that will execute the script actions
            BATestScriptListener testScriptListener = new BATestScriptListener(ctx, scriptIterator.next(), fromNeedURI, toNeedURI, MILLIS_BETWEEN_MESSAGES);
            // remember it so we can check its state later
            testScriptListeners.add(testScriptListener);
            // subscribe it to the relevant events.
            bus.subscribe(ConnectFromOtherNeedEvent.class, testScriptListener);
            bus.subscribe(OpenFromOtherNeedEvent.class, testScriptListener);
            bus.subscribe(MessageFromOtherNeedEvent.class, testScriptListener);
            // add a filter that will wait for the FinishedEvent emitted by that listener
            // wrap it in an acceptance filter to make extra sure we count each listener only once.
            mainScriptListenerFilter.addFilter(new AcceptOnceFilter(new FinishedEventFilter(testScriptListener)));
        }
    };
    // when done, connect the participants to the coordinator
    this.needConnector = new ActionOnceAfterNEventsListener(ctx, "needConnector", noOfNeeds, new ConnectFromListToListAction(ctx, botContextWrapper.getCoordinatorListName(), botContextWrapper.getParticipantListName(), getCoordinatorFacetType().getURI(), getParticipantFacetType().getURI(), MILLIS_BETWEEN_MESSAGES, scriptConnectHook, "Hi!"));
    bus.subscribe(NeedCreatedEvent.class, this.needConnector);
    // for each group member, there are 2 listeners waiting for messages. when they are all finished, we're done.
    this.scriptsDoneListener = new ActionOnceAfterNEventsListener(ctx, "scriptsDoneListener", mainScriptListenerFilter, noOfNeeds - 1, new DeactivateAllNeedsOfListAction(ctx, botContextWrapper.getParticipantListName()));
    bus.subscribe(FinishedEvent.class, this.scriptsDoneListener);
    // When the needs are deactivated, all connections are closed. wait for the close events and signal work done.
    this.workDoneSignaller = new ActionOnceAfterNEventsListener(ctx, "workDoneSignaller", noOfNeeds - 1, new SignalWorkDoneAction(ctx));
    bus.subscribe(CloseFromOtherNeedEvent.class, this.workDoneSignaller);
}
Also used : EventListenerContext(won.bot.framework.eventbot.EventListenerContext) ActionOnceAfterNEventsListener(won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener) CreateNeedWithFacetsAction(won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction) EventBus(won.bot.framework.eventbot.bus.EventBus) OrFilter(won.bot.framework.eventbot.filter.impl.OrFilter) SignalWorkDoneAction(won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction) URI(java.net.URI) DeactivateAllNeedsOfListAction(won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsOfListAction) ConnectFromListToListAction(won.bot.framework.eventbot.action.impl.wonmessage.ConnectFromListToListAction) BATestScriptListener(won.bot.framework.eventbot.listener.baStateBots.BATestScriptListener) ActionOnEventListener(won.bot.framework.eventbot.listener.impl.ActionOnEventListener) AcceptOnceFilter(won.bot.framework.eventbot.filter.impl.AcceptOnceFilter) FinishedEventFilter(won.bot.framework.eventbot.filter.impl.FinishedEventFilter) ParticipantCoordinatorBotContextWrapper(won.bot.framework.bot.context.ParticipantCoordinatorBotContextWrapper) BATestBotScript(won.bot.framework.eventbot.listener.baStateBots.BATestBotScript)

Aggregations

BATestBotScript (won.bot.framework.eventbot.listener.baStateBots.BATestBotScript)10 URI (java.net.URI)5 ArrayList (java.util.ArrayList)5 ParticipantCoordinatorBotContextWrapper (won.bot.framework.bot.context.ParticipantCoordinatorBotContextWrapper)2 EventListenerContext (won.bot.framework.eventbot.EventListenerContext)2 SignalWorkDoneAction (won.bot.framework.eventbot.action.impl.lifecycle.SignalWorkDoneAction)2 CreateNeedWithFacetsAction (won.bot.framework.eventbot.action.impl.needlifecycle.CreateNeedWithFacetsAction)2 DeactivateAllNeedsOfListAction (won.bot.framework.eventbot.action.impl.needlifecycle.DeactivateAllNeedsOfListAction)2 ConnectFromListToListAction (won.bot.framework.eventbot.action.impl.wonmessage.ConnectFromListToListAction)2 EventBus (won.bot.framework.eventbot.bus.EventBus)2 AcceptOnceFilter (won.bot.framework.eventbot.filter.impl.AcceptOnceFilter)2 FinishedEventFilter (won.bot.framework.eventbot.filter.impl.FinishedEventFilter)2 OrFilter (won.bot.framework.eventbot.filter.impl.OrFilter)2 BATestScriptAction (won.bot.framework.eventbot.listener.baStateBots.BATestScriptAction)2 BATestScriptListener (won.bot.framework.eventbot.listener.baStateBots.BATestScriptListener)2 CompletedFPBot (won.bot.framework.eventbot.listener.baStateBots.baCCMessagingBots.atomicBots.coordinationMessageAsTextBot.CompletedFPBot)2 ActionOnEventListener (won.bot.framework.eventbot.listener.impl.ActionOnEventListener)2 ActionOnceAfterNEventsListener (won.bot.framework.eventbot.listener.impl.ActionOnceAfterNEventsListener)2 AdditionalParticipantCoordinatorBotContextWrapper (won.bot.framework.bot.context.AdditionalParticipantCoordinatorBotContextWrapper)1 BaseEventBotAction (won.bot.framework.eventbot.action.BaseEventBotAction)1