private void cleanAndNotifyState() { cleanup(); if (state.isAlive()) { eventThread.queueEvent(new WatchedEvent(Event.EventType.None, Event.KeeperState.Disconnected, null)); } clientCnxnSocket.updateNow(); clientCnxnSocket.updateLastSendAndHeard(); }
void queueEvent(String clientPath, int err, Set<Watcher> materializedWatchers, EventType eventType) { KeeperState sessionState = KeeperState.SyncConnected; if (KeeperException.Code.SESSIONEXPIRED.intValue() == err || KeeperException.Code.CONNECTIONLOSS.intValue() == err) { sessionState = Event.KeeperState.Disconnected; } WatchedEvent event = new WatchedEvent(eventType, sessionState, clientPath); eventThread.queueEvent(event, materializedWatchers); }
/** * Returns the local address to which the socket is bound. * THIS METHOD IS EXPECTED TO BE USED FOR TESTING ONLY!!! * * @since 3.3.0 * * @return ip address of the remote side of the connection or null if * not connected */ protected SocketAddress testableLocalSocketAddress() { return cnxn.sendThread.getClientCnxnSocket().getLocalSocketAddress(); }
public void testRoundTrip() throws IOException { MultiResponse response = new MultiResponse(); response.add(new OpResult.CheckResult()); response.add(new OpResult.CreateResult("foo-bar")); response.add(new OpResult.DeleteResult()); Stat s = new Stat(); s.setCzxid(546); response.add(new OpResult.SetDataResult(s)); MultiResponse decodedResponse = codeDecode(response); Assert.assertEquals(response, decodedResponse); Assert.assertEquals(response.hashCode(), decodedResponse.hashCode()); }
public boolean execute() throws KeeperException, InterruptedException { zookeeper.delete(id, -1); return Boolean.TRUE; } };
@Override public void injectSessionExpiration() { LOG.info("injectSessionExpiration() called"); clientCnxn.eventThread.queueEvent(new WatchedEvent( Watcher.Event.EventType.None, Watcher.Event.KeeperState.Expired, null)); clientCnxn.eventThread.queueEventOfDeath(); clientCnxn.state = ZooKeeper.States.CLOSED; clientCnxn.sendThread.getClientCnxnSocket().onClosing(); } }
public void process(WatchedEvent event) { if (getPrintWatches()) { ZooKeeperMain.printMessage("WATCHER::"); ZooKeeperMain.printMessage(event.toString()); } } }
private static int checkAndIncVersion(int currentVersion, int expectedVersion, String path) throws KeeperException.BadVersionException { if (expectedVersion != -1 && expectedVersion != currentVersion) { throw new KeeperException.BadVersionException(path); } return currentVersion + 1; }
/** * Get the name of the server principal for a SASL client. * @param addr the address of the host. * @param clientConfig the configuration for the client. * @return the name of the principal. */ static String getServerPrincipal(InetSocketAddress addr, ZKClientConfig clientConfig) { return getServerPrincipal(new WrapperInetSocketAddress(addr), clientConfig); }
public void saslCompleted() { sendThread.getClientCnxnSocket().saslCompleted(); }
@Override public String toString() { return "EndOfStreamException: " + getMessage(); } }
/** * The session password for this ZooKeeper client instance. The value * returned is not valid until the client connects to a server and may * change after a re-connect. * * This method is NOT thread safe * * @return current session password */ public byte[] getSessionPasswd() { return cnxn.getSessionPasswd(); }
/** * The Asynchronous version of getConfig. * * @see #getData(String, boolean, Stat) */ public void getConfig(boolean watch, DataCallback cb, Object ctx) { getConfig(watch ? watchManager.defaultWatcher : null, cb, ctx); }
/** * Constructs a delete operation. Arguments are as for the ZooKeeper method of the same name. * @see ZooKeeper#delete(String, int) * * @param path * the path of the node to be deleted. * @param version * the expected node version. */ public static Op delete(String path, int version) { return new Delete(path, version); }
@Override Op withChroot(String path) { return new SetData(path, data, version); } }
@Override Op withChroot(String path) { return new Check(path, version); } }
@Override protected TestableZooKeeper createClient(String hp) throws IOException, InterruptedException { MyWatcher watcher = new MyWatcher(); return createClient(watcher, hp); }