boolean attemptToClaim ( String workUnit , boolean claimForHandoff ) throws InterruptedException { LOG . debug ( "Attempting to claim {}. For handoff? {}" , workUnit , claimForHandoff ) ; String path = claimForHandoff ? String . format ( "/%s/handoff-result/%s" , cluster . name , workUnit ) : cluster . workUnitClaimPath ( workUnit ) ; final boolean created = ZKUtils . createEphemeral ( cluster . zk , path , cluster . myNodeID ) ; if ( created ) { if ( claimForHandoff ) { cluster . claimedForHandoff . add ( workUnit ) ; } cluster . startWork ( workUnit ) ; return true ; } if ( isPeggedToMe ( workUnit ) ) { claimWorkPeggedToMe ( workUnit ) ; return true ; } return false ; }
Attempts to claim a given work unit by creating an ephemeral node in ZooKeeper with this node s ID . If the claim succeeds start work . If not move on .