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

	<si:channel id="testChannel"/>

	<file:outbound-channel-adapter id="simpleAdapter"
								   channel="testChannel"
								   directory="${java.io.tmpdir}"
								   temporary-file-suffix=".foo"
								   chmod="777"
								   preserve-timestamp="true"
								   filename-generator-expression="'foo.txt'"/>

	<file:outbound-channel-adapter id="adapterWithCustomNameGenerator"
								   channel="testChannel"
								   flush-when-idle="false"
								   filename-generator="customFileNameGenerator"
								   directory="${java.io.tmpdir}"/>

	<file:outbound-channel-adapter id="adapterWithDirectoryExpression"
								   channel="testChannel"
								   directory-expression="'foo/bar'"/>

	<file:outbound-channel-adapter id="adapterWithAppendNewLine"
								   channel="testChannel"
								   append-new-line="true"
								   directory="${java.io.tmpdir}"/>

	<file:outbound-channel-adapter id="adapterWithDeleteFlag"
								   channel="testChannel"
								   delete-source-files="true"
								   directory="${java.io.tmpdir}"/>

	<file:outbound-channel-adapter id="adapterWithCharset"
								   channel="testChannel"
								   charset="UTF-8"
								   directory="${java.io.tmpdir}"/>

	<file:outbound-channel-adapter id="adapterWithOrder"
								   channel="testChannel"
								   order="555"
								   auto-startup="false"
								   directory="${java.io.tmpdir}"/>

	<file:outbound-channel-adapter id="adapterWithFlushing"
								   channel="testChannel"
								   order="555"
								   mode="APPEND_NO_FLUSH"
								   flush-interval="12345"
								   flush-predicate="predicate"
								   buffer-size="4096"
								   auto-startup="false"
								   directory="${java.io.tmpdir}"/>

	<bean id="predicate" class="org.mockito.Mockito" factory-method="mock">
		<constructor-arg
				value="org.springframework.integration.file.FileWritingMessageHandler.MessageFlushPredicate"
				type="java.lang.Class"/>
	</bean>

	<file:outbound-channel-adapter id="usageChannel"
								   filename-generator-expression="@fooString"
								   mode="APPEND"
								   directory-expression="@barString">
		<file:request-handler-advice-chain>
			<bean class="org.springframework.integration.file.config.FileOutboundChannelAdapterParserTests$FooAdvice"/>
		</file:request-handler-advice-chain>
	</file:outbound-channel-adapter>

	<file:outbound-channel-adapter id="adapterUsageWithAppendAndAppendNewLineTrue"
								   filename-generator-expression="@fooString"
								   mode="APPEND"
								   append-new-line="true"
								   directory-expression="@barString">
	</file:outbound-channel-adapter>

	<file:outbound-channel-adapter id="adapterUsageWithAppendAndAppendNewLineFalse"
								   filename-generator-expression="@fooString"
								   mode="APPEND"
								   append-new-line="false"
								   directory-expression="@barString">
	</file:outbound-channel-adapter>

	<bean id="fooString" class="java.lang.String">
		<constructor-arg value="fileToAppend.txt"/>
	</bean>

	<bean id="barString" class="java.lang.String">
		<constructor-arg value="test"/>
	</bean>

	<file:outbound-channel-adapter id="usageChannelWithFailMode"
								   filename-generator-expression="'fileToFail.txt'"
								   mode="FAIL"
								   directory="test"/>

	<file:outbound-channel-adapter id="usageChannelWithIgnoreMode"
								   filename-generator-expression="'fileToIgnore.txt'"
								   mode="IGNORE"
								   directory="test"/>

	<si:channel id="usageChannelConcurrent">
		<si:dispatcher task-executor="executor"/>
	</si:channel>


	<file:outbound-channel-adapter channel="usageChannelConcurrent"
								   filename-generator-expression="'fileToAppendConcurrent.txt'"
								   mode="APPEND"
								   directory="test">
		<file:request-handler-advice-chain>
			<bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
				<property name="onSuccessExpressionString" value="@fileWriteLatch.countDown()"/>
			</bean>
		</file:request-handler-advice-chain>
	</file:outbound-channel-adapter>

	<bean id="customFileNameGenerator" class="org.springframework.integration.file.config.CustomFileNameGenerator"/>

	<bean id="fileWriteLatch" class="java.util.concurrent.CountDownLatch">
		<constructor-arg value="2"/>
	</bean>

	<context:property-placeholder/>

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

</beans>
