if (!cnxn.getState().isAlive()) { if (LOG.isDebugEnabled()) { LOG.debug("Close called on already closed client");
/** * Close this client object. Once the client is closed, its session becomes * invalid. All the ephemeral nodes in the ZooKeeper server associated with * the session will be removed. The watches left on those nodes (and on * their parents) will be triggered. * * @throws InterruptedException */ public synchronized void close() throws InterruptedException { if (!cnxn.getState().isAlive()) { if (LOG.isDebugEnabled()) { LOG.debug("Close called on already closed client"); } return; } if (LOG.isDebugEnabled()) { LOG.debug("Closing session: 0x" + Long.toHexString(getSessionId())); } try { cnxn.close(); } catch (IOException e) { if (LOG.isDebugEnabled()) { LOG.debug("Ignoring unexpected exception during close", e); } } LOG.info("Session: 0x" + Long.toHexString(getSessionId()) + " closed"); }
/** {@inheritDoc} */ @Override public void run() { try { zkClient.exists(paths.clusterDir, false); } catch (Throwable t) { if (zkClient.getState().isAlive()) U.warn(log, "Failed to ping Zookeeper.", t); else scheduler.cancel(); } }
final int MAX_SEND_PING_INTERVAL = 10000; //10 seconds InetSocketAddress serverAddress = null; while (state.isAlive()) { try { if (!clientCnxnSocket.isConnected()) { if (closing || !state.isAlive()) { break; if (state.isAlive()) { eventThread.queueEvent(new WatchedEvent( Event.EventType.None, if (state.isAlive()) { eventThread.queueEvent(new WatchedEvent(Event.EventType.None, Event.KeeperState.Disconnected, null));
if (!zk.getState().isAlive()) return;
Packet queuePacket(RequestHeader h, ReplyHeader r, Record request, Record response, AsyncCallback cb, String clientPath, String serverPath, Object ctx, WatchRegistration watchRegistration) { Packet packet = null; // Note that we do not generate the Xid for the packet yet. It is // generated later at send-time, by an implementation of ClientCnxnSocket::doIO(), // where the packet is actually sent. synchronized (outgoingQueue) { packet = new Packet(h, r, request, response, watchRegistration); packet.cb = cb; packet.ctx = ctx; packet.clientPath = clientPath; packet.serverPath = serverPath; if (!state.isAlive() || closing) { conLossPacket(packet); } else { // If the client is asking to close the session then // mark as closing if (h.getType() == OpCode.closeSession) { closing = true; } outgoingQueue.add(packet); } } sendThread.getClientCnxnSocket().wakeupCnxn(); return packet; }
if (zk == null || !zk.getState().isAlive()) { System.out.println("Not connected"); return false;
@Override public void run() { while (!isClosed) { lock.lock(); try { if (zk == null || !zk.getState().isAlive()) { LOGGER.info("is not alive, try close before and new connect to zk"); tryReConnect(); } conditionNotConnect.await(1000, TimeUnit.MILLISECONDS); } catch (Exception e) { LOGGER.error("guard error, sleep 1000 to retry", e); try { Thread.sleep(1000); } catch (InterruptedException ignored) { } } finally { lock.unlock(); } } } };
@Override public void run() { while (!isClosed) { lock.lock(); try { if (zk == null || !zk.getState().isAlive()) { LOGGER.info("is not alive, try close before and new connect to zk"); tryReConnect(); } conditionNotConnect.await(1000, TimeUnit.MILLISECONDS); } catch (Exception e) { LOGGER.error("guard error, sleep 1000 to retry", e); try { Thread.sleep(1000); } catch (InterruptedException ignored) { } } finally { lock.unlock(); } } } };
if (!sendThread.getZkState().isAlive()) {
if (!state.isAlive() || closing) { conLossPacket(packet); } else {
synchronized ZooKeeper getZooKeeper() throws IOException { if (zooKeeper != null && !zooKeeper.getState().isAlive()) { invalidateClient(); } if (zooKeeper == null) { zooKeeper = new ZooKeeper(connectionString, timeoutMillis, new Watcher() { @Override public void process(WatchedEvent event) { } }); if (auth != null) { zooKeeper.addAuthInfo("digest", auth); } } return zooKeeper; }
public void addAuthInfo(String scheme, byte auth[]) { if (!state.isAlive()) { return; } authInfo.add(new AuthData(scheme, auth)); queuePacket(new RequestHeader(-4, OpCode.auth), null, new AuthPacket(0, scheme, auth), null, null, null, null, null, null); }
protected void connectToZK(String newHost) throws InterruptedException, IOException { if (zk != null && zk.getState().isAlive()) { zk.close(); } host = newHost; boolean readOnly = cl.getOption("readonly") != null; zk = new ZooKeeper(host, Integer.parseInt(cl.getOption("timeout")), new MyWatcher(), readOnly); }
private ZooKeeper getZk() throws IOException { // may be closed when session expired if (zookeeper == null || !zookeeper.getState().isAlive()) { zookeeper = new ZooKeeper(connectString, sessionTimeoutMs, e -> {}); } return zookeeper; }
public void addAuthInfo(String scheme, byte auth[]) { if (!state.isAlive()) { return; } authInfo.add(new AuthData(scheme, auth)); queuePacket(new RequestHeader(-4, OpCode.auth), null, new AuthPacket(0, scheme, auth), null, null, null, null, null, null); }
protected void connectToZK(String newHost) throws InterruptedException, IOException { if (zk != null && zk.getState().isAlive()) { zk.close(); } host = newHost; boolean readOnly = cl.getOption("readonly") != null; if (cl.getOption("secure") != null) { System.setProperty(ZKClientConfig.SECURE_CLIENT, "true"); System.out.println("Secure connection is enabled"); } zk = new ZooKeeperAdmin(host, Integer.parseInt(cl.getOption("timeout")), new MyWatcher(), readOnly); }
private void cleanAndNotifyState() { cleanup(); if (state.isAlive()) { eventThread.queueEvent(new WatchedEvent(Event.EventType.None, Event.KeeperState.Disconnected, null)); } clientCnxnSocket.updateNow(); clientCnxnSocket.updateLastSendAndHeard(); }