# Class WatchManager

java.lang.Object
org.apache.zookeeper.server.watch.WatchManager

All Implemented Interfaces:
  `IWatchManager`

public class WatchManager extends Object implements IWatchManager
This class manages watches. It allows watches to be associated with a string and removes watchers and their watches in addition to managing triggers.

## Constructor Summary

Constructors
Constructor
Description
`WatchManager()`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`addWatch(String path, Watcher watcher)`
Add watch to specific path.
`boolean`
`addWatch(String path, Watcher watcher, WatcherMode watcherMode)`
Add watch to specific path.
`boolean`
`containsWatcher(String path, Watcher watcher)`
Checks the specified watcher exists for the given path.
`boolean`
`containsWatcher(String path, Watcher watcher, WatcherMode watcherMode)`
Checks the specified watcher exists for the given path and mode.
`void`
`dumpWatches(PrintWriter pwriter, boolean byPath)`
String representation of watches.
`WatchesReport`
`getWatches()`
Returns a watch report.
`WatchesPathReport`
`getWatchesByPath()`
Returns a watch report by path.
`WatchesSummary`
`getWatchesSummary()`
Returns a watch summary.
`boolean`
`removeWatcher(String path, Watcher watcher)`
Removes the specified watcher for the given path.
`boolean`
`removeWatcher(String path, Watcher watcher, WatcherMode watcherMode)`
Removes the specified watcher for the given path and mode.
`void`
`removeWatcher(Watcher watcher)`
The entry to remove the watcher when the cnxn is closed.
`void`
`shutdown()`
Clean up the watch manager.
`int`
`size()`
Get the size of watchers.
`String`
`toString()`
`WatcherOrBitSet`
`triggerWatch(String path, Watcher.Event.EventType type, long zxid, List<ACL> acl)`
Distribute the watch event for the given path.
`WatcherOrBitSet`
`triggerWatch(String path, Watcher.Event.EventType type, long zxid, List<ACL> acl, WatcherOrBitSet supress)`
Distribute the watch event for the given path, but ignore those suppressed ones.

### Methods inherited from class Object

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

## Constructor Details

### WatchManager

public WatchManager()

## Method Details

### size

public int size()
Description copied from interface: `IWatchManager`
Get the size of watchers.

Specified by:
  `size` in interface `IWatchManager`
Returns:
  the watchers number managed in this class.

### addWatch

public boolean addWatch(String path, Watcher watcher)
Description copied from interface: `IWatchManager`
Add watch to specific path.

Specified by:
  `addWatch` in interface `IWatchManager`
Parameters:
  `path` - znode path
  `watcher` - watcher object reference
Returns:
  true if the watcher added is not already present

### addWatch

public boolean addWatch(String path, Watcher watcher, WatcherMode watcherMode)
Description copied from interface: `IWatchManager`
Add watch to specific path.

Specified by:
  `addWatch` in interface `IWatchManager`
Parameters:
  `path` - znode path
  `watcher` - watcher object reference
  `watcherMode` - the watcher mode to use
Returns:
  true if the watcher added is not already present

### removeWatcher

public void removeWatcher(Watcher watcher)
Description copied from interface: `IWatchManager`
The entry to remove the watcher when the cnxn is closed.

Specified by:
  `removeWatcher` in interface `IWatchManager`
Parameters:
  `watcher` - watcher object reference

### triggerWatch

public WatcherOrBitSet triggerWatch(String path, Watcher.Event.EventType type, long zxid, List<ACL> acl)
Description copied from interface: `IWatchManager`
Distribute the watch event for the given path.

Specified by:
  `triggerWatch` in interface `IWatchManager`
Parameters:
  `path` - znode path
  `type` - the watch event type
  `zxid` - the zxid for the corresponding change that triggered this event
  `acl` - ACL of the znode in path
Returns:
  the watchers have been notified

### triggerWatch

public WatcherOrBitSet triggerWatch(String path, Watcher.Event.EventType type, long zxid, List<ACL> acl, WatcherOrBitSet supress)
Description copied from interface: `IWatchManager`
Distribute the watch event for the given path, but ignore those suppressed ones.

Specified by:
  `triggerWatch` in interface `IWatchManager`
Parameters:
  `path` - znode path
  `type` - the watch event type
  `zxid` - the zxid for the corresponding change that triggered this event
  `supress` - the suppressed watcher set
Returns:
  the watchers have been notified

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### dumpWatches

public void dumpWatches(PrintWriter pwriter, boolean byPath)
Description copied from interface: `IWatchManager`
String representation of watches. Warning, may be large!

Specified by:
  `dumpWatches` in interface `IWatchManager`
Parameters:
  `pwriter` - the writer to dump the watches
  `byPath` - iff true output watches by paths, otw output watches by connection

### containsWatcher

public boolean containsWatcher(String path, Watcher watcher)
Description copied from interface: `IWatchManager`
Checks the specified watcher exists for the given path.

Specified by:
  `containsWatcher` in interface `IWatchManager`
Parameters:
  `path` - znode path
  `watcher` - watcher object reference
Returns:
  true if the watcher exists, false otherwise

### containsWatcher

public boolean containsWatcher(String path, Watcher watcher, WatcherMode watcherMode)
Description copied from interface: `IWatchManager`
Checks the specified watcher exists for the given path and mode.

Specified by:
  `containsWatcher` in interface `IWatchManager`
Parameters:
  `path` - znode path
  `watcher` - watcher object reference
  `watcherMode` - watcher mode, null for any mode
Returns:
  true if the watcher exists, false otherwise

### removeWatcher

public boolean removeWatcher(String path, Watcher watcher, WatcherMode watcherMode)
Description copied from interface: `IWatchManager`
Removes the specified watcher for the given path and mode.

Specified by:
  `removeWatcher` in interface `IWatchManager`
Parameters:
  `path` - znode path
  `watcher` - watcher object reference
  `watcherMode` - watcher mode, null to remove all modes
Returns:
  true if the watcher successfully removed, false otherwise

### removeWatcher

public boolean removeWatcher(String path, Watcher watcher)
Description copied from interface: `IWatchManager`
Removes the specified watcher for the given path.

Specified by:
  `removeWatcher` in interface `IWatchManager`
Parameters:
  `path` - znode path
  `watcher` - watcher object reference
Returns:
  true if the watcher successfully removed, false otherwise

### getWatches

public WatchesReport getWatches()
Description copied from interface: `IWatchManager`
Returns a watch report.

Specified by:
  `getWatches` in interface `IWatchManager`
Returns:
  watch report
See Also:
  - `WatchesReport`

### getWatchesByPath

public WatchesPathReport getWatchesByPath()
Description copied from interface: `IWatchManager`
Returns a watch report by path.

Specified by:
  `getWatchesByPath` in interface `IWatchManager`
Returns:
  watch report
See Also:
  - `WatchesPathReport`

### getWatchesSummary

public WatchesSummary getWatchesSummary()
Description copied from interface: `IWatchManager`
Returns a watch summary.

Specified by:
  `getWatchesSummary` in interface `IWatchManager`
Returns:
  watch summary
See Also:
  - `WatchesSummary`

### shutdown

public void shutdown()
Description copied from interface: `IWatchManager`
Clean up the watch manager.

Specified by:
  `shutdown` in interface `IWatchManager`