use of org.springframework.scheduling.support.PeriodicTrigger in project spring-integration by spring-projects.
the class SourcePollingChannelAdapterFactoryBeanTests method testAdviceChain.
@Test
public void testAdviceChain() throws Exception {
SourcePollingChannelAdapterFactoryBean factoryBean = new SourcePollingChannelAdapterFactoryBean();
QueueChannel outputChannel = new QueueChannel();
TestApplicationContext context = TestUtils.createTestApplicationContext();
factoryBean.setBeanFactory(context.getBeanFactory());
factoryBean.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
factoryBean.setOutputChannel(outputChannel);
factoryBean.setSource(() -> new GenericMessage<>("test"));
PollerMetadata pollerMetadata = new PollerMetadata();
List<Advice> adviceChain = new ArrayList<Advice>();
final AtomicBoolean adviceApplied = new AtomicBoolean(false);
adviceChain.add((MethodInterceptor) invocation -> {
adviceApplied.set(true);
return invocation.proceed();
});
pollerMetadata.setTrigger(new PeriodicTrigger(5000));
pollerMetadata.setMaxMessagesPerPoll(1);
pollerMetadata.setAdviceChain(adviceChain);
factoryBean.setPollerMetadata(pollerMetadata);
factoryBean.setAutoStartup(true);
factoryBean.afterPropertiesSet();
context.registerEndpoint("testPollingEndpoint", factoryBean.getObject());
context.refresh();
Message<?> message = outputChannel.receive(5000);
assertEquals("test", message.getPayload());
assertTrue("adviceChain was not applied", adviceApplied.get());
}
use of org.springframework.scheduling.support.PeriodicTrigger in project spring-integration by spring-projects.
the class WebServiceOutboundGatewayParserTests method simpleGatewayWithPoller.
@Test
public void simpleGatewayWithPoller() {
AbstractEndpoint endpoint = this.context.getBean("gatewayWithPoller", AbstractEndpoint.class);
assertEquals(PollingConsumer.class, endpoint.getClass());
Object triggerObject = new DirectFieldAccessor(endpoint).getPropertyValue("trigger");
assertEquals(PeriodicTrigger.class, triggerObject.getClass());
PeriodicTrigger trigger = (PeriodicTrigger) triggerObject;
DirectFieldAccessor accessor = new DirectFieldAccessor(trigger);
assertEquals("PeriodicTrigger had wrong period", 5000, ((Long) accessor.getPropertyValue("period")).longValue());
}
use of org.springframework.scheduling.support.PeriodicTrigger in project spring-cloud-stream by spring-cloud.
the class DefaultPollerProperties method getPollerMetadata.
public PollerMetadata getPollerMetadata() {
PollerMetadata pollerMetadata = new PollerMetadata();
pollerMetadata.setTrigger(new PeriodicTrigger(this.fixedDelay));
pollerMetadata.setMaxMessagesPerPoll(this.maxMessagesPerPoll);
return pollerMetadata;
}
use of org.springframework.scheduling.support.PeriodicTrigger 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);
}
use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.
the class NeedInactivityChecker method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
if (this.taskScheduler == null)
throw new IllegalStateException("taskScheduler must be set");
if (this.inactivityCheckInterval > 0) {
PeriodicTrigger periodicTrigger = new PeriodicTrigger(this.inactivityCheckInterval, TimeUnit.SECONDS);
periodicTrigger.setInitialDelay(this.inactivityCheckInterval);
this.trigger = periodicTrigger;
}
this.inactivityCheckTask = new InactivityCheckTask();
taskScheduler.schedule(this.inactivityCheckTask, trigger);
if (logger.isDebugEnabled()) {
logger.debug("setting up inactivity checker to check inactivity every {} seconds, warn after {} seconds and deactivate after {} seconds", new Object[] { inactivityCheckInterval, warnTimeout, deactivateTimeout });
}
}
Aggregations