WatchService: passing parameter at registration

64 views Asked by At

I'm looking for a way to pass parameters when registering a Path to a WatchService. The goal is to get those parameters when processing events related to the Path.

WatchService watchService = FileSystems.getDefault().newWatchService();
....
path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE); //I would like to pass some parameters here...
....
key = watchService.take(); // ... so that I can get these parameters here from the WatchKey

Any idea if it is possible?

Thanks, Mickael

1

There are 1 answers

0
manash On BEST ANSWER

I just found that the WatchKey returned at registration is the same as the one returned by the take()/poll() method.

I managed to solve it by maintaining an external Map<WatchKey, ....>.