@ Override public void process ( WatchedEvent event ) { if ( LOG . isDebugEnabled ( ) ) { LOG . info ( "Received ZooKeeper Event, " + "type=" + event . getType ( ) + ", " + "state=" + event . getState ( ) + ", " + "path=" + event . getPath ( ) ) ; } switch ( event . getType ( ) ) { case None : { switch ( event . getState ( ) ) { case SyncConnected : { try { waitToInitZooKeeper ( 2000 ) ; // init zookeeper in another thread, wait for a while } catch ( Exception e ) { LOG . error ( "Error to init ZooKeeper object after sleeping 2000 ms, reconnect ZooKeeper" ) ; try { reconnectZooKeeper ( ) ; } catch ( Exception e1 ) { LOG . error ( "Error to reconnect with ZooKeeper" , e1 ) ; } } break ; } default : break ; } break ; } default : break ; } }
Deal with connection event just wait for a while when connected .