INT-1477 restructuring samples repo to have basic, intermediate, advancedand applications directories
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.integration.samples.fileprocessing;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* @author ozhurakousky
|
||||
*
|
||||
*/
|
||||
public class FileProcessor {
|
||||
private Random random = new Random();
|
||||
private Logger logger = Logger.getLogger(FileProcessor.class);
|
||||
|
||||
public File process(File file) throws Exception{
|
||||
Thread.sleep(random.nextInt(10)*500);
|
||||
logger.info("Processing File: " + file);
|
||||
return file;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-file="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:task="http://www.springframework.org/schema/task">
|
||||
|
||||
|
||||
<int-file:inbound-channel-adapter id="filesInChannel"
|
||||
directory="file:input">
|
||||
<int:poller id="poller" fixed-rate="10" task-executor="executor"/>
|
||||
</int-file:inbound-channel-adapter>
|
||||
|
||||
<int:service-activator input-channel="filesInChannel" output-channel="filesOutChannel">
|
||||
<bean class="org.springframework.integration.samples.fileprocessing.FileProcessor"/>
|
||||
</int:service-activator>
|
||||
|
||||
<int:channel id="filesOutChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<task:executor id="executor" pool-size="10"/>
|
||||
</beans>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.0.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-file="http://www.springframework.org/schema/integration/file"
|
||||
xmlns:task="http://www.springframework.org/schema/task">
|
||||
|
||||
|
||||
<int-file:inbound-channel-adapter id="filesInChannel"
|
||||
directory="file:input">
|
||||
<int:poller id="poller" fixed-rate="10"/>
|
||||
</int-file:inbound-channel-adapter>
|
||||
|
||||
<int:service-activator input-channel="filesInChannel" output-channel="filesOutChannel">
|
||||
<bean class="org.springframework.integration.samples.fileprocessing.FileProcessor"/>
|
||||
</int:service-activator>
|
||||
|
||||
<int:channel id="filesOutChannel">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.springframework.integration.samples.fileprocessing;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class FileProcessingTest {
|
||||
private int fileCount = 5;
|
||||
private Logger logger = Logger.getLogger(FileProcessingTest.class);
|
||||
|
||||
@Before
|
||||
public void createDirectory(){
|
||||
File directory = new File("input");
|
||||
if (directory.exists()){
|
||||
directory.delete();
|
||||
}
|
||||
directory.mkdir();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequentialFileProcessing() throws Exception {
|
||||
logger.info("\n\n#### Starting Sequential processing test ####");
|
||||
logger.info("Populating directory with files");
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
File file = new File("input/file_" + i + ".txt");
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(file));
|
||||
out.write("hello " + i);
|
||||
out.close();
|
||||
}
|
||||
logger.info("Populated directory with files");
|
||||
Thread.sleep(2000);
|
||||
logger.info("Starting Spring Integration Sequential File processing");
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("META-INF/spring/integration/sequentialFileProcessing-config.xml");
|
||||
PollableChannel filesOutChannel = ac.getBean("filesOutChannel", PollableChannel.class);
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
logger.info("Finished processing " + filesOutChannel.receive(10000).getPayload());
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testConcurrentFileProcessing() throws Exception {
|
||||
logger.info("\n\n#### Starting Concurrent processing test #### ");
|
||||
logger.info("Populating directory with files");
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
File file = new File("input/file_" + i + ".txt");
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(file));
|
||||
out.write("hello " + i);
|
||||
out.close();
|
||||
}
|
||||
logger.info("Populated directory with files");
|
||||
Thread.sleep(2000);
|
||||
logger.info("Starting Spring Integration Sequential File processing");
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/concurrentFileProcessing-config.xml");
|
||||
PollableChannel filesOutChannel = ac.getBean("filesOutChannel", PollableChannel.class);
|
||||
for (int i = 0; i < fileCount; i++) {
|
||||
logger.info("Finished processing " + filesOutChannel.receive(10000).getPayload());
|
||||
}
|
||||
}
|
||||
}
|
||||
32
intermediate/file-processing/src/test/resources/log4j.xml
Normal file
32
intermediate/file-processing/src/test/resources/log4j.xml
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
|
||||
|
||||
<!-- Appenders -->
|
||||
<appender name="console" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-5p: %c - %m%n" />
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<!-- Loggers -->
|
||||
<logger name="org.springframework">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration.samples.fileprocessing">
|
||||
<level value="debug" />
|
||||
</logger>
|
||||
|
||||
<logger name="org.springframework.integration.file">
|
||||
<level value="warn" />
|
||||
</logger>
|
||||
|
||||
<!-- Root Logger -->
|
||||
<root>
|
||||
<priority value="warn" />
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
||||
Reference in New Issue
Block a user