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;
}
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();
}
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);
}
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());
}
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;
}
Aggregations