Package name.pachler.nio.file

# Class WatchKey

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

Direct Known Subclasses:
  `PathWatchKey`

public abstract class WatchKey extends Object
A `WatchKey` represents a `Watchable`'s registration for events with a `WatchService`. It is created on registration and subsequently used to retreive `WatchEvent`s.
To stop receiving events from a `WatchService` (that is, undoing registration), use the `cancel()` method. Note that this will invalidate the `WatchKey`, which should then be discarded (as it cannot be reused).

See Also:
  - `WatchService.poll()`
  - `WatchService.take()`
  - `pollEvents()`

## Constructor Summary

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

## Method Summary

Modifier and Type
Method
Description
`abstract void`
`cancel()`
This cancels the registration with the WatchService that this WatchKey was registered with.
`abstract boolean`
`isValid()`
`abstract List<WatchEvent<?>>`
`pollEvents()`
Returns the events that have occurred for this WatchKey.
`abstract boolean`
`reset()`
Resets this `WatchKey` (marks it as non-signalled) so that it's corresponding `WatchService` can report it again via it's `WatchService.poll()` and `WatchService.take()` methods.

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

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

## Constructor Details

### WatchKey

protected WatchKey()

## Method Details

### cancel

public abstract void cancel()
This cancels the registration with the WatchService that this WatchKey was registered with. This means that no new events will be delivered to this key any more. Events that are pending can still be retreived with pollEvents(), and if the WatchKey is still marked as signalled a call to WatchService's poll() or take() functions will still return it.

### isValid

public abstract boolean isValid()

Returns:
  if this watch key is valid. A watch key is valid if
  - It has not been canceled
  - The WatchService is not yet closed

### pollEvents

public abstract List<WatchEvent<?>> pollEvents()
Returns the events that have occurred for this WatchKey. Just calling this method will not reset the signalled state of this key; you'll have to call #reset() to indicate to the WatchService that the the client is ready to receive more events and that the key can be re-queued. After the WatchService has determined that events have occurred for a registered Watchable represented by a given WatchKey, it will return that key when the client calls it's WatchService#take() or WatchService#poll() methods.

Returns:
  a list of events that have occurred since the last time that #pollEvents() was called.

### reset

public abstract boolean reset()
Resets this `WatchKey` (marks it as non-signalled) so that it's corresponding `WatchService` can report it again via it's `WatchService.poll()` and `WatchService.take()` methods.

Returns:
  `true` if the key could be reset, `false` otherwise (typically if the corresponding `WatchService` has been closed or if the the key was not signalled).