org.springframework.scheduling.support.PeriodicTrigger Java Examples

The following examples show how to use org.springframework.scheduling.support.PeriodicTrigger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupplierWithCustomPoller() {
	System.clearProperty("spring.cloud.function.definition");
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(SupplierWithExplicitPollerConfiguration.class))
					.web(WebApplicationType.NONE)
					.run("--spring.jmx.enabled=false", "--spring.cloud.stream.poller.fixed-delay=2000")) {

		OutputDestination outputDestination = context.getBean(OutputDestination.class);

		PollerMetadata pollerMetadata = context.getBean(PollerMetadata.class);
		assertThat(((PeriodicTrigger) pollerMetadata.getTrigger()).getPeriod()).isEqualTo(2000);

		Message<byte[]> outputMessage = outputDestination.receive(6000);
		assertThat(outputMessage.getPayload()).isEqualTo("hello".getBytes());
	}
}
 
Example #2
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupplierWithCustomPollerAndMappedOutput() {
	System.clearProperty("spring.cloud.function.definition");
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(SupplierWithExplicitPollerConfiguration.class))
					.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false",
							"--spring.cloud.stream.poller.fixed-delay=2000",
							"--spring.cloud.function.bindings.supplier-out-0=output")) {

		OutputDestination outputDestination = context.getBean(OutputDestination.class);

		PollerMetadata pollerMetadata = context.getBean(PollerMetadata.class);
		assertThat(((PeriodicTrigger) pollerMetadata.getTrigger()).getPeriod()).isEqualTo(2000);

		Message<byte[]> outputMessage = outputDestination.receive(6000);
		assertThat(outputMessage.getPayload()).isEqualTo("hello".getBytes());
	}
}
 
Example #3
Source File: CustomPollerConfiguration.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
/**
 * Custom poller poller metadata.
 *
 * @return the poller metadata
 */
@Bean(name = StreamSpanReporter.POLLER)
PollerMetadata customPoller() {
	PollerMetadata poller = new PollerMetadata();
	poller.setMaxMessagesPerPoll(500);
	poller.setTrigger(new PeriodicTrigger(5000L));
	return poller;
}
 
Example #4
Source File: TriggerConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean(name = TriggerConstants.TRIGGER_BEAN_NAME)
@Conditional(PeriodicTriggerCondition.class)
public Trigger periodicTrigger() {
	PeriodicTrigger trigger = new PeriodicTrigger(triggerProperties.getFixedDelay(),
			triggerProperties.getTimeUnit());
	trigger.setInitialDelay(triggerProperties.getInitialDelay());
	return trigger;
}
 
Example #5
Source File: DefaultPollerProperties.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
public PollerMetadata getPollerMetadata() {
	PollerMetadata pollerMetadata = new PollerMetadata();
	if (cron != null) {
		pollerMetadata.setTrigger(new CronTrigger(cron));
	}
	else {
		final PeriodicTrigger periodicTrigger = new PeriodicTrigger(this.fixedDelay);
		periodicTrigger.setInitialDelay(initialDelay);
		pollerMetadata.setTrigger(periodicTrigger);
	}

	pollerMetadata.setMaxMessagesPerPoll(this.maxMessagesPerPoll);
	return pollerMetadata;
}
 
Example #6
Source File: ThreadPoolTaskSchedulerConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public PeriodicTrigger periodicFixedDelayTrigger() {
    PeriodicTrigger periodicTrigger = new PeriodicTrigger(2000, TimeUnit.MICROSECONDS);
    periodicTrigger.setFixedRate(true);
    periodicTrigger.setInitialDelay(1000);
    return periodicTrigger;
}
 
Example #7
Source File: SpringSessionValidationScheduler.java    From es with Apache License 2.0 5 votes vote down vote up
/**
 * Starts session validation by creating a spring PeriodicTrigger.
 */
public void enableSessionValidation() {

    enabled = true;

    if (log.isDebugEnabled()) {
        log.debug("Scheduling session validation job using Spring Scheduler with " +
                "session validation interval of [" + sessionValidationInterval + "]ms...");
    }

    try {

        PeriodicTrigger trigger = new PeriodicTrigger(sessionValidationInterval, TimeUnit.MILLISECONDS);
        trigger.setInitialDelay(sessionValidationInterval);

        scheduler.schedule(new Runnable() {
            @Override
            public void run() {
                if(enabled) {
                    sessionManager.validateSessions();
                }
            }
        }, trigger);

        this.enabled = true;

        if (log.isDebugEnabled()) {
            log.debug("Session validation job successfully scheduled with Spring Scheduler.");
        }

    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Error starting the Spring Scheduler session validation job.  Session validation may not occur.", e);
        }
    }
}
 
Example #8
Source File: ThreadPoolTaskSchedulerConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public PeriodicTrigger periodicTrigger() {
    return new PeriodicTrigger(2000, TimeUnit.MICROSECONDS);
}