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


Java TaskScheduler类代码示例

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


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

示例1: postProcessAfterInitialization

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Test
public void postProcessAfterInitialization() throws Exception {
    assertThat(processor.postProcessAfterInitialization(mock(Executor.class), toBeExcluded).getClass(),
            not(equalTo(ContextAwareExecutor.class)));
    //concurrent
    assertThat(processor.postProcessAfterInitialization(mock(Executor.class), beanName).getClass(),
            equalTo(ContextAwareExecutor.class));
    assertThat(processor.postProcessAfterInitialization(mock(ExecutorService.class), beanName).getClass(),
            equalTo(ContextAwareExecutorService.class));
    assertThat(processor.postProcessAfterInitialization(mock(ScheduledExecutorService.class), beanName).getClass(),
            equalTo(ContextAwareScheduledExecutorService.class));

    //spring
    assertThat(processor.postProcessAfterInitialization(mock(TaskScheduler.class), beanName).getClass(),
            equalTo(ContextAwareTaskScheduler.class));
    assertThat(processor.postProcessAfterInitialization(new ThreadPoolTaskExecutor(), beanName).getClass(),
            equalTo(ContextAwareThreadPoolTaskExecutor.class));
    assertThat(processor.postProcessAfterInitialization(new ThreadPoolTaskScheduler(), beanName).getClass(),
            equalTo(ContextAwareThreadPoolTaskScheduler.class));
    assertThat(processor.postProcessAfterInitialization(mock(AsyncListenableTaskExecutor.class), beanName).getClass(),
            equalTo(ContextAwareAsyncListenableTaskExecutor.class));
    assertThat(processor.postProcessAfterInitialization(mock(AsyncTaskExecutor.class), beanName).getClass(),
            equalTo(ContextAwareAsyncTaskExecutor.class));
    assertThat(processor.postProcessAfterInitialization(mock(SchedulingTaskExecutor.class), beanName).getClass(),
            equalTo(ContextAwareSchedulingTaskExecutor.class));
}
 
开发者ID:enadim,项目名称:spring-cloud-ribbon-extensions,代码行数:27,代码来源:PreservesExecutionContextExecutorStrategyTest.java

示例2: bbTaskScheduler

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Bean
public TaskScheduler bbTaskScheduler() {
	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.setThreadNamePrefix("API-Schd-ThrP-");
	taskScheduler.setAwaitTerminationSeconds(1);
	taskScheduler.setRejectedExecutionHandler(new ThreadPoolTaskRejectedHandler());
	
	return taskScheduler;
}
 
开发者ID:BuaBook,项目名称:buabook-api-interface,代码行数:10,代码来源:BuaBookApiInterfaceConfig.java

示例3: sendWithReceipt

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Test
public void sendWithReceipt() throws Exception {

	this.session.afterConnected(this.connection);
	assertTrue(this.session.isConnected());

	this.session.setTaskScheduler(mock(TaskScheduler.class));
	this.session.setAutoReceipt(true);
	this.session.send("/topic/foo", "sample payload");

	Message<byte[]> message = this.messageCaptor.getValue();
	StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertNotNull(accessor.getReceipt());

	StompHeaders stompHeaders = new StompHeaders();
	stompHeaders.setDestination("/topic/foo");
	stompHeaders.setReceipt("my-receipt");
	this.session.send(stompHeaders, "sample payload");

	message = this.messageCaptor.getValue();
	accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
	assertEquals("my-receipt", accessor.getReceipt());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DefaultStompSessionTests.java

示例4: receiptReceived

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Test
public void receiptReceived() throws Exception {

	this.session.afterConnected(this.connection);
	this.session.setTaskScheduler(mock(TaskScheduler.class));

	AtomicReference<Boolean> received = new AtomicReference<>();

	StompHeaders headers = new StompHeaders();
	headers.setDestination("/topic/foo");
	headers.setReceipt("my-receipt");
	Subscription subscription = this.session.subscribe(headers, mock(StompFrameHandler.class));
	subscription.addReceiptTask(() -> received.set(true));

	assertNull(received.get());

	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.RECEIPT);
	accessor.setReceiptId("my-receipt");
	accessor.setLeaveMutable(true);
	this.session.handleMessage(MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders()));

	assertNotNull(received.get());
	assertTrue(received.get());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:DefaultStompSessionTests.java

示例5: receiptReceivedBeforeTaskAdded

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Test
public void receiptReceivedBeforeTaskAdded() throws Exception {

	this.session.afterConnected(this.connection);
	this.session.setTaskScheduler(mock(TaskScheduler.class));

	AtomicReference<Boolean> received = new AtomicReference<>();

	StompHeaders headers = new StompHeaders();
	headers.setDestination("/topic/foo");
	headers.setReceipt("my-receipt");
	Subscription subscription = this.session.subscribe(headers, mock(StompFrameHandler.class));

	StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.RECEIPT);
	accessor.setReceiptId("my-receipt");
	accessor.setLeaveMutable(true);
	this.session.handleMessage(MessageBuilder.createMessage(new byte[0], accessor.getMessageHeaders()));

	subscription.addReceiptTask(() -> received.set(true));

	assertNotNull(received.get());
	assertTrue(received.get());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DefaultStompSessionTests.java

示例6: TransportHandlingSockJsService

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
/**
 * Create a TransportHandlingSockJsService with given {@link TransportHandler handler} types.
 * @param scheduler a task scheduler for heart-beat messages and removing timed-out sessions;
 * the provided TaskScheduler should be declared as a Spring bean to ensure it gets
 * initialized at start-up and shuts down when the application stops
 * @param handlers one or more {@link TransportHandler} implementations to use
 */
public TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) {
	super(scheduler);

	if (CollectionUtils.isEmpty(handlers)) {
		logger.warn("No transport handlers specified for TransportHandlingSockJsService");
	}
	else {
		for (TransportHandler handler : handlers) {
			handler.initialize(this);
			this.handlers.put(handler.getTransportType(), handler);
		}
	}

	if (jackson2Present) {
		this.messageCodec = new Jackson2SockJsMessageCodec();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:TransportHandlingSockJsService.java

示例7: fallbackAfterTimeout

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Test
public void fallbackAfterTimeout() throws Exception {
	TaskScheduler scheduler = mock(TaskScheduler.class);
	Runnable sessionCleanupTask = mock(Runnable.class);
	DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET);
	DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING);
	request1.setFallbackRequest(request2);
	request1.setTimeoutScheduler(scheduler);
	request1.addTimeoutTask(sessionCleanupTask);
	request1.connect(null, this.connectFuture);

	assertTrue(this.webSocketTransport.invoked());
	assertFalse(this.xhrTransport.invoked());

	// Get and invoke the scheduled timeout task
	ArgumentCaptor<Runnable> taskCaptor = ArgumentCaptor.forClass(Runnable.class);
	verify(scheduler).schedule(taskCaptor.capture(), any(Date.class));
	verifyNoMoreInteractions(scheduler);
	taskCaptor.getValue().run();

	assertTrue(this.xhrTransport.invoked());
	verify(sessionCleanupTask).run();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DefaultTransportRequestTests.java

示例8: doTestWrapperTokenCreated

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
private void doTestWrapperTokenCreated(String authMountPath) {
    final ClientHttpRequestFactory factory = createClientHttpRequestFactory();
    final VaultTemplate template = new VaultTemplate(getVault().getEndpoint(), factory, () -> VaultToken.of(getVault().getToken()));

    // Ensure approle auth enabled
    template.opsForSys().authMount(authMountPath, VaultMount.create("approle"));
    then(template.opsForSys().getAuthMounts()).containsKey(authMountPath + "/");
    template.write("auth/" + authMountPath + "/role/testrole", CollectionsUtil.asMap(
            "secret_id_ttl", "10m",
            "token_num_uses", "10",
            "token_ttl", "20m",
            "token_max_ttl", "30m",
            "secret_id_num_uses", "40"
    ));
    Pair<String, String> credentials = getAppRoleCredentials(template, "auth/" + authMountPath + "/role/testrole");


    final Pair<String, String> wrapped = VaultConnector.doRequestWrappedToken(new VaultFeatureSettings(getVault().getUrl(), authMountPath, credentials.getFirst(), credentials.getSecond()));

    then(wrapped.getFirst()).isNotNull();
    then(wrapped.getSecond()).isNotNull();


    final CubbyholeAuthenticationOptions options = CubbyholeAuthenticationOptions.builder()
            .wrapped()
            .initialToken(VaultToken.of(wrapped.getFirst()))
            .build();
    final RestTemplate simpleTemplate = UtilKt.createRestTemplate(new VaultFeatureSettings(getVault().getUrl(), authMountPath, "", ""));
    final CubbyholeAuthentication authentication = new CubbyholeAuthentication(options, simpleTemplate);
    final TaskScheduler scheduler = new ConcurrentTaskScheduler();

    final MyLifecycleAwareSessionManager sessionManager = new MyLifecycleAwareSessionManager(authentication, simpleTemplate, scheduler);

    then(sessionManager.getSessionToken()).isNotNull();

    sessionManager.renewToken();

    then(sessionManager.getSessionToken()).isNotNull();
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:40,代码来源:VaultConnectorTest.java

示例9: taskScheduler

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Bean
public TaskScheduler taskScheduler () {
	ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
	scheduler.setThreadNamePrefix( CsapCoreService.class.getSimpleName() + "Scheduler" );
	scheduler.setPoolSize( 2 );
	return scheduler;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:8,代码来源:CsapCoreService.java

示例10: setScheduledTask

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
public void setScheduledTask(Runnable task, Trigger trigger ){
    
    if(this.scheduleFuture!=null){
        this.scheduleFuture.cancel(true);
    }
    
    TaskScheduler taskScheduler = this.taskRegistrar.getScheduler(); 
    this.scheduleFuture = taskScheduler.schedule(task, trigger);
}
 
开发者ID:jrtechnologies,项目名称:yum,代码行数:10,代码来源:ScheduledTasks.java

示例11: onApplicationEvent

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
	if (event.getApplicationContext() != this.applicationContext) {
		return;
	}

	if (this.scheduler != null) {
		this.registrar.setScheduler(this.scheduler);
	}

	Map<String, SchedulingConfigurer> configurers =
			this.applicationContext.getBeansOfType(SchedulingConfigurer.class);
	for (SchedulingConfigurer configurer : configurers.values()) {
		configurer.configureTasks(this.registrar);
	}

	if (this.registrar.hasTasks() && this.registrar.getScheduler() == null) {
		Map<String, ? super Object> schedulers = new HashMap<String, Object>();
		schedulers.putAll(this.applicationContext.getBeansOfType(TaskScheduler.class));
		schedulers.putAll(this.applicationContext.getBeansOfType(ScheduledExecutorService.class));
		if (schedulers.size() == 0) {
			// do nothing -> fall back to default scheduler
		}
		else if (schedulers.size() == 1) {
			this.registrar.setScheduler(schedulers.values().iterator().next());
		}
		else if (schedulers.size() >= 2){
			throw new IllegalStateException(
					"More than one TaskScheduler and/or ScheduledExecutorService  " +
					"exist within the context. Remove all but one of the beans; or " +
					"implement the SchedulingConfigurer interface and call " +
					"ScheduledTaskRegistrar#setScheduler explicitly within the " +
					"configureTasks() callback. Found the following beans: " + schedulers.keySet());
		}
	}

	this.registrar.afterPropertiesSet();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:ScheduledAnnotationBeanPostProcessor.java

示例12: setScheduler

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
/**
 * Set the {@link TaskScheduler} to register scheduled tasks with, or a
 * {@link java.util.concurrent.ScheduledExecutorService} to be wrapped as a
 * {@code TaskScheduler}.
 */
public void setScheduler(Object scheduler) {
	Assert.notNull(scheduler, "Scheduler object must not be null");
	if (scheduler instanceof TaskScheduler) {
		this.taskScheduler = (TaskScheduler) scheduler;
	}
	else if (scheduler instanceof ScheduledExecutorService) {
		this.taskScheduler = new ConcurrentTaskScheduler(((ScheduledExecutorService) scheduler));
	}
	else {
		throw new IllegalArgumentException("Unsupported scheduler type: " + scheduler.getClass());
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ScheduledTaskRegistrar.java

示例13: testReconnectDetailsSetServerAvailableAtStartup

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Test
public void testReconnectDetailsSetServerAvailableAtStartup()
    throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    TaskScheduler taskScheduler = new ConcurrentTaskScheduler();
    MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
        null);
    service.setApplicationEventPublisher(applicationContext);
    service.setInboundMessageChannel(inboundMessageChannel);
    service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
        MqttQualityOfService.QOS_0);
    service.getMqttConnectOptions().setCleanSession(true);
    service.setReconnectDetails(new DefaultReconnectService(), taskScheduler);
    Assert.assertTrue(service.start());
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    // simulate a lost connection
    CRUSHER_PROXY.reopen();
    Assert.assertFalse(service.isStarted());
    Assert.assertFalse(service.isConnected());
    Thread.sleep(1100);
    Assert.assertTrue(service.isStarted());
    Assert.assertTrue(service.isConnected());
    Assert.assertEquals(2, clientConnectedCount.get());
    Assert.assertEquals(0, clientDisconnectedCount.get());
    Assert.assertEquals(1, clientLostConnectionCount.get());
    Assert.assertEquals(0, clientFailedConnectionCount.get());
    service.stop();
    service.close();
    applicationContext.close();
}
 
开发者ID:christophersmith,项目名称:summer-mqtt,代码行数:35,代码来源:AutomaticReconnectTest.java

示例14: testReconnectDetailsSetServerUnavailableAtStartup

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Test
public void testReconnectDetailsSetServerUnavailableAtStartup()
    throws MqttException, InterruptedException
{
    StaticApplicationContext applicationContext = getStaticApplicationContext();
    CRUSHER_PROXY.close();
    TaskScheduler taskScheduler = new ConcurrentTaskScheduler();
    MessageChannel inboundMessageChannel = new ExecutorSubscribableChannel();
    PahoAsyncMqttClientService service = new PahoAsyncMqttClientService(
        BrokerHelper.getProxyUri(), BrokerHelper.getClientId(), MqttClientConnectionType.PUBSUB,
        null);
    service.setApplicationEventPublisher(applicationContext);
    service.setInboundMessageChannel(inboundMessageChannel);
    service.subscribe(String.format("client/%s", BrokerHelper.getClientId()),
        MqttQualityOfService.QOS_0);
    service.getMqttConnectOptions().setCleanSession(true);
    service.setReconnectDetails(new DefaultReconnectService(), taskScheduler);
    Assert.assertFalse(service.start());
    Assert.assertFalse(service.isConnected());
    Assert.assertFalse(service.isStarted());
    CRUSHER_PROXY.open();
    Thread.sleep(3100);
    Assert.assertTrue(service.isConnected());
    Assert.assertTrue(service.isStarted());
    Assert.assertEquals(1, clientConnectedCount.get());
    Assert.assertEquals(0, clientDisconnectedCount.get());
    Assert.assertEquals(0, clientLostConnectionCount.get());
    Assert.assertEquals(1, clientFailedConnectionCount.get());
    service.stop();
    service.close();
    applicationContext.close();
}
 
开发者ID:christophersmith,项目名称:summer-mqtt,代码行数:33,代码来源:AutomaticReconnectTest.java

示例15: test

import org.springframework.scheduling.TaskScheduler; //导入依赖的package包/类
@Test
public void test()
{
    AbstractMqttClientService clientService = Mockito.mock(AbstractMqttClientService.class,
        Mockito.withSettings().useConstructor(MqttClientConnectionType.PUBSUB)
            .defaultAnswer(Mockito.CALLS_REAL_METHODS));
    Assert.assertEquals(MqttClientConnectionType.PUBSUB, clientService.getConnectionType());
    Assert.assertFalse(clientService.isStarted());
    Assert.assertNotNull(clientService.getMqttClientConfiguration());
    Assert.assertNull(clientService.applicationEventPublisher);
    clientService.setApplicationEventPublisher(Mockito.mock(ApplicationEventPublisher.class));
    Assert.assertNotNull(clientService.applicationEventPublisher);
    clientService.subscribe("inbound/client");
    Mockito.verify(clientService, Mockito.times(1)).subscribe(Mockito.anyString(),
        Mockito.any());
    Assert.assertNull(clientService.inboundMessageChannel);
    clientService.setInboundMessageChannel(Mockito.mock(MessageChannel.class));
    Assert.assertNotNull(clientService.inboundMessageChannel);
    Assert.assertNull(clientService.reconnectService);
    Assert.assertNull(clientService.taskScheduler);
    clientService.setReconnectDetails(Mockito.mock(ReconnectService.class),
        Mockito.mock(TaskScheduler.class));
    Assert.assertNotNull(clientService.reconnectService);
    Assert.assertNotNull(clientService.taskScheduler);
    Assert.assertEquals(0, clientService.getTopicSubscriptions().size());
    clientService.topicSubscriptions
        .add(new TopicSubscription("test", MqttQualityOfService.QOS_0));
    Assert.assertEquals(1, clientService.getTopicSubscriptions().size());
}
 
开发者ID:christophersmith,项目名称:summer-mqtt,代码行数:30,代码来源:AbstractMqttClientServiceTest.java


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