当前位置: 首页>>代码示例>>Java>>正文


Java Trigger类代码示例

本文整理汇总了Java中org.springframework.scheduling.Trigger的典型用法代码示例。如果您正苦于以下问题:Java Trigger类的具体用法?Java Trigger怎么用?Java Trigger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Trigger类属于org.springframework.scheduling包,在下文中一共展示了Trigger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: schedule

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
    if (!enabled) {
        logger.debug("skip : {}", task);

        return null;
    }

    ScheduledFuture<?> future = instance.schedule(task, trigger);
    String runnableKey = findRunnableKey(task);

    if (Boolean.FALSE.equals(skipMap.get(runnableKey))) {
        future.cancel(true);
    }

    return future;
}
 
开发者ID:zhaojunfei,项目名称:lemon,代码行数:17,代码来源:ProxyTaskScheduler.java

示例2: schedule

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Override
public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
    ScheduledFuture scheduledFuture = null;
    try {
        TaskDefine taskDefine = resolveTaskName(task);
        if (taskDefine.getType().equals(TaskDefine.TYPE_SPRING_TASK)) {
            super.schedule(task, trigger);
            LOGGER.debug(":添加本地任务[" + taskDefine.stringKey() + "]");
        } else {
            String cronEx = trigger.toString();
            int index = cronEx.indexOf(":");
            if (index >= 0) {
                cronEx = cronEx.substring(index + 1);
                taskDefine.setCronExpression(cronEx.trim());
            }
            scheduleTask.addTask(taskDefine);
            scheduledFuture = super.schedule(taskWrapper(task), trigger);
            LOGGER.debug(currenScheduleServer.getUuid() + ":自动向集群注册任务[" + taskDefine.stringKey() + "]");
        }
    } catch (Exception e) {
        LOGGER.error("update task error", e);
    }
    return scheduledFuture;
}
 
开发者ID:liuht777,项目名称:uncode-scheduler,代码行数:25,代码来源:SchedulerTaskManager.java

示例3: shouldRunTokenRenewal

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldRunTokenRenewal() {

	when(clientAuthentication.login()).thenReturn(
			LoginToken.renewable("login".toCharArray(), Duration.ofSeconds(5)));

	ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);

	sessionManager.getSessionToken();
	verify(taskScheduler).schedule(runnableCaptor.capture(), any(Trigger.class));

	runnableCaptor.getValue().run();

	verify(restOperations).postForObject(
			eq("auth/token/renew-self"),
			eq(new HttpEntity<Object>(VaultHttpHeaders.from(LoginToken.renewable(
					"login", 5)))), any(Class.class));
	verify(clientAuthentication, times(1)).login();
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:20,代码来源:LifecycleAwareSessionManagerUnitTests.java

示例4: shouldReScheduleTokenRenewalAfterSuccessfulRenewal

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldReScheduleTokenRenewalAfterSuccessfulRenewal() {

	when(clientAuthentication.login()).thenReturn(
			LoginToken.renewable("login".toCharArray(), Duration.ofSeconds(5)));
	when(restOperations.postForObject(anyString(), any(), eq(VaultResponse.class)))
			.thenReturn(
					fromToken(LoginToken.of("foo".toCharArray(),
							Duration.ofSeconds(10))));

	ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);

	sessionManager.getSessionToken();
	verify(taskScheduler).schedule(runnableCaptor.capture(), any(Trigger.class));

	runnableCaptor.getValue().run();

	verify(taskScheduler, times(2)).schedule(any(Runnable.class), any(Trigger.class));
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:20,代码来源:LifecycleAwareSessionManagerUnitTests.java

示例5: shouldNotScheduleRenewalIfRenewalTtlExceedsThreshold

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldNotScheduleRenewalIfRenewalTtlExceedsThreshold() {

	when(clientAuthentication.login()).thenReturn(
			LoginToken.renewable("login".toCharArray(), Duration.ofSeconds(5)));
	when(restOperations.postForObject(anyString(), any(), eq(VaultResponse.class)))
			.thenReturn(
					fromToken(LoginToken.of("foo".toCharArray(),
							Duration.ofSeconds(2))));

	ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);

	sessionManager.getSessionToken();
	verify(taskScheduler).schedule(runnableCaptor.capture(), any(Trigger.class));

	runnableCaptor.getValue().run();

	verify(taskScheduler, times(1)).schedule(any(Runnable.class), any(Trigger.class));
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:20,代码来源:LifecycleAwareSessionManagerUnitTests.java

示例6: shouldReLoginIfRenewalTtlExceedsThreshold

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldReLoginIfRenewalTtlExceedsThreshold() {

	when(clientAuthentication.login()).thenReturn(
			LoginToken.renewable("login".toCharArray(), Duration.ofSeconds(5)),
			LoginToken.renewable("bar".toCharArray(), Duration.ofSeconds(5)));
	when(restOperations.postForObject(anyString(), any(), eq(VaultResponse.class)))
			.thenReturn(
					fromToken(LoginToken.of("foo".toCharArray(),
							Duration.ofSeconds(2))));

	ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
	sessionManager.getSessionToken();
	verify(taskScheduler).schedule(runnableCaptor.capture(), any(Trigger.class));
	runnableCaptor.getValue().run();

	assertThat(sessionManager.getSessionToken()).isEqualTo(
			LoginToken.renewable("bar".toCharArray(), Duration.ofSeconds(5)));

	verify(clientAuthentication, times(2)).login();
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:22,代码来源:LifecycleAwareSessionManagerUnitTests.java

示例7: shouldUseTaskScheduler

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldUseTaskScheduler() {

	sessionManager = new LifecycleAwareSessionManager(clientAuthentication,
			taskScheduler, restOperations);

	when(clientAuthentication.login()).thenReturn(
			LoginToken.renewable("login".toCharArray(), Duration.ofSeconds(5)));

	ArgumentCaptor<Trigger> triggerCaptor = ArgumentCaptor.forClass(Trigger.class);

	sessionManager.getSessionToken();
	verify(taskScheduler).schedule(any(Runnable.class), triggerCaptor.capture());

	assertThat(triggerCaptor.getValue().nextExecutionTime(null)).isNotNull();
	assertThat(triggerCaptor.getValue().nextExecutionTime(null)).isNull();
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:18,代码来源:LifecycleAwareSessionManagerUnitTests.java

示例8: shouldNotReScheduleTokenRenewalAfterFailedRenewal

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldNotReScheduleTokenRenewalAfterFailedRenewal() {

	when(clientAuthentication.login()).thenReturn(
			LoginToken.renewable("login".toCharArray(), Duration.ofSeconds(5)));
	when(
			restOperations.postForObject(anyString(), any(),
					ArgumentMatchers.<Class> any())).thenThrow(
			new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR));

	ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);

	sessionManager.getSessionToken();
	verify(taskScheduler).schedule(runnableCaptor.capture(), any(Trigger.class));

	runnableCaptor.getValue().run();

	verify(taskScheduler, times(1)).schedule(any(Runnable.class), any(Trigger.class));
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:20,代码来源:LifecycleAwareSessionManagerUnitTests.java

示例9: shouldNotScheduleRenewalIfRenewalTtlExceedsThreshold

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldNotScheduleRenewalIfRenewalTtlExceedsThreshold() {

	mockToken(LoginToken.renewable("login".toCharArray(), Duration.ofSeconds(5)));
	when(responseSpec.bodyToMono(VaultResponse.class)).thenReturn(
			Mono.just(fromToken(LoginToken.of("foo".toCharArray(),
					Duration.ofSeconds(2)))));

	ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);

	sessionManager.getSessionToken().as(StepVerifier::create).expectNextCount(1)
			.verifyComplete();
	verify(taskScheduler).schedule(runnableCaptor.capture(), any(Trigger.class));

	runnableCaptor.getValue().run();

	verify(taskScheduler, times(1)).schedule(any(Runnable.class), any(Trigger.class));
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:19,代码来源:ReactiveLifecycleAwareSessionManagerUnitTests.java

示例10: shouldRenewLease

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldRenewLease() {

	prepareRenewal();
	when(vaultOperations.doWithSession(any(RestOperationsCallback.class)))
			.thenReturn(getResponseEntity("new_lease", true, 70, HttpStatus.OK));

	secretLeaseContainer.start();

	ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
	verify(taskScheduler).schedule(captor.capture(), any(Trigger.class));

	captor.getValue().run();
	verifyZeroInteractions(scheduledFuture);
	verify(taskScheduler, times(2)).schedule(captor.capture(), any(Trigger.class));
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:17,代码来源:SecretLeaseContainerUnitTests.java

示例11: shouldNotRenewExpiringLease

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldNotRenewExpiringLease() {

	prepareRenewal();
	when(vaultOperations.doWithSession(any(RestOperationsCallback.class)))
			.thenReturn(getResponseEntity("new_lease", true, 5, HttpStatus.OK));

	secretLeaseContainer.start();

	ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
	verify(taskScheduler).schedule(captor.capture(), any(Trigger.class));

	captor.getValue().run();
	verifyZeroInteractions(scheduledFuture);
	verify(taskScheduler, times(1)).schedule(captor.capture(), any(Trigger.class));
	verify(leaseListenerAdapter).onLeaseEvent(any(SecretLeaseCreatedEvent.class));
	verify(leaseListenerAdapter).onLeaseEvent(any(SecretLeaseExpiredEvent.class));
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:19,代码来源:SecretLeaseContainerUnitTests.java

示例12: shouldPublishRenewalErrors

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldPublishRenewalErrors() {

	prepareRenewal();
	when(vaultOperations.doWithSession(any(RestOperationsCallback.class))).thenThrow(
			new HttpClientErrorException(HttpStatus.I_AM_A_TEAPOT));

	secretLeaseContainer.start();

	ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
	verify(taskScheduler).schedule(runnableCaptor.capture(), any(Trigger.class));

	runnableCaptor.getValue().run();

	verify(leaseListenerAdapter).onLeaseEvent(any(SecretLeaseCreatedEvent.class));
	verify(leaseListenerAdapter).onLeaseError(captor.capture(),
			any(VaultException.class));
	verifyNoMoreInteractions(leaseListenerAdapter);

	SecretLeaseEvent leaseEvent = captor.getValue();

	assertThat(leaseEvent.getSource()).isEqualTo(requestedSecret);
	assertThat(leaseEvent.getLease()).isNotNull();
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:25,代码来源:SecretLeaseContainerUnitTests.java

示例13: shouldRequestRotatingGenericSecrets

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldRequestRotatingGenericSecrets() {

	when(taskScheduler.schedule(any(Runnable.class), any(Trigger.class))).thenReturn(
			scheduledFuture);

	when(vaultOperations.read(rotatingGenericSecret.getPath())).thenReturn(
			createGenericSecrets());

	secretLeaseContainer.addRequestedSecret(rotatingGenericSecret);
	secretLeaseContainer.start();

	verify(leaseListenerAdapter).onLeaseEvent(captor.capture());

	SecretLeaseCreatedEvent leaseCreatedEvent = (SecretLeaseCreatedEvent) captor
			.getValue();

	assertThat(leaseCreatedEvent.getSource()).isEqualTo(rotatingGenericSecret);
	assertThat(leaseCreatedEvent.getLease()).isNotNull();
	assertThat(leaseCreatedEvent.getSecrets()).containsKey("key");
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:22,代码来源:SecretLeaseContainerUnitTests.java

示例14: afterPropertiesSet

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
	JobKey jobKey = new JobKey(pollingEndpointBeanName);

	if (!scheduler.checkExists(jobKey)) {
		JobDetail jobDetail = JobBuilder.newJob(PollingEndpointQuartzBridgeJob.class)
				.withIdentity(jobKey)
				.storeDurably()
				.build();

		JobDataMap jobDataMap = new JobDataMap();
		jobDataMap.put(PollingEndpointQuartzBridgeJob.POLLING_ENDPOINT_BEAN_NAME_KEY, pollingEndpointBeanName);
		jobDataMap.put(PollingEndpointQuartzBridgeJob.TRIGGER_BEAN_NAME_KEY, triggerBeanName);

		org.quartz.Trigger trigger = TriggerBuilder.newTrigger()
				.withIdentity(pollingEndpointBeanName)
				.withSchedule(scheduleBuilder)
				.forJob(jobDetail)
				.usingJobData(jobDataMap)
				.build();

		scheduler.scheduleJob(jobDetail, trigger);
	}
}
 
开发者ID:vpavic,项目名称:spring-integration-quartz-bridge,代码行数:25,代码来源:PollingEndpointQuartzBridgeTrigger.java

示例15: shouldBuildTriggers

import org.springframework.scheduling.Trigger; //导入依赖的package包/类
@Test
public void shouldBuildTriggers() {
	
	String[] expressions = new String[]{ 
			"fixed-rate:100",
			"fixed-delay:100",
			"fixed-rate:10,fixed-delay:10",
			"0 0 * 14 3 ?",
			"timerange:10:00:00->12:00:00->(fixed-rate:100)"
	};
	
	TriggerBuilder triggerBuilder = new TriggerBuilder();
	for (String expression : expressions) {
		Trigger trigger = triggerBuilder.build(expression);
		TriggerContext triggerContext = new SimpleTriggerContext();
		trigger.nextExecutionTime(triggerContext);
	}
	
}
 
开发者ID:danidemi,项目名称:jlubricant,代码行数:20,代码来源:TriggerBuilderTest.java


注:本文中的org.springframework.scheduling.Trigger类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。