List of usage examples for org.apache.zookeeper KeeperException.SystemErrorException KeeperException.SystemErrorException
KeeperException.SystemErrorException
From source file:com.dw.zk.DefaultZkSessionManager.java
License:Apache License
/** * This method ensures a ZK session is fully CONNECTED state, and not in a CONNECTING state. *///from w w w . ja va2 s .c om private void ensureConnectionEstablishedBeforeProceeding() throws KeeperException.SystemErrorException { if (logger.isDebugEnabled()) { logger.debug("The current Zookeeper state is " + zk.getState() + "."); } if (zk.getState() == ZooKeeper.States.CONNECTING) { for (int retry = 0; (retry * connectedCheckDelay) < maxConnectionWaitTime; retry++) { if (zk.getState() == ZooKeeper.States.CONNECTED) { break; } else { if (logger.isDebugEnabled()) { logger.debug("Time waited for Zookeeper CONNECTED state is currently " + (retry * connectedCheckDelay) + " milliseconds."); } try { Thread.sleep(connectedCheckDelay); } catch (InterruptedException e) { logger.debug("sleep interrupted"); } } } } if (zk.getState() != ZooKeeper.States.CONNECTED) { if (logger.isDebugEnabled()) { logger.error("Zookeeper failed to achieve a CONNECTED state. The current state is " + zk.getState() + "."); } throw new KeeperException.SystemErrorException(); } }