use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.
the class BACCBotTest method before.
@Before
public void before() {
if (!run) {
// create a bot instance and auto-wire it
AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
Object botBean = beanFactory.initializeBean(bot, "mybot");
bot = (MyBot) botBean;
// the bot also needs a trigger so its act() method is called regularly.
// (there is no trigger bean in the context)
PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
bot.setTrigger(trigger);
logger.info("starting test case testBACCBot");
// adding the bot to the bot manager will cause it to be initialized.
// at that point, the trigger starts.
botManager.setShutdownApplicationContextIfWorkDone(false);
botManager.addBot(bot);
staticBotManager = botManager;
// and both threads continue.
try {
bot.getBarrier().await();
} catch (InterruptedException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
} catch (BrokenBarrierException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
run = true;
}
}
use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.
the class BAPCBotTest method before.
@Before
public void before() {
if (!run) {
// create a bot instance and auto-wire it
AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
Object botBean = beanFactory.initializeBean(bot, "mybot");
bot = (MyBot) botBean;
// the bot also needs a trigger so its act() method is called regularly.
// (there is no trigger bean in the context)
PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
bot.setTrigger(trigger);
logger.info("starting test case testBAPCBot");
// adding the bot to the bot manager will cause it to be initialized.
// at that point, the trigger starts.
botManager.setShutdownApplicationContextIfWorkDone(false);
botManager.addBot(bot);
staticBotManager = botManager;
// and both threads continue.
try {
bot.getBarrier().await();
} catch (InterruptedException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
} catch (BrokenBarrierException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
run = true;
}
}
use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.
the class CommentBotTest method before.
/**
* This is run before each @TestD method.
*/
@Before
public void before() {
if (!run) {
// create a bot instance and auto-wire it
AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
Object botBean = beanFactory.initializeBean(bot, "mybot");
bot = (MyBot) botBean;
// the bot also needs a trigger so its act() method is called regularly.
// (there is no trigger bean in the context)
PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
bot.setTrigger(trigger);
logger.info("starting test case testCommentBot");
// adding the bot to the bot manager will cause it to be initialized.
// at that point, the trigger starts.
botManager.addBot(bot);
// and both threads continue.
try {
bot.getBarrier().await();
} catch (InterruptedException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
} catch (BrokenBarrierException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
run = true;
}
}
use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.
the class GroupingBotTest method before.
/**
* This is run before each @TestD method.
*/
@Before
public void before() {
if (!run) {
AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
Object botBean = beanFactory.initializeBean(bot, "mybot");
bot = (MyBot) botBean;
// the bot also needs a trigger so its act() method is called regularly.
// (there is no trigger bean in the context)
PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
bot.setTrigger(trigger);
logger.info("starting test case testGroupBot");
// adding the bot to the bot manager will cause it to be initialized.
// at that point, the trigger starts.
botManager.addBot(bot);
// and both threads continue.
try {
bot.getBarrier().await();
} catch (InterruptedException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
} catch (BrokenBarrierException e) {
// To change body of catch statement use File | Settings | File Templates.
e.printStackTrace();
}
run = true;
}
}
use of org.springframework.scheduling.support.PeriodicTrigger in project spring-integration by spring-projects.
the class MethodInvokingMessageHandlerTests method subscription.
@Test
public void subscription() throws Exception {
TestApplicationContext context = TestUtils.createTestApplicationContext();
SynchronousQueue<String> queue = new SynchronousQueue<String>();
TestBean testBean = new TestBean(queue);
QueueChannel channel = new QueueChannel();
context.registerChannel("channel", channel);
Message<String> message = new GenericMessage<String>("testing");
channel.send(message);
assertNull(queue.poll());
MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(testBean, "foo");
PollingConsumer endpoint = new PollingConsumer(channel, handler);
endpoint.setTrigger(new PeriodicTrigger(10));
context.registerEndpoint("testEndpoint", endpoint);
context.refresh();
String result = queue.poll(2000, TimeUnit.MILLISECONDS);
assertNotNull(result);
assertEquals("testing", result);
context.stop();
}
Aggregations