Search in sources :

Example 1 with SimpleAsyncTaskExecutor

use of org.springframework.core.task.SimpleAsyncTaskExecutor in project camel by apache.

the class DefaultJmsMessageListenerContainer method createDefaultTaskExecutor.

/**
     * Create a default TaskExecutor. Called if no explicit TaskExecutor has been specified.
     * <p />
     * The type of {@link TaskExecutor} will depend on the value of
     * {@link JmsConfiguration#getDefaultTaskExecutorType()}. For more details, refer to the Javadoc of
     * {@link DefaultTaskExecutorType}.
     * <p />
     * In all cases, it uses the specified bean name and Camel's {@link org.apache.camel.spi.ExecutorServiceManager}
     * to resolve the thread name.
     * @see JmsConfiguration#setDefaultTaskExecutorType(DefaultTaskExecutorType)
     * @see ThreadPoolTaskExecutor#setBeanName(String)
     */
@Override
protected TaskExecutor createDefaultTaskExecutor() {
    String pattern = endpoint.getCamelContext().getExecutorServiceManager().getThreadNamePattern();
    String beanName = getBeanName() == null ? endpoint.getThreadName() : getBeanName();
    TaskExecutor answer;
    if (endpoint.getDefaultTaskExecutorType() == DefaultTaskExecutorType.ThreadPool) {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setBeanName(beanName);
        executor.setThreadFactory(new CamelThreadFactory(pattern, beanName, true));
        executor.setCorePoolSize(endpoint.getConcurrentConsumers());
        // Direct hand-off mode. Do not queue up tasks: assign it to a thread immediately.
        // We set no upper-bound on the thread pool (no maxPoolSize) as it's already implicitly constrained by
        // maxConcurrentConsumers on the DMLC itself (i.e. DMLC will only grow up to a level of concurrency as
        // defined by maxConcurrentConsumers).
        executor.setQueueCapacity(0);
        executor.initialize();
        answer = executor;
    } else {
        SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(beanName);
        executor.setThreadFactory(new CamelThreadFactory(pattern, beanName, true));
        answer = executor;
    }
    taskExecutor = answer;
    return answer;
}
Also used : CamelThreadFactory(org.apache.camel.util.concurrent.CamelThreadFactory) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Example 2 with SimpleAsyncTaskExecutor

use of org.springframework.core.task.SimpleAsyncTaskExecutor in project spring-security by spring-projects.

the class WebAsyncManagerIntegrationFilterTests method setUp.

@Before
public void setUp() {
    when(asyncWebRequest.getNativeRequest(HttpServletRequest.class)).thenReturn(request);
    when(request.getRequestURI()).thenReturn("/");
    filterChain = new MockFilterChain();
    threadFactory = new JoinableThreadFactory();
    SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
    executor.setThreadFactory(threadFactory);
    asyncManager = WebAsyncUtils.getAsyncManager(request);
    asyncManager.setAsyncWebRequest(asyncWebRequest);
    asyncManager.setTaskExecutor(executor);
    when(request.getAttribute(WebAsyncUtils.WEB_ASYNC_MANAGER_ATTRIBUTE)).thenReturn(asyncManager);
    filter = new WebAsyncManagerIntegrationFilter();
}
Also used : SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) MockFilterChain(org.springframework.mock.web.MockFilterChain) Before(org.junit.Before)

Example 3 with SimpleAsyncTaskExecutor

use of org.springframework.core.task.SimpleAsyncTaskExecutor in project spring-framework by spring-projects.

the class StandardWebSocketClientTests method taskExecutor.

@Test
public void taskExecutor() throws Exception {
    URI uri = new URI("ws://localhost/abc");
    this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor());
    WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get();
    assertNotNull(session);
}
Also used : SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) URI(java.net.URI) WebSocketSession(org.springframework.web.socket.WebSocketSession) Test(org.junit.Test)

Example 4 with SimpleAsyncTaskExecutor

use of org.springframework.core.task.SimpleAsyncTaskExecutor in project spring-framework by spring-projects.

the class JettyWebSocketClientTests method doHandshakeWithTaskExecutor.

@Test
public void doHandshakeWithTaskExecutor() throws Exception {
    WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
    headers.setSecWebSocketProtocol(Arrays.asList("echo"));
    this.client.setTaskExecutor(new SimpleAsyncTaskExecutor());
    this.wsSession = this.client.doHandshake(new TextWebSocketHandler(), headers, new URI(this.wsUrl)).get();
    assertEquals(this.wsUrl, this.wsSession.getUri().toString());
    assertEquals("echo", this.wsSession.getAcceptedProtocol());
}
Also used : WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) TextWebSocketHandler(org.springframework.web.socket.handler.TextWebSocketHandler) URI(java.net.URI) Test(org.junit.Test)

Example 5 with SimpleAsyncTaskExecutor

use of org.springframework.core.task.SimpleAsyncTaskExecutor in project spring-framework by spring-projects.

the class BufferedSimpleAsyncHttpRequestFactoryTests method createRequestFactory.

@Override
protected AsyncClientHttpRequestFactory createRequestFactory() {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    AsyncListenableTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    requestFactory.setTaskExecutor(taskExecutor);
    return requestFactory;
}
Also used : AsyncListenableTaskExecutor(org.springframework.core.task.AsyncListenableTaskExecutor) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor)

Aggregations

SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)5 URI (java.net.URI)2 Test (org.junit.Test)2 CamelThreadFactory (org.apache.camel.util.concurrent.CamelThreadFactory)1 Before (org.junit.Before)1 AsyncListenableTaskExecutor (org.springframework.core.task.AsyncListenableTaskExecutor)1 TaskExecutor (org.springframework.core.task.TaskExecutor)1 MockFilterChain (org.springframework.mock.web.MockFilterChain)1 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)1 WebSocketHttpHeaders (org.springframework.web.socket.WebSocketHttpHeaders)1 WebSocketSession (org.springframework.web.socket.WebSocketSession)1 TextWebSocketHandler (org.springframework.web.socket.handler.TextWebSocketHandler)1