Basically, I am using the new Java 7 WatchService to monitor the directory.
I have a chain of handlers that listen for every I / O event thrown by a directory.
The problem is that some of the handlers must somehow change the cause of these IO events (== files). For example, if someone puts a file in a controlled folder, one of the handlers can change its extension, add something to it a file name or something else.
These actions, of course, trigger new I / O events, and the above handlers receive them. Then they make their changes again. This obviously leads to an endless loop ...
Does Java offer any way to handle this situation? If not, how would you handle this?
Basically, I would like to start event handlers only when the event was not triggered by the action of these handlers.
UPDATE: As for the solution, I would rather make a change only in the main code of the event router than worry about it in every handler that I write ("the handler makes changes only if didn" do it earlier ").
source share