use of won.bot.framework.eventbot.behaviour.ExecuteWonMessageCommandBehaviour in project webofneeds by researchstudio-sat.
the class FactoryBot method initializeEventListeners.
@Override
protected final void initializeEventListeners() {
if (!(super.getBotContextWrapper() instanceof FactoryBotContextWrapper)) {
logger.error("FactoryBot does not work without a FactoryBotContextWrapper");
throw new IllegalStateException("FactoryBot does not work without a FactoryBotContextWrapper");
}
if (getNeedProducer() == null) {
logger.error("FactoryBots do not work without a set needProducer");
throw new IllegalStateException("FactoryBots do not work without a set needProducer");
}
EventListenerContext ctx = getEventListenerContext();
BotBehaviour factoryBotInitBehaviour = new FactoryBotInitBehaviour(ctx);
BotBehaviour factoryBotHintBehaviour = new FactoryBotHintBehaviour(ctx);
BotBehaviour messageCommandBehaviour = new ExecuteWonMessageCommandBehaviour(ctx);
BotBehaviour runningBehaviour = new BotBehaviour(ctx) {
@Override
protected void onActivate(Optional<Object> message) {
initializeFactoryEventListeners();
}
};
factoryBotInitBehaviour.onDeactivateActivate(runningBehaviour, factoryBotHintBehaviour, messageCommandBehaviour);
factoryBotInitBehaviour.activate();
}
use of won.bot.framework.eventbot.behaviour.ExecuteWonMessageCommandBehaviour in project webofneeds by researchstudio-sat.
the class GroupCycleBot method initializeEventListeners.
@Override
protected void initializeEventListeners() {
EventListenerContext ctx = getEventListenerContext();
// start with a friendly message
ctx.getEventBus().subscribe(InitializeEvent.class, new ActionOnFirstEventListener(ctx, new BaseEventBotAction(ctx) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
logger.info("");
logger.info("We will create {} groups with {} members each.", NUMBER_OF_GROUPS, NUMBER_OF_GROUPMEMBERS);
logger.info("The groups all be connected to each other, resulting in {} group-group connections", NUMBER_OF_GROUPS * (NUMBER_OF_GROUPS - 1) / 2);
logger.info("Then, one group member will send a message to its group, which should reach all other group members exactly once");
logger.info("This will result in {} messages being received.", NUMBER_OF_GROUPS * NUMBER_OF_GROUPMEMBERS - 1);
logger.info("The groups will forward {} messages and suppress {} duplicates", NUMBER_OF_GROUPS * (NUMBER_OF_GROUPS + NUMBER_OF_GROUPMEMBERS - 2), (int) Math.pow(NUMBER_OF_GROUPS, 2) - 3 * NUMBER_OF_GROUPS + 2);
logger.info("");
}
}));
// understand message commands
BotBehaviour messageCommandBehaviour = new ExecuteWonMessageCommandBehaviour(ctx);
messageCommandBehaviour.activate();
// if we receive a connection message, log it
BotBehaviour logConnectionMessageBehaviour = new LogConnectionMessageBehaviour(ctx);
logConnectionMessageBehaviour.activate();
// log other important events (group/member creation and conneciton)
BotBehaviour infoBehaviour = new OutputInfoMessagesBehaviour(ctx);
infoBehaviour.activate();
// wait for both groups to finish being set up, then connect the groups
BehaviourBarrier barrier = new BehaviourBarrier(ctx);
for (int i = 0; i < NUMBER_OF_GROUPS; i++) {
// create group 1, its members, and connect them
CreateGroupBehaviour groupCreate = new CreateGroupBehaviour(ctx);
OpenOnConnectBehaviour groupOpenOnConnect = new OpenOnConnectBehaviour(ctx);
CreateGroupMembersBehaviour groupMembers = new CreateGroupMembersBehaviour(ctx);
groupCreate.onDeactivateActivate(groupOpenOnConnect, groupMembers);
barrier.waitFor(groupMembers);
// wait for the initialize event and trigger group creation
ctx.getEventBus().subscribe(InitializeEvent.class, new ActionOnFirstEventListener(ctx, new BaseEventBotAction(ctx) {
@Override
protected void doRun(Event event, EventListener executingListener) throws Exception {
groupCreate.activate();
}
}));
}
BotBehaviour connectGroupsBehaviour = new ConnectGroupsBehaviour(ctx);
barrier.thenStart(connectGroupsBehaviour);
barrier.activate();
// after connecting the groups, send one message on behalf of one of the group members
// and count the messages that group members receive
// when all groups are connected, start the count behaviour
CountReceivedMessagesBehaviour countReceivedMessagesBehaviour = new CountReceivedMessagesBehaviour(ctx);
connectGroupsBehaviour.onDeactivateActivate(countReceivedMessagesBehaviour);
// wait for the count behaviour to have started, then send the group message
BotBehaviour sendInitialMessageBehaviour = new SendOneMessageBehaviour(ctx);
countReceivedMessagesBehaviour.onActivateActivate(sendInitialMessageBehaviour);
}
Aggregations