public boolean enter ( long maxWait , TimeUnit unit ) throws Exception { long startMs = System . currentTimeMillis ( ) ; boolean hasMaxWait = ( unit != null ) ; long maxWaitMs = hasMaxWait ? TimeUnit . MILLISECONDS . convert ( maxWait , unit ) : Long . MAX_VALUE ; boolean readyPathExists = ( client . checkExists ( ) . usingWatcher ( watcher ) . forPath ( readyPath ) != null ) ; client . create ( ) . creatingParentContainersIfNeeded ( ) . withMode ( CreateMode . EPHEMERAL ) . forPath ( ourPath ) ; boolean result = ( readyPathExists || internalEnter ( startMs , hasMaxWait , maxWaitMs ) ) ; if ( connectionLost . get ( ) ) { throw new KeeperException . ConnectionLossException ( ) ; } return result ; }
Enter the barrier and block until all members have entered or the timeout has elapsed