use of org.apache.zookeeper.proto.WatcherEvent in project zookeeper by apache.
the class NIOServerCnxn method process.
/*
* (non-Javadoc)
*
* @see org.apache.zookeeper.server.ServerCnxnIface#process(org.apache.zookeeper.proto.WatcherEvent)
*/
@Override
public void process(WatchedEvent event) {
ReplyHeader h = new ReplyHeader(ClientCnxn.NOTIFICATION_XID, -1L, 0);
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, "Deliver event " + event + " to 0x" + Long.toHexString(this.sessionId) + " through " + this);
}
// Convert WatchedEvent to a type that can be sent over the wire
WatcherEvent e = event.getWrapper();
// The last parameter OpCode here is used to select the response cache.
// Passing OpCode.error (with a value of -1) means we don't care, as we don't need
// response cache on delivering watcher events.
int responseSize = sendResponse(h, e, "notification", null, null, ZooDefs.OpCode.error);
ServerMetrics.getMetrics().WATCH_BYTES.add(responseSize);
}
use of org.apache.zookeeper.proto.WatcherEvent in project zookeeper by apache.
the class WatchedEventTest method testCreatingWatchedEventFromInvalidWrapper.
@Test
public void testCreatingWatchedEventFromInvalidWrapper() {
try {
WatcherEvent wep = new WatcherEvent(-2342, -252352, "foo");
new WatchedEvent(wep);
fail("Was able to create WatchedEvent from bad wrapper");
} catch (RuntimeException re) {
// we're good
}
}
use of org.apache.zookeeper.proto.WatcherEvent in project zookeeper by apache.
the class NettyServerCnxn method process.
@Override
public void process(WatchedEvent event) {
ReplyHeader h = new ReplyHeader(ClientCnxn.NOTIFICATION_XID, -1L, 0);
if (LOG.isTraceEnabled()) {
ZooTrace.logTraceMessage(LOG, ZooTrace.EVENT_DELIVERY_TRACE_MASK, "Deliver event " + event + " to 0x" + Long.toHexString(this.sessionId) + " through " + this);
}
// Convert WatchedEvent to a type that can be sent over the wire
WatcherEvent e = event.getWrapper();
try {
int responseSize = sendResponse(h, e, "notification");
ServerMetrics.getMetrics().WATCH_BYTES.add(responseSize);
} catch (IOException e1) {
LOG.debug("Problem sending to {}", getRemoteSocketAddress(), e1);
close();
}
}
use of org.apache.zookeeper.proto.WatcherEvent in project zookeeper by apache.
the class WatchedEventTest method testConvertingToEventWrapper.
@Test
public void testConvertingToEventWrapper() {
WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.Expired, "blah");
WatcherEvent wew = we.getWrapper();
assertEquals(EventType.NodeCreated.getIntValue(), wew.getType());
assertEquals(KeeperState.Expired.getIntValue(), wew.getState());
assertEquals("blah", wew.getPath());
}
use of org.apache.zookeeper.proto.WatcherEvent in project zookeeper by apache.
the class WatchedEventTest method testCreatingWatchedEventFromWrapper.
@Test
public void testCreatingWatchedEventFromWrapper() {
// Make sure we can handle any type of correct wrapper
EnumSet<EventType> allTypes = EnumSet.allOf(EventType.class);
EnumSet<KeeperState> allStates = EnumSet.allOf(KeeperState.class);
WatchedEvent we;
WatcherEvent wep;
for (EventType et : allTypes) {
for (KeeperState ks : allStates) {
wep = new WatcherEvent(et.getIntValue(), ks.getIntValue(), "blah");
we = new WatchedEvent(wep);
assertEquals(et, we.getType());
assertEquals(ks, we.getState());
assertEquals("blah", we.getPath());
}
}
}
Aggregations