On 2011-10-10 8:20 AM, szaruba wrote: > Hi everybody, > > In our project we have to grab lots of files out of a directory and copy > them into another directory. > The time, when we start the file consumption is fixed and given, we just > have to grab all files from > the directory.(What I have to say is, that we don't know how much files we > have to grab, or how they are named) > If this happened, we want to make the route sleeping until the next > "grabbing" time. At the end of the > route (when all Files are transfered), we are calling a java bean for > creating a protocol. > > We have already solved the timer based task(our route is starting at a fixed > time, using quartz) and now > there is the problem: The route isn't able to sleep, because the file > consumer is polling based and always > polling on the directory. > > What we need: In best case, we want to use a file consumer, which is able to > start grabbing files from a directory > (consuming all files) and able to stop, when all files are consumed. (so a > non polling based file endpoint)
I had to do something similar to this using a JMS component (where it's impossible to tell how many items are left). Here's the strategies I'm aware of: * Find out how many files you need to handle when the route starts. o This only works if you have non-Camel access to the file system. o Add a processor to the beginning of the route which finds out how many files you need to handle. Decrement that number every time you transfer one. Stop the route when that number hits zero. o This strategy will break if new files are added while the route is running. * Use some sort of "sentinel" value. o Add a file that sorts last, so when you get that file, you know you handled everything. o I'm not sure if this will work with files but it's something to consider. * Use the time. o When the route starts, save the current time. o If you see a file with a timestamp newer than the saved time, the file is new and you can stop. o Need to find a way to sort by timestamp. o Breaks if the file timestamps aren't set (for example, just moving a file may not change the timestamp). * Don't use Camel. o It may make more sense in your case to just handle the files directly (without Camel)