public class EventingWatchService extends Object implements PathWatchService
WatchService interface to a PathWatchService.
Since the idea of a WatchService for a FileSystem is that it
maps onto the native event notification facility where available, this class
is considered to be an "eventing" implementation of the
PathWatchService interface.
Example:
FileSystem fs = FileSystems.getDefault();
PathWatchService s = new EventingWatchService(fs.newWatchService());
s.register(fs.getPath("/home/luke"),
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
s.start();
for (;;) {
WatchKey k = s.take();
...
}
| Constructor and Description |
|---|
EventingWatchService(WatchService service)
Constructs an instance on the specified watch service.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
WatchKey |
poll() |
WatchKey |
poll(long timeout,
TimeUnit unit) |
WatchKey |
register(Path dir,
WatchEvent.Kind<?>... kinds)
Registers the specified directory, using the specified
WatchEvent
kinds and no WatchEvent modifiers, with this watch service. |
WatchKey |
register(Path dir,
WatchEvent.Kind<?>[] kinds,
WatchEvent.Modifier... modifiers)
Registers the specified directory, using the specified
WatchEvent
kinds and modifiers, with this watch service. |
void |
start()
Starts this service.
|
WatchKey |
take() |
public EventingWatchService(WatchService service)
service - the watch service to be adaptedpublic void start()
PathWatchServicestart in interface PathWatchServicepublic WatchKey register(Path dir, WatchEvent.Kind<?>... kinds) throws IOException
PathWatchServiceWatchEvent
kinds and no WatchEvent modifiers, with this watch service.
This method is intended to be similar in behavior to
Path.register(WatchService, WatchEvent.Kind[]).
register in interface PathWatchServicedir - directory to watch; must not be a symbolic linkkinds - events to register forClosedWatchServiceException - if this watch service is closedNotDirectoryException - if dir is not a directoryIOException - if an I/O error occurspublic WatchKey register(Path dir, WatchEvent.Kind<?>[] kinds, WatchEvent.Modifier... modifiers) throws IOException
PathWatchServiceWatchEvent
kinds and modifiers, with this watch service.
This method is intended to be similar in behavior to
Path.register(WatchService, WatchEvent.Kind[], WatchEvent.Modifier[])
.
register in interface PathWatchServicedir - directory to watch; must not be a symbolic linkkinds - events to register formodifiers - modifiers modifying how dir is registeredClosedWatchServiceException - if this watch service is closedNotDirectoryException - if dir is not a directoryIOException - if an I/O error occurspublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface WatchServiceIOExceptionpublic WatchKey poll()
poll in interface WatchServiceClosedWatchServiceExceptionpublic WatchKey poll(long timeout, TimeUnit unit) throws InterruptedException
poll in interface WatchServiceClosedWatchServiceExceptionInterruptedExceptionpublic WatchKey take() throws InterruptedException
take in interface WatchServiceClosedWatchServiceExceptionInterruptedException