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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations