congrats Icon
New! Announcing our next generation AI code completions
Read here
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

  • Reading from database using SQL prepared statement
  • getResourceAsStream (ClassLoader)
  • addToBackStack (FragmentTransaction)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • PhpStorm for WordPress
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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