Search in sources :

Example 1 with WatcherEvent

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);
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) WatcherEvent(org.apache.zookeeper.proto.WatcherEvent)

Example 2 with WatcherEvent

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
    }
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) WatcherEvent(org.apache.zookeeper.proto.WatcherEvent) Test(org.junit.jupiter.api.Test)

Example 3 with WatcherEvent

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();
    }
}
Also used : ReplyHeader(org.apache.zookeeper.proto.ReplyHeader) IOException(java.io.IOException) WatcherEvent(org.apache.zookeeper.proto.WatcherEvent)

Example 4 with WatcherEvent

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());
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) WatcherEvent(org.apache.zookeeper.proto.WatcherEvent) Test(org.junit.jupiter.api.Test)

Example 5 with WatcherEvent

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());
        }
    }
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) EventType(org.apache.zookeeper.Watcher.Event.EventType) KeeperState(org.apache.zookeeper.Watcher.Event.KeeperState) WatcherEvent(org.apache.zookeeper.proto.WatcherEvent) Test(org.junit.jupiter.api.Test)

Aggregations

WatcherEvent (org.apache.zookeeper.proto.WatcherEvent)5 WatchedEvent (org.apache.zookeeper.WatchedEvent)3 Test (org.junit.jupiter.api.Test)3 ReplyHeader (org.apache.zookeeper.proto.ReplyHeader)2 IOException (java.io.IOException)1 EventType (org.apache.zookeeper.Watcher.Event.EventType)1 KeeperState (org.apache.zookeeper.Watcher.Event.KeeperState)1