Package org.springframework.scheduling

Examples of org.springframework.scheduling.TaskScheduler


   * @param beanFactory BeanFactory for lookup, must not be null.
   * @return task scheduler
   * @throws IllegalStateException if no such bean is available
   */
  public static TaskScheduler getRequiredTaskScheduler(BeanFactory beanFactory) {
    TaskScheduler taskScheduler = getTaskScheduler(beanFactory);
    Assert.state(taskScheduler != null, "No such bean '" + TASK_SCHEDULER_BEAN_NAME + "'");
    return taskScheduler;
  }
View Full Code Here


*/
public class PollingTaskSupportTests {

  @Test
  public void testPollingTask() throws InterruptedException {
    TaskScheduler taskScheduler = new ConcurrentTaskScheduler();
    TaskExecutor taskExecutor = new SyncTaskExecutor();
    TestPollingTaskSupport poller = new TestPollingTaskSupport(taskScheduler, taskExecutor,
        TimeUnit.SECONDS, 2);
    poller.init();
    poller.start();
View Full Code Here

    // if these tests starts to fail or cause other timing
    // problems, we need to find a better way to run
    // test without adding too long sleeps

    TaskScheduler taskScheduler = new ConcurrentTaskScheduler();
    TaskExecutor taskExecutor = new ConcurrentTaskExecutor();
    TestPollingTaskSupport poller = new TestPollingTaskSupport(taskScheduler, taskExecutor);
    IdleTimeoutTrigger trigger = new IdleTimeoutTrigger(1000);
    poller.setTrigger(trigger);
    poller.init();
View Full Code Here

    SubscribableChannel channel = mock(SubscribableChannel.class);
    SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
    StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
    handler.addProtocolHandler(stompHandler);

    TaskScheduler scheduler = mock(TaskScheduler.class);
    DefaultSockJsService service = new DefaultSockJsService(scheduler);
    WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
    SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

    assertEquals(stompHandler.getSupportedProtocols(), sockJsHandler.getSubProtocols());
View Full Code Here

  }

  @Test
  public void getSubProtocolsNone() throws Exception {
    WebSocketHandler handler = new TextWebSocketHandler();
    TaskScheduler scheduler = mock(TaskScheduler.class);
    DefaultSockJsService service = new DefaultSockJsService(scheduler);
    WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
    SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);

    assertNull(sockJsHandler.getSubProtocols());
View Full Code Here

    this.connectFuture.get();
  }

  @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);
View Full Code Here

    }
  }

  private ScheduledFuture<?> getSchedule(final Callable<T> callable, final Queue<T> queue, final AtomicReference<Throwable> throwable) {

    TaskScheduler scheduler = taskScheduler;
    if (scheduler == null) {
      ConcurrentTaskScheduler concurrentTaskScheduler = new ConcurrentTaskScheduler();
      concurrentTaskScheduler.setErrorHandler(new PropagatingErrorHandler());
      scheduler = concurrentTaskScheduler;
    }

    Runnable task = new Runnable() {

      public void run() {
        if (!queue.isEmpty() || throwable.get() != null) {
          return;
        }
        T result;
        try {
          result = callable.call();
        }
        catch (RuntimeException e) {
          throwable.set(e);
          throw e;
        }
        catch (Exception e) {
          throwable.set(e);
          throw new IllegalStateException("Could not obtain result", e);
        }
        if (result != null) {
          queue.add(result);
        }
      }
    };

    ScheduledFuture<?> schedule = scheduler.schedule(task, trigger);

    return schedule;

  }
View Full Code Here

TOP

Related Classes of org.springframework.scheduling.TaskScheduler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.