Wednesday 8 May 2013

Controlling the order in which files get processed in a File/FTP Adapter

File/Ftp Adapter allows you to control the order in which files are processed.

 You may have a requirement to process the files in order of their modified times/ file sizes etc.
You can achieve this in a File/Ftp adapter with a "FileSorter" attribute . This attribute could be defined in the JCA file for your inbound File/Ftp Adapter service.
file_sorting.jpg

The File/Ftp Adapter ships with two predefined sorters that use the last modified times e.g.

file_sorting_timestamp.jpg
What If you would like to define the order yourself.
Well in this case, you will have to implement implement a Java Comparator and register that with the File Adapter as described below:
  1. Write a Java comparator. For example, the FileSizeSorter comparator below sorts the files in descending order of their sizes:

file_sorter_size.jpg
2.    In order to compile this class , add fileAdapter.jar in the classpath. Go to [ORACLE_SOA_HOME]/connectors and expand FileAdapter.rar
 e.g. jar xvf FileAdapter.rar in order to extract fileAdapter.jar.

You will need to fileAdapter.jar in your classath in order to compile the
FileSizeSorter.java 
class e.g. setenv CLASSPATH fileAdapter.jar
javac -d . FileSizeSorter.java
3.    After compilation, bundle the class in its own jar e.g.
 jar cvf fileadapter-sorter.jar file
4.  Bundle the fileadapter-sorter.jar in the FileAdapter.rar e.g.
 jar uvf FileAdapter.rar fileadapter-sorter.jar 
 This step is required since the fileadapter-sorter.jar becomes visible to the ClassLoader that loads FileAdapter.rar. Though, there are other ways e.g. copying the fileadapter-sorter.jar and fileAdapter.jar under [DOMAIN_HOME]/lib, but, the one above is the simplest and easiest.

Please note that in order to achieve this behavior, the following steps are mandatory:
1) Setting SingleThreadModel as "true" in the JCA file (see image at the top)
2)  If
The File/Ftp Adapter allows you to control the order in which files get processed. For example, you might want the files to be processed in order of their modified times/ file sizes etc.
Luckily, the File/Ftp adapter allows you to achieve this via a "FileSorter" attribute that you can define in the JCA file for your inbound File/Ftp Adapter service.
file_sorting.jpg

The File/Ftp Adapter ships with two predefined sorters that use the last modified times e.g.

file_sorting_timestamp.jpg
However, there are times when you would like to define the order yourself. In situations like this, you can implement a Java Comparator and register that with the File Adapter as described below:
  1. Write a comparator. For example, the FileSizeSorter comparator below sorts the files in descending order of their sizes:

file_sorter_size.jpg
2.    In order to compile this class though, you will need fileAdapter.jar in the classpath. Go to [FMW_HOME]/AS11gR1SOA/soa/connectors and expand FileAdapter.rar e.g. jar xvf FileAdapter.rar in order to extract fileAdapter.jar. You will need to fileAdapter.jar in your classath in order to compile the
FileSizeSorter.java 
class e.g. setenv CLASSPATH fileAdapter.jar
javac -d . FileSizeSorter.java
3.    After compilation, bundle the class in its own jar e.g.
 jar cvf fileadapter-sorter.jar file
4.  Bundle the fileadapter-sorter.jar in the FileAdapter.rar e.g.
 jar uvf FileAdapter.rar fileadapter-sorter.jar 
 This step is required since the fileadapter-sorter.jar becomes visible to the ClassLoader that loads FileAdapter.rar. Though, there are other ways e.g. copying the fileadapter-sorter.jar and fileAdapter.jar under [DOMAIN_HOME]/lib, but, the one above is the simplest and easiest.

Please note that in order to achieve this behavior, the following steps are mandatory:
1) Setting SingleThreadModel as "true" in the JCA file (see figure above)
2)  If you're using BPEL, make sure to model a synchronous process.

No comments:

Post a Comment