Search in sources :

Example 1 with AggregatingMessageHandler

use of org.springframework.integration.aggregator.AggregatingMessageHandler in project spring-integration by spring-projects.

the class AggregatorFactoryBean method createHandler.

@Override
protected AggregatingMessageHandler createHandler() {
    MessageGroupProcessor outputProcessor;
    if (this.processorBean instanceof MessageGroupProcessor) {
        outputProcessor = (MessageGroupProcessor) this.processorBean;
    } else {
        if (!StringUtils.hasText(this.methodName)) {
            outputProcessor = new MethodInvokingMessageGroupProcessor(this.processorBean);
        } else {
            outputProcessor = new MethodInvokingMessageGroupProcessor(this.processorBean, this.methodName);
        }
    }
    AggregatingMessageHandler aggregator = new AggregatingMessageHandler(outputProcessor);
    if (this.expireGroupsUponCompletion != null) {
        aggregator.setExpireGroupsUponCompletion(this.expireGroupsUponCompletion);
    }
    if (this.sendTimeout != null) {
        aggregator.setSendTimeout(this.sendTimeout);
    }
    if (this.outputChannelName != null) {
        aggregator.setOutputChannelName(this.outputChannelName);
    }
    if (this.metrics != null) {
        aggregator.configureMetrics(this.metrics);
    }
    if (this.statsEnabled != null) {
        aggregator.setStatsEnabled(this.statsEnabled);
    }
    if (this.countsEnabled != null) {
        aggregator.setCountsEnabled(this.countsEnabled);
    }
    if (this.lockRegistry != null) {
        aggregator.setLockRegistry(this.lockRegistry);
    }
    if (this.messageStore != null) {
        aggregator.setMessageStore(this.messageStore);
    }
    if (this.correlationStrategy != null) {
        aggregator.setCorrelationStrategy(this.correlationStrategy);
    }
    if (this.releaseStrategy != null) {
        aggregator.setReleaseStrategy(this.releaseStrategy);
    }
    if (this.groupTimeoutExpression != null) {
        aggregator.setGroupTimeoutExpression(this.groupTimeoutExpression);
    }
    if (this.forceReleaseAdviceChain != null) {
        aggregator.setForceReleaseAdviceChain(this.forceReleaseAdviceChain);
    }
    if (this.taskScheduler != null) {
        aggregator.setTaskScheduler(this.taskScheduler);
    }
    if (this.discardChannel != null) {
        aggregator.setDiscardChannel(this.discardChannel);
    }
    if (this.discardChannelName != null) {
        aggregator.setDiscardChannelName(this.discardChannelName);
    }
    if (this.sendPartialResultOnExpiry != null) {
        aggregator.setSendPartialResultOnExpiry(this.sendPartialResultOnExpiry);
    }
    if (this.minimumTimeoutForEmptyGroups != null) {
        aggregator.setMinimumTimeoutForEmptyGroups(this.minimumTimeoutForEmptyGroups);
    }
    if (this.expireGroupsUponTimeout != null) {
        aggregator.setExpireGroupsUponTimeout(this.expireGroupsUponTimeout);
    }
    return aggregator;
}
Also used : AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) MethodInvokingMessageGroupProcessor(org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor) MessageGroupProcessor(org.springframework.integration.aggregator.MessageGroupProcessor) MethodInvokingMessageGroupProcessor(org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor)

Example 2 with AggregatingMessageHandler

use of org.springframework.integration.aggregator.AggregatingMessageHandler in project spring-integration by spring-projects.

the class ScatterGatherParserTests method testAuction.

@Test
public void testAuction() {
    MessageHandler scatterGather = this.beanFactory.getBean("scatterGather1.handler", MessageHandler.class);
    assertThat(scatterGather, instanceOf(ScatterGatherHandler.class));
    assertSame(this.beanFactory.getBean("scatterChannel"), TestUtils.getPropertyValue(scatterGather, "scatterChannel"));
    assertTrue(this.beanFactory.containsBean("scatterGather1.gatherer"));
    AggregatingMessageHandler gatherer = this.beanFactory.getBean("scatterGather1.gatherer", AggregatingMessageHandler.class);
    assertSame(gatherer, TestUtils.getPropertyValue(scatterGather, "gatherer"));
    Object reaper = this.beanFactory.getBean("reaper");
    assertSame(gatherer.getMessageStore(), TestUtils.getPropertyValue(reaper, "messageGroupStore"));
    assertTrue(TestUtils.getPropertyValue(scatterGather, "requiresReply", Boolean.class));
}
Also used : AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) MessageHandler(org.springframework.messaging.MessageHandler) ScatterGatherHandler(org.springframework.integration.scattergather.ScatterGatherHandler) Test(org.junit.Test)

Example 3 with AggregatingMessageHandler

use of org.springframework.integration.aggregator.AggregatingMessageHandler in project spring-integration by spring-projects.

the class AggregatorParserTests method testAggregationWithExpressionsAndPojoAggregator.

@Test
public void testAggregationWithExpressionsAndPojoAggregator() {
    EventDrivenConsumer aggregatorConsumer = (EventDrivenConsumer) context.getBean("aggregatorWithExpressionsAndPojoAggregator");
    AggregatingMessageHandler aggregatingMessageHandler = (AggregatingMessageHandler) TestUtils.getPropertyValue(aggregatorConsumer, "handler");
    MethodInvokingMessageGroupProcessor messageGroupProcessor = (MethodInvokingMessageGroupProcessor) TestUtils.getPropertyValue(aggregatingMessageHandler, "outputProcessor");
    Object messageGroupProcessorTargetObject = TestUtils.getPropertyValue(messageGroupProcessor, "processor.delegate.targetObject");
    assertSame(context.getBean("aggregatorBean"), messageGroupProcessorTargetObject);
    ReleaseStrategy releaseStrategy = (ReleaseStrategy) TestUtils.getPropertyValue(aggregatingMessageHandler, "releaseStrategy");
    CorrelationStrategy correlationStrategy = (CorrelationStrategy) TestUtils.getPropertyValue(aggregatingMessageHandler, "correlationStrategy");
    Long minimumTimeoutForEmptyGroups = TestUtils.getPropertyValue(aggregatingMessageHandler, "minimumTimeoutForEmptyGroups", Long.class);
    assertTrue(ExpressionEvaluatingReleaseStrategy.class.equals(releaseStrategy.getClass()));
    assertTrue(ExpressionEvaluatingCorrelationStrategy.class.equals(correlationStrategy.getClass()));
    assertEquals(60000L, minimumTimeoutForEmptyGroups.longValue());
}
Also used : AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MethodInvokingMessageGroupProcessor(org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor) CorrelationStrategy(org.springframework.integration.aggregator.CorrelationStrategy) ExpressionEvaluatingCorrelationStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategy) ExpressionEvaluatingReleaseStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingReleaseStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy) ReleaseStrategy(org.springframework.integration.aggregator.ReleaseStrategy) ExpressionEvaluatingReleaseStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingReleaseStrategy) ExpressionEvaluatingCorrelationStrategy(org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategy) Test(org.junit.Test)

Example 4 with AggregatingMessageHandler

use of org.springframework.integration.aggregator.AggregatingMessageHandler in project spring-integration by spring-projects.

the class PNamespaceTests method testPNamespaceChain.

@Test
public void testPNamespaceChain() {
    List<?> handlers = (List<?>) TestUtils.getPropertyValue(sampleChain, "handler.handlers");
    AggregatingMessageHandler handler = (AggregatingMessageHandler) handlers.get(0);
    SampleAggregator aggregator = (SampleAggregator) TestUtils.getPropertyValue(handler, "outputProcessor.processor.delegate.targetObject");
    assertEquals("Bill", aggregator.getName());
}
Also used : AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) List(java.util.List) Test(org.junit.Test)

Example 5 with AggregatingMessageHandler

use of org.springframework.integration.aggregator.AggregatingMessageHandler in project spring-integration by spring-projects.

the class AggregatorAnnotationPostProcessor method createHandler.

@Override
protected MessageHandler createHandler(Object bean, Method method, List<Annotation> annotations) {
    MethodInvokingMessageGroupProcessor processor = new MethodInvokingMessageGroupProcessor(bean, method);
    processor.setBeanFactory(this.beanFactory);
    MethodInvokingReleaseStrategy releaseStrategy = null;
    Method releaseStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, ReleaseStrategy.class);
    if (releaseStrategyMethod != null) {
        releaseStrategy = new MethodInvokingReleaseStrategy(bean, releaseStrategyMethod);
    }
    MethodInvokingCorrelationStrategy correlationStrategy = null;
    Method correlationStrategyMethod = MessagingAnnotationUtils.findAnnotatedMethod(bean, CorrelationStrategy.class);
    if (correlationStrategyMethod != null) {
        correlationStrategy = new MethodInvokingCorrelationStrategy(bean, correlationStrategyMethod);
    }
    AggregatingMessageHandler handler = new AggregatingMessageHandler(processor, new SimpleMessageStore(), correlationStrategy, releaseStrategy);
    String discardChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "discardChannel", String.class);
    if (StringUtils.hasText(discardChannelName)) {
        handler.setDiscardChannelName(discardChannelName);
    }
    String outputChannelName = MessagingAnnotationUtils.resolveAttribute(annotations, "outputChannel", String.class);
    if (StringUtils.hasText(outputChannelName)) {
        handler.setOutputChannelName(outputChannelName);
    }
    String sendPartialResultsOnExpiry = MessagingAnnotationUtils.resolveAttribute(annotations, "sendPartialResultsOnExpiry", String.class);
    if (sendPartialResultsOnExpiry != null) {
        handler.setSendPartialResultOnExpiry(Boolean.parseBoolean(this.beanFactory.resolveEmbeddedValue(sendPartialResultsOnExpiry)));
    }
    handler.setBeanFactory(this.beanFactory);
    return handler;
}
Also used : AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) SimpleMessageStore(org.springframework.integration.store.SimpleMessageStore) MethodInvokingMessageGroupProcessor(org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor) Method(java.lang.reflect.Method) MethodInvokingCorrelationStrategy(org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy) MethodInvokingReleaseStrategy(org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)

Aggregations

AggregatingMessageHandler (org.springframework.integration.aggregator.AggregatingMessageHandler)7 Test (org.junit.Test)3 MethodInvokingMessageGroupProcessor (org.springframework.integration.aggregator.MethodInvokingMessageGroupProcessor)3 ScatterGatherHandler (org.springframework.integration.scattergather.ScatterGatherHandler)3 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)2 Method (java.lang.reflect.Method)1 List (java.util.List)1 CorrelationStrategy (org.springframework.integration.aggregator.CorrelationStrategy)1 ExpressionEvaluatingCorrelationStrategy (org.springframework.integration.aggregator.ExpressionEvaluatingCorrelationStrategy)1 ExpressionEvaluatingReleaseStrategy (org.springframework.integration.aggregator.ExpressionEvaluatingReleaseStrategy)1 MessageGroupProcessor (org.springframework.integration.aggregator.MessageGroupProcessor)1 MethodInvokingCorrelationStrategy (org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy)1 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)1 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)1 RecipientListRouter (org.springframework.integration.router.RecipientListRouter)1 SimpleMessageStore (org.springframework.integration.store.SimpleMessageStore)1 MessageHandler (org.springframework.messaging.MessageHandler)1