static boolean grabTicket ( ZooKeeper zookeeper , String lockNode , String ticket ) throws InterruptedException , KeeperException { try { zookeeper . create ( lockNode + "/" + ticket , new byte [ 0 ] , ZooDefs . Ids . OPEN_ACL_UNSAFE , CreateMode . EPHEMERAL ) ; } catch ( KeeperException e ) { if ( e . code ( ) == KeeperException . Code . NODEEXISTS ) { // It is possible that two processes try to grab the exact same ticket at the same time. // This is common for the locking ticket. logger . debug ( "Failed to claim ticket {}." , ticket ) ; return false ; } else { throw e ; } } logger . debug ( "Claimed ticket {}." , ticket ) ; return true ; }
Grab a ticket in the queue .