Example usage for org.springframework.integration.channel ExecutorChannel ExecutorChannel

List of usage examples for org.springframework.integration.channel ExecutorChannel ExecutorChannel

Introduction

In this page you can find the example usage for org.springframework.integration.channel ExecutorChannel ExecutorChannel.

Prototype

public ExecutorChannel(Executor executor) 

Source Link

Document

Create an ExecutorChannel that delegates to the provided Executor when dispatching Messages.

Usage

From source file:ru.jts_dev.gameserver.config.GameIntegrationConfig.java

@Bean
public MessageChannel incomingPacketExecutorChannel() {
    // TODO: 07.12.15 investigate, may be should replace with spring TaskExecutor
    return new ExecutorChannel(Executors.newCachedThreadPool());
}

From source file:nl.rav.comparision.integration.unitofwork.java.UnitOfWorkSpringTest.java

private void createRouteBuilder() {
    handler = new AbstractReplyProducingMessageHandler() {
        @Override//from  ww w.  jav a 2 s  .com
        protected Object handleRequestMessage(Message<?> requestMessage) {
            return "baz";
        }
    };
    AbstractReplyProducingMessageHandler handler2 = new AbstractReplyProducingMessageHandler() {
        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            if (doFail.get()) {
                throw new RuntimeException("qux");
            }
            return requestMessage.getPayload();
        }
    };

    SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    taskExecutor.setThreadNamePrefix("test-");
    ExecutorChannel intermediate = new ExecutorChannel(taskExecutor);
    handler.setOutputChannel(intermediate);
    intermediate.subscribe(handler2);

    replies = new QueueChannel();
    handler2.setOutputChannel(replies);

    successChannel = new QueueChannel();
    failureChannel = new QueueChannel();
    ExpressionEvaluatingRequestHandlerAdvice advice = new ExpressionEvaluatingRequestHandlerAdvice();
    advice.setBeanFactory(mock(BeanFactory.class));
    advice.setSuccessChannel(successChannel);
    advice.setFailureChannel(failureChannel);
    advice.setOnSuccessExpression("'foo'");
    advice.setOnFailureExpression("'bar:' + #exception.message");

    List<Advice> adviceChain = new ArrayList<Advice>();
    adviceChain.add(advice);
    handler.setAdviceChain(adviceChain);
    handler.afterPropertiesSet();
    handler2.setAdviceChain(adviceChain);
    handler2.afterPropertiesSet();
}

From source file:ru.jts_dev.authserver.config.AuthIntegrationConfig.java

@Bean
public MessageChannel incomingPacketExecutorChannel() {
    // TODO: 07.12.15 investigate, may be should replaced with spring TaskExecutor
    return new ExecutorChannel(Executors.newCachedThreadPool());
}

From source file:org.springframework.integration.channel.P2pChannelTests.java

@Test
public void testExecutorChannelLoggingWithMoreThenOneSubscriber() {
    final ExecutorChannel channel = new ExecutorChannel(mock(Executor.class));
    channel.setBeanName("executorChannel");

    final Log logger = mock(Log.class);
    when(logger.isInfoEnabled()).thenReturn(true);
    ReflectionUtils.doWithFields(AbstractMessageChannel.class, new FieldCallback() {

        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
            if ("logger".equals(field.getName())) {
                field.setAccessible(true);
                field.set(channel, logger);
            }/*  w w  w  .j  a v  a 2 s  .  c  o  m*/
        }
    });
    channel.subscribe(mock(MessageHandler.class));
    channel.subscribe(mock(MessageHandler.class));
    verify(logger, times(2)).info(Mockito.anyString());
}