congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ReentrantDistributedLock
Code IndexAdd Tabnine to your IDE (free)

How to use
ReentrantDistributedLock
in
co.cask.coopr.common.zookeeper.lib

Best Java code snippets using co.cask.coopr.common.zookeeper.lib.ReentrantDistributedLock (Showing top 20 results out of 315)

origin: caskdata/coopr

 @Override
 protected Lock initialValue() {
  return new ReentrantDistributedLock(zkClient, IDS_BASEPATH + "/lock");
 }
};
origin: caskdata/coopr

/**
 * Acquires a distributed lock through ZooKeeper. It's the same as calling
 * {@link #acquire(boolean, boolean, long, java.util.concurrent.TimeUnit)} with {@link Long#MAX_VALUE} as timeout.
 */
private boolean acquire(boolean interruptible, boolean waitForLock) throws InterruptedException, ExecutionException {
 try {
  return acquire(interruptible, waitForLock, Long.MAX_VALUE, TimeUnit.SECONDS);
 } catch (TimeoutException e) {
  // Should never happen
  throw Throwables.propagate(e);
 }
}
origin: caskdata/coopr

@Test (timeout = 20000)
public void testReentrant() {
 // Test the lock is reentrant from the same thread
 ZKClientService zkClient = createZKClient();
 try {
  ReentrantDistributedLock lock = new ReentrantDistributedLock(zkClient, "reentrant");
  lock.lock();
  try {
   try {
    lock.lock();
   } finally {
    lock.unlock();
   }
  } finally {
   lock.unlock();
  }
 } finally {
  zkClient.stopAndWait();
 }
}
origin: caskdata/coopr

ZKClientService zkClient2 = createZKClient();
try {
 final ReentrantDistributedLock lock1 = new ReentrantDistributedLock(zkClient1, "/multiTrylock");
 final ReentrantDistributedLock lock2 = new ReentrantDistributedLock(zkClient2, "/multiTrylock");
 lock1.lock();
 try {
  t.start();
  Assert.assertTrue(lockFailed.await(5000, TimeUnit.SECONDS));
 } finally {
  lock1.unlock();
 Assert.assertTrue(lock1.tryLock());
 lock1.unlock();
} finally {
 zkClient1.stopAndWait();
origin: caskdata/coopr

 @Override
 public void run() {
  lock2.lock();
  try {
   lockAcquired.countDown();
  } finally {
   lock2.unlock();
  }
 }
};
origin: caskdata/coopr

 @Override
 public void run() {
  try {
   lock2.lockInterruptibly();
   try {
    lockAcquired.countDown();
   } finally {
    lock2.unlock();
   }
  } catch (InterruptedException e) {
   lockInterrupted.countDown();
  }
 }
};
origin: caskdata/coopr

 @Override
 public void run() {
  try {
   if (!lock.tryLock()) {
    lockFailed.countDown();
   }
   if (!lock.tryLock(1, TimeUnit.SECONDS)) {
    lockFailed.countDown();
   }
   if (lock.tryLock(5, TimeUnit.SECONDS)) {
    // Test the reentrant park as well
    if (lock.tryLock(1, TimeUnit.SECONDS)) {
     if (lock.tryLock()) {
      lockAcquired.countDown();
      lock.unlock();
     }
     lock.unlock();
    }
    lock.unlock();
   }
  } catch (InterruptedException e) {
   // Shouldn't happen
   LOG.error(e.getMessage(), e);
  }
 }
};
origin: caskdata/coopr

ZKClientService zkClient2 = createZKClient();
try {
 final ReentrantDistributedLock lock1 = new ReentrantDistributedLock(zkClient1, "/multiInterrupt");
 final ReentrantDistributedLock lock2 = new ReentrantDistributedLock(zkClient2, "/multiInterrupt");
 lock1.lock();
  lock1.unlock();
 lock2.lock();
 lock2.unlock();
origin: caskdata/coopr

 final ReentrantDistributedLock lock = new ReentrantDistributedLock(zkClient, "/trylock");
 lock.lock();
 try {
  t.start();
  Assert.assertTrue(lockFailed.await(5, TimeUnit.SECONDS));
 } finally {
  lock.unlock();
 Assert.assertTrue(lock.tryLock());
 lock.unlock();
} finally {
 zkClient.stopAndWait();
origin: caskdata/coopr

 @Override
 public void run() {
  lock.lock();
  try {
   acquired.countDown();
  } finally {
   lock.unlock();
  }
 }
};
origin: caskdata/coopr

 @Override
 public void run() {
  try {
   lock.lockInterruptibly();
   try {
    lockAcquired.countDown();
   } finally {
    lock.unlock();
   }
  } catch (InterruptedException e) {
   lockInterrupted.countDown();
  }
 }
};
origin: caskdata/coopr

 @Override
 public void run() {
  try {
   if (!lock2.tryLock()) {
    lockFailed.countDown();
   }
   if (!lock2.tryLock(1, TimeUnit.SECONDS)) {
    lockFailed.countDown();
   }
   if (lock2.tryLock(5000, TimeUnit.SECONDS)) {
    // Test the reentrant park as well
    if (lock2.tryLock(1, TimeUnit.SECONDS)) {
     if (lock2.tryLock()) {
      lockAcquired.countDown();
      lock2.unlock();
     }
     lock2.unlock();
    }
    lock2.unlock();
   }
  } catch (InterruptedException e) {
   // Shouldn't happen
   LOG.error(e.getMessage(), e);
  }
 }
};
origin: caskdata/coopr

try {
 final ReentrantDistributedLock lock = new ReentrantDistributedLock(zkClient, "multiThreads");
 final CountDownLatch acquired = new CountDownLatch(1);
 Thread t = new Thread() {
 lock.lock();
 try {
  t.start();
  lock.unlock();
origin: caskdata/coopr

 @Override
 protected Lock initialValue() {
  return new ReentrantDistributedLock(zkClient, basePath);
 }
};
origin: caskdata/coopr

@Override
public void lock() {
 lock.lock();
 try {
  acquire(false, true);
 } catch (Exception e) {
  lock.unlock();
  throw Throwables.propagate(e);
 }
}
origin: caskdata/coopr

final ReentrantDistributedLock lock = new ReentrantDistributedLock(zkClient, "/interrupt");
lock.lock();
try {
 final CountDownLatch lockAcquired = new CountDownLatch(1);
 Assert.assertTrue(lockInterrupted.await(2, TimeUnit.SECONDS));
} finally {
 lock.unlock();
origin: caskdata/coopr

 public Lock getTenantProvisionerLock() {
  return new ReentrantDistributedLock(zkClient, Constants.Lock.TENANT_NAMESPACE);
 }
}
origin: caskdata/coopr

@Override
public boolean tryLock() {
 if (!lock.tryLock()) {
  return false;
 }
 try {
  if (acquire(false, false)) {
   return true;
  }
  lock.unlock();
  return false;
 } catch (Exception e) {
  lock.unlock();
  throw Throwables.propagate(e);
 }
}
origin: caskdata/coopr

try {
 ReentrantDistributedLock lock1 = new ReentrantDistributedLock(zkClient1, "multiClients");
 final ReentrantDistributedLock lock2 = new ReentrantDistributedLock(zkClient2, "multiClients");
 lock1.lock();
 try {
  lock1.lock();
  lock1.unlock();
  lock1.unlock();
origin: caskdata/coopr

public SynchronizedZKMap(ZKClient zkClient, Serializer<T> serializer) {
 this.zkClient = zkClient;
 this.serializer = serializer;
 this.currentView = Maps.newHashMap();
 this.currentViewVersion = -1;
 this.globalLock = new ReentrantDistributedLock(zkClient, LOCK_PATH);
}
co.cask.coopr.common.zookeeper.libReentrantDistributedLock

Javadoc

A reentrant distributed lock implementation that uses ZooKeeper using the receipt described in http://zookeeper.apache.org/doc/trunk/recipes.html#sc_recipes_Locks

Most used methods

  • <init>
    Creates a distributed lock instance.
  • acquire
    Acquires a distributed lock through ZooKeeper.
  • lock
  • lockInterruptibly
  • tryLock
  • unlock

Popular in Java

  • Updating database using SQL prepared statement
  • putExtra (Intent)
  • getSupportFragmentManager (FragmentActivity)
  • onCreateOptionsMenu (Activity)
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now