Package name.pachler.nio.file

# Class WatchService

java.lang.Object
name.pachler.nio.file.WatchService

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

Direct Known Subclasses:
  `PathWatchService`

public abstract class WatchService extends Object implements Closeable
A service that provides monitoring for `Watchable`s, reporting changes on these objects (in the case of jpathwatch, these are `Path` instances). To utilise file monitoring, a program needs to acquire a watch service first, like this:
`WatchService ws = FileSystems.getDefault().newWatchService();`

A path needs to be constructed for the directory to be watched, by simply using the `Paths` class:
`// assuming we want to watch the '/tmp' directory on a Unix system. Path path = Paths.get("/tmp");`

We can now register the path with the watch service. In this case, we want to watch for files created under the /tmp directory, so we register using `Path.register(name.pachler.nio.file.WatchService, name.pachler.nio.file.WatchEvent.Kind<?>...)` with the `StandardWatchEventKind.ENTRY_CREATE` event kind and no modifiers, like this:
`WatchKey key = path.register(ws, ENTRY_CREATE);`

Note that we receive a `WatchKey` now, which represents the registration of our path with the watch service. The key is also used subsequently to retreive events. We'll now wait for an event to occur, like this:
`// this will block until an event has occurred, or the WatchService is closed. WatchKey k = ws.take();`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`WatchService()`

## Method Summary

Modifier and Type
Method
Description
`abstract void`
`close()`
`abstract WatchKey`
`poll()`
`abstract WatchKey`
`poll(long timeout, TimeUnit unit)`
`abstract WatchKey`
`take()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### WatchService

protected WatchService()

## Method Details

### close

public abstract void close() throws IOException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Throws:
  `IOException`

### poll

public abstract WatchKey poll() throws InterruptedException, ClosedWatchServiceException

Throws:
  `InterruptedException`
  `ClosedWatchServiceException`

### poll

public abstract WatchKey poll(long timeout, TimeUnit unit) throws InterruptedException, ClosedWatchServiceException

Throws:
  `InterruptedException`
  `ClosedWatchServiceException`

### take

public abstract WatchKey take() throws InterruptedException, ClosedWatchServiceException

Throws:
  `InterruptedException`
  `ClosedWatchServiceException`