org.apache.accumulo.server.zookeeper.ZooQueueLock类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(3.4k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.apache.accumulo.server.zookeeper.ZooQueueLock类的一些代码示例,展示了ZooQueueLock类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooQueueLock类的具体详情如下:
包路径:org.apache.accumulo.server.zookeeper.ZooQueueLock
类名称:ZooQueueLock

ZooQueueLock介绍

暂无

代码示例

代码示例来源:origin: org.apache.accumulo/accumulo-server

public static void main(String args[]) throws InterruptedException, KeeperException {
 ZooQueueLock lock = new ZooQueueLock("/lock", true);
 DistributedReadWriteLock rlocker = new DistributedReadWriteLock(lock, "reader".getBytes(UTF_8));
 DistributedReadWriteLock wlocker = new DistributedReadWriteLock(lock, "wlocker".getBytes(UTF_8));
 final Lock readLock = rlocker.readLock();
 readLock.lock();
 final Lock readLock2 = rlocker.readLock();
 readLock2.lock();
 final Lock writeLock = wlocker.writeLock();
 if (writeLock.tryLock(100, TimeUnit.MILLISECONDS))
  throw new RuntimeException("Write lock achieved during read lock!");
 readLock.unlock();
 readLock2.unlock();
 writeLock.lock();
 if (readLock.tryLock(100, TimeUnit.MILLISECONDS))
  throw new RuntimeException("Read lock achieved during write lock!");
 final Lock writeLock2 = DistributedReadWriteLock.recoverLock(lock, "wlocker".getBytes(UTF_8));
 writeLock2.unlock();
 readLock.lock();
 System.out.println("success");
}

代码示例来源:origin: org.apache.accumulo/accumulo-server-base

public static void main(String args[]) throws InterruptedException, KeeperException {
 ZooQueueLock lock = new ZooQueueLock("/lock", true);
 DistributedReadWriteLock rlocker = new DistributedReadWriteLock(lock, "reader".getBytes(UTF_8));
 DistributedReadWriteLock wlocker = new DistributedReadWriteLock(lock,
   "wlocker".getBytes(UTF_8));
 final Lock readLock = rlocker.readLock();
 readLock.lock();
 final Lock readLock2 = rlocker.readLock();
 readLock2.lock();
 final Lock writeLock = wlocker.writeLock();
 if (writeLock.tryLock(100, TimeUnit.MILLISECONDS))
  throw new RuntimeException("Write lock achieved during read lock!");
 readLock.unlock();
 readLock2.unlock();
 writeLock.lock();
 if (readLock.tryLock(100, TimeUnit.MILLISECONDS))
  throw new RuntimeException("Read lock achieved during write lock!");
 final Lock writeLock2 = DistributedReadWriteLock.recoverLock(lock, "wlocker".getBytes(UTF_8));
 writeLock2.unlock();
 readLock.lock();
 System.out.println("success");
}

代码示例来源:origin: org.apache.accumulo/accumulo-master

private static Lock getLock(String tableId, long tid, boolean writeLock) throws Exception {
 byte[] lockData = String.format("%016x", tid).getBytes(UTF_8);
 ZooQueueLock qlock = new ZooQueueLock(
   ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZTABLE_LOCKS + "/" + tableId,
   false);
 Lock lock = DistributedReadWriteLock.recoverLock(qlock, lockData);
 if (lock == null) {
  DistributedReadWriteLock locker = new DistributedReadWriteLock(qlock, lockData);
  if (writeLock)
   lock = locker.writeLock();
  else
   lock = locker.readLock();
 }
 return lock;
}

代码示例来源:origin: org.apache.accumulo/accumulo-server

private static Lock getLock(String tableId, long tid, boolean writeLock) throws Exception {
 byte[] lockData = String.format("%016x", tid).getBytes(UTF_8);
 ZooQueueLock qlock = new ZooQueueLock(ZooUtil.getRoot(HdfsZooInstance.getInstance()) + Constants.ZTABLE_LOCKS + "/" + tableId, false);
 Lock lock = DistributedReadWriteLock.recoverLock(qlock, lockData);
 if (lock == null) {
  DistributedReadWriteLock locker = new DistributedReadWriteLock(qlock, lockData);
  if (writeLock)
   lock = locker.writeLock();
  else
   lock = locker.readLock();
 }
 return lock;
}

相关文章

ZooQueueLock类方法