use of won.bot.framework.manager.BotManager in project webofneeds by researchstudio-sat.
the class BotRunnerApp method main.
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("arguments: [bot class name]");
System.exit(1);
}
String botClass = args[0];
SpringApplication app = new SpringApplication(new Object[] { "classpath:/spring/app/botRunner.xml" });
app.setWebEnvironment(false);
ConfigurableApplicationContext applicationContext = app.run(args);
Bot bot = null;
// create a bot instance and auto-wire it
AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
bot = (Bot) beanFactory.autowire(Class.forName(botClass), AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
Object botBean = beanFactory.initializeBean(bot, "theBot");
bot = (Bot) botBean;
// (there is no trigger bean in the context)
if (bot instanceof TriggeredBot) {
PeriodicTrigger trigger = new PeriodicTrigger(5000, TimeUnit.MILLISECONDS);
trigger.setInitialDelay(1000);
((TriggeredBot) bot).setTrigger(trigger);
}
BotManager botManager = (BotManager) applicationContext.getBean("botManager");
// adding the bot to the bot manager will cause it to be initialized.
// at that point, the trigger starts.
botManager.addBot(bot);
}
Aggregations