# Class WatchedEvent

java.lang.Object
org.apache.zookeeper.WatchedEvent

@Public public class WatchedEvent extends Object
A WatchedEvent represents a change on the ZooKeeper that a Watcher is able to respond to. The WatchedEvent includes exactly what happened, the current state of the ZooKeeper, and the path of the znode that was involved in the event.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final long`
`NO_ZXID`

## Constructor Summary

Constructors
Constructor
Description
`WatchedEvent(WatcherEvent eventMessage, long zxid)`
Convert a WatcherEvent sent over the wire into a full-fledged WatchedEvent
`WatchedEvent(Watcher.Event.EventType eventType, Watcher.Event.KeeperState keeperState, String path)`
Create a WatchedEvent with specified type, state and path
`WatchedEvent(Watcher.Event.EventType eventType, Watcher.Event.KeeperState keeperState, String path, long zxid)`
Create a WatchedEvent with specified type, state, path and zxid

## Method Summary

Modifier and Type
Method
Description
`String`
`getPath()`
`Watcher.Event.KeeperState`
`getState()`
`Watcher.Event.EventType`
`getType()`
`WatcherEvent`
`getWrapper()`
Convert WatchedEvent to type that can be sent over network
`long`
`getZxid()`
Returns the zxid of the transaction that triggered this watch if it is of one of the following types: `Watcher.Event.EventType.NodeCreated` `Watcher.Event.EventType.NodeDeleted` `Watcher.Event.EventType.NodeDataChanged` `Watcher.Event.EventType.NodeChildrenChanged` Otherwise, returns -1L.
`String`
`toString()`

### Methods inherited from class Object

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

## Field Details

### NO_ZXID

public static final long NO_ZXID

See Also:
  - Constant Field Values

## Constructor Details

### WatchedEvent

public WatchedEvent(Watcher.Event.EventType eventType, Watcher.Event.KeeperState keeperState, String path, long zxid)
Create a WatchedEvent with specified type, state, path and zxid

### WatchedEvent

public WatchedEvent(Watcher.Event.EventType eventType, Watcher.Event.KeeperState keeperState, String path)
Create a WatchedEvent with specified type, state and path

### WatchedEvent

public WatchedEvent(WatcherEvent eventMessage, long zxid)
Convert a WatcherEvent sent over the wire into a full-fledged WatchedEvent

## Method Details

### getState

public Watcher.Event.KeeperState getState()

### getType

public Watcher.Event.EventType getType()

### getPath

public String getPath()

### getZxid

public long getZxid()
Returns the zxid of the transaction that triggered this watch if it is of one of the following types:

- `Watcher.Event.EventType.NodeCreated`
- `Watcher.Event.EventType.NodeDeleted`
- `Watcher.Event.EventType.NodeDataChanged`
- `Watcher.Event.EventType.NodeChildrenChanged`

Otherwise, returns -1L. Note that -1L is also returned by old servers that do not support this feature.

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### getWrapper

public WatcherEvent getWrapper()
Convert WatchedEvent to type that can be sent over network