@Override public boolean lock(){
  try {
    lockPath=zk.create(this.lockTypeFolder + CarbonCommonConstants.FILE_SEPARATOR + lockName,null,Ids.OPEN_ACL_UNSAFE,CreateMode.EPHEMERAL_SEQUENTIAL);
    List<String> nodes=zk.getChildren(this.lockTypeFolder,null);
    Collections.sort(nodes);
    if (lockPath.endsWith(nodes.get(0))) {
      return true;
    }
 else {
      zk.delete(lockPath,-1);
      return false;
    }
  }
 catch (  KeeperException|InterruptedException e) {
    LOGGER.error(e,e.getMessage());
    return false;
  }
}

@ Override public boolean lock ( ) { try { lockPath = zk . create ( this . lockTypeFolder + CarbonCommonConstants . FILE_SEPARATOR + lockName , null , Ids . OPEN_ACL_UNSAFE , CreateMode . EPHEMERAL_SEQUENTIAL ) ; List < String > nodes = zk . getChildren ( this . lockTypeFolder , null ) ; Collections . sort ( nodes ) ; if ( lockPath . endsWith ( nodes . get ( 0 ) ) ) { return true ; } else { zk . delete ( lockPath , - 1 ) ; return false ; } } catch ( KeeperException | InterruptedException e ) { LOGGER . error ( e , e . getMessage ( ) ) ; return false ; } }
handling of the locking mechanism using zoo keeper .
