Hey all
Need your guidance and suggestions to implement File Locking the right way.
I have a directory that may receive multiple data files. There would be multiple threads to read and process the files. Once a file is processed, it has to be archived and the original file needs to be deleted. Since there are multiple threads involved, I am exploring the File Locking mechanism in SI.
Please find below my current configuration:
The custom directory scanner is being injected with a locker and it takes care of locking the file.Code:<bean id="filter" class="org.springframework.integration.file.filters.RegexPatternFileListFilter"> <constructor-arg name="pattern" value="${fileName.regex}" /> </bean> <bean id="locker" class="org.springframework.integration.file.locking.NioFileLocker" /> <!-- scan to process files from recently created ones to the oldest --> <bean id="customDirectorySanner" class="com.spring.int.Sample.CustomDirectoryScanner"> <property name="sortOrder" value="Desc" /> <property name="locker" ref="locker" /> </bean> <!-- File Polling Components (first) --> <integration:service-activator input-channel="inputChannelOne" ref="customJobLauncher" method="processFile" /> <file:inbound-channel-adapter id="first" channel="inputChannelOne" directory="file:${dir.home.input}" filter="filter" scanner="customDirectorySanner"> <integration:poller id="pollerOne" fixed-delay="${polling.interval}" max-messages-per-poll="5"/> </file:inbound-channel-adapter> <!-- File Polling Components (second) --> <integration:service-activator input-channel="inputChannelSecond" ref="customJobLauncher" method="processFile" /> <file:inbound-channel-adapter id="first" channel="inputChannelSecond" directory="file:${dir.home.input}" filter="filter" scanner="customDirectorySanner"> <integration:poller id="pollerSecond" fixed-delay="${polling.interval}" max-messages-per-poll="5"/> </file:inbound-channel-adapter>
When and where shall I unlock it?
Do I need to pass the locker to the Service Activator and invoke unlock() on the file?
Appreciate your suggestions and recommendations.
Thanks.
Chandra


Reply With Quote
