Search in sources :

Example 1 with ConcurrentTaskScheduler

use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project spring-integration by spring-projects.

the class StompSessionManagerTests method testDoConnectFailure.

@Test
public void testDoConnectFailure() throws Exception {
    StompClientSupport stompClient = mock(StompClientSupport.class);
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
    AbstractStompSessionManager sessionManager = new AbstractStompSessionManager(stompClient) {

        private final AtomicBoolean thrown = new AtomicBoolean();

        @Override
        protected ListenableFuture<StompSession> doConnect(StompSessionHandler handler) {
            if (!this.thrown.getAndSet(true)) {
                throw new RuntimeException("intentional");
            } else {
                SettableListenableFuture<StompSession> future = new SettableListenableFuture<StompSession>();
                StompSession stompSession = mock(StompSession.class);
                future.set(stompSession);
                handler.afterConnected(stompSession, getConnectHeaders());
                return future;
            }
        }
    };
    sessionManager.start();
    final SettableListenableFuture<StompSession> stompSessionFuture = new SettableListenableFuture<StompSession>();
    sessionManager.connect(new StompSessionHandlerAdapter() {

        @Override
        public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
            stompSessionFuture.set(session);
        }
    });
    assertNotNull(stompSessionFuture.get(10, TimeUnit.SECONDS));
    sessionManager.stop();
}
Also used : ConcurrentTaskScheduler(org.springframework.scheduling.concurrent.ConcurrentTaskScheduler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) StompClientSupport(org.springframework.messaging.simp.stomp.StompClientSupport) StompSession(org.springframework.messaging.simp.stomp.StompSession) StompSessionHandler(org.springframework.messaging.simp.stomp.StompSessionHandler) StompHeaders(org.springframework.messaging.simp.stomp.StompHeaders) StompSessionHandlerAdapter(org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter) Test(org.junit.Test)

Example 2 with ConcurrentTaskScheduler

use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project spring-security by spring-projects.

the class DelegatingSecurityContextTaskSchedulerTests method scheduleWhenSecurityContextThenSecurityContextPropagated.

@Test
public void scheduleWhenSecurityContextThenSecurityContextPropagated() throws Exception {
    willAnswer((invocation) -> {
        assertThat(SecurityContextHolder.getContext()).isEqualTo(this.securityContext);
        return null;
    }).given(this.runnable).run();
    TaskScheduler delegateTaskScheduler = new ConcurrentTaskScheduler();
    this.delegatingSecurityContextTaskScheduler = new DelegatingSecurityContextTaskScheduler(delegateTaskScheduler, this.securityContext);
    assertWrapped(this.runnable);
}
Also used : ConcurrentTaskScheduler(org.springframework.scheduling.concurrent.ConcurrentTaskScheduler) TaskScheduler(org.springframework.scheduling.TaskScheduler) ConcurrentTaskScheduler(org.springframework.scheduling.concurrent.ConcurrentTaskScheduler) Test(org.junit.jupiter.api.Test)

Example 3 with ConcurrentTaskScheduler

use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project CVE-2018-1270 by CaledoniaProject.

the class ServiceClient method main.

public static void main(String... argv) {
    WebSocketClient webSocketClient = new StandardWebSocketClient();
    WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new MappingJackson2MessageConverter());
    stompClient.setTaskScheduler(new ConcurrentTaskScheduler());
    String url = "ws://127.0.0.1:8080/hello";
    StompSessionHandler sessionHandler = new MySessionHandler();
    stompClient.connect(url, sessionHandler);
    // Don't close immediately.
    new Scanner(System.in).nextLine();
}
Also used : ConcurrentTaskScheduler(org.springframework.scheduling.concurrent.ConcurrentTaskScheduler) Scanner(java.util.Scanner) MappingJackson2MessageConverter(org.springframework.messaging.converter.MappingJackson2MessageConverter) StompSessionHandler(org.springframework.messaging.simp.stomp.StompSessionHandler) WebSocketStompClient(org.springframework.web.socket.messaging.WebSocketStompClient) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) WebSocketClient(org.springframework.web.socket.client.WebSocketClient) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient)

Example 4 with ConcurrentTaskScheduler

use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project spring-security by spring-projects.

the class DelegatingSecurityContextTaskSchedulerTests method scheduleWhenDefaultThenCurrentSecurityContextPropagated.

@Test
public void scheduleWhenDefaultThenCurrentSecurityContextPropagated() throws Exception {
    willAnswer((invocation) -> {
        assertThat(SecurityContextHolder.getContext()).isEqualTo(this.originalSecurityContext);
        return null;
    }).given(this.runnable).run();
    TaskScheduler delegateTaskScheduler = new ConcurrentTaskScheduler();
    this.delegatingSecurityContextTaskScheduler = new DelegatingSecurityContextTaskScheduler(delegateTaskScheduler);
    assertWrapped(this.runnable);
}
Also used : ConcurrentTaskScheduler(org.springframework.scheduling.concurrent.ConcurrentTaskScheduler) TaskScheduler(org.springframework.scheduling.TaskScheduler) ConcurrentTaskScheduler(org.springframework.scheduling.concurrent.ConcurrentTaskScheduler) Test(org.junit.jupiter.api.Test)

Example 5 with ConcurrentTaskScheduler

use of org.springframework.scheduling.concurrent.ConcurrentTaskScheduler in project spring-framework by spring-projects.

the class ScheduledTaskRegistrar method scheduleTasks.

/**
 * Schedule all registered tasks against the underlying
 * {@linkplain #setTaskScheduler(TaskScheduler) task scheduler}.
 */
@SuppressWarnings("deprecation")
protected void scheduleTasks() {
    if (this.taskScheduler == null) {
        this.localExecutor = Executors.newSingleThreadScheduledExecutor();
        this.taskScheduler = new ConcurrentTaskScheduler(this.localExecutor);
    }
    if (this.triggerTasks != null) {
        for (TriggerTask task : this.triggerTasks) {
            addScheduledTask(scheduleTriggerTask(task));
        }
    }
    if (this.cronTasks != null) {
        for (CronTask task : this.cronTasks) {
            addScheduledTask(scheduleCronTask(task));
        }
    }
    if (this.fixedRateTasks != null) {
        for (IntervalTask task : this.fixedRateTasks) {
            addScheduledTask(scheduleFixedRateTask(task));
        }
    }
    if (this.fixedDelayTasks != null) {
        for (IntervalTask task : this.fixedDelayTasks) {
            addScheduledTask(scheduleFixedDelayTask(task));
        }
    }
}
Also used : ConcurrentTaskScheduler(org.springframework.scheduling.concurrent.ConcurrentTaskScheduler)

Aggregations

ConcurrentTaskScheduler (org.springframework.scheduling.concurrent.ConcurrentTaskScheduler)5 Test (org.junit.jupiter.api.Test)2 StompSessionHandler (org.springframework.messaging.simp.stomp.StompSessionHandler)2 TaskScheduler (org.springframework.scheduling.TaskScheduler)2 Scanner (java.util.Scanner)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 MappingJackson2MessageConverter (org.springframework.messaging.converter.MappingJackson2MessageConverter)1 StompClientSupport (org.springframework.messaging.simp.stomp.StompClientSupport)1 StompHeaders (org.springframework.messaging.simp.stomp.StompHeaders)1 StompSession (org.springframework.messaging.simp.stomp.StompSession)1 StompSessionHandlerAdapter (org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter)1 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)1 WebSocketClient (org.springframework.web.socket.client.WebSocketClient)1 StandardWebSocketClient (org.springframework.web.socket.client.standard.StandardWebSocketClient)1 WebSocketStompClient (org.springframework.web.socket.messaging.WebSocketStompClient)1