<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/task https://www.springframework.org/schema/task/spring-task.xsd
		http://www.springframework.org/schema/integration https://www.springframework.org/schema/integration/spring-integration.xsd">

	<channel id="input">
		<queue capacity="5" />
	</channel>

	<beans:bean id="headersFunction"
				class="org.springframework.integration.aggregator.integration.AggregatorIntegrationTests"
				factory-method="firstMessageHeaders"/>

	<aggregator ref="summer" method="sum" input-channel="input" output-channel="output" expression=""
				headers-function="headersFunction">
		<poller task-executor="executor" max-messages-per-poll="5" fixed-delay="20" />
	</aggregator>

	<task:executor id="executor" pool-size="5"/>

	<channel id="output">
		<queue capacity="5" />
	</channel>

	<channel id="discard">
		<queue capacity="5" />
	</channel>

	<beans:bean id="summer"
		class="org.springframework.integration.aggregator.integration.AggregatorIntegrationTests$SummingAggregator" />

	<aggregator id="expiringAggregator" input-channel="expiringAggregatorInput" output-channel="output"
				expire-groups-upon-completion="true" discard-channel="discard"/>

	<aggregator id="nonExpiringAggregator" input-channel="nonExpiringAggregatorInput" output-channel="output"
				expire-groups-upon-completion="false" discard-channel="discard"/>

	<aggregator id="gta"
				input-channel="groupTimeoutAggregatorInput" output-channel="output" discard-channel="discard"
				send-partial-result-on-expiry="true"
				send-timeout="100"
				group-timeout="100"/>

	<aggregator input-channel="groupTimeoutExpressionAggregatorInput" output-channel="output" discard-channel="discard"
				send-partial-result-on-expiry="true"
				group-timeout-expression="size() ge 2 ? new java.util.Date(timestamp + 500) : null"
			    release-strategy-expression="messages[0].headers.sequenceNumber == messages[0].headers.sequenceSize"/>

	<aggregator input-channel="zeroGroupTimeoutExpressionAggregatorInput" output-channel="output" discard-channel="discard"
				send-partial-result-on-expiry="true"
				send-timeout="10"
				group-timeout-expression="@bool.getAndSet(true) ? 0 : 10"
			    release-strategy-expression="messages[0].headers.sequenceNumber == messages[0].headers.sequenceSize"/>

	<beans:bean id="bool" class="java.util.concurrent.atomic.AtomicBoolean" />

	<bridge input-channel="errorChannel" output-channel="errors" />

	<channel id="errors">
		<queue />
	</channel>

</beans:beans>
