Tabnine Logo
ReentrantDistributedLock
Code IndexAdd Tabnine to your IDE (free)

How to use
ReentrantDistributedLock
in
org.apache.twill.internal.zookeeper

Best Java code snippets using org.apache.twill.internal.zookeeper.ReentrantDistributedLock (Showing top 14 results out of 315)

origin: org.apache.twill/twill-core

@Override
public Lock createLock(String name) {
 return new ReentrantDistributedLock(zkClient, "/lock/" + name);
}
origin: org.apache.twill/twill-zookeeper

/**
 * Acquires a distributed lock through ZooKeeper. It's the same as calling
 * {@link #acquire(boolean, boolean, long, 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: apache/twill

@Override
public Lock createLock(String name) {
 return new ReentrantDistributedLock(zkClient, "/lock/" + name);
}
origin: apache/twill

/**
 * Acquires a distributed lock through ZooKeeper. It's the same as calling
 * {@link #acquire(boolean, boolean, long, 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: co.cask.cdap/cdap-data-fabric

@Override
protected Lock getLock(StreamId streamId) {
 // It's ok to create new locks every time as it's backed by ZK for distributed lock
 ZKClient lockZKClient = ZKClients.namespace(zkClient, "/" + Constants.Service.STREAMS + "/locks");
 return new ReentrantDistributedLock(lockZKClient, streamId.toString());
}
origin: apache/twill

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

this.logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
this.zkClient = injector.getInstance(ZKClientService.class);
this.shutdownLock = new ReentrantDistributedLock(zkClient, "/lock/" + Constants.Service.MASTER_SERVICES);
origin: org.apache.twill/twill-zookeeper

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

@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: org.apache.twill/twill-zookeeper

@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: org.apache.twill/twill-zookeeper

@Override
public void lockInterruptibly() throws InterruptedException {
 lock.lockInterruptibly();
 try {
  acquire(true, true);
 } catch (Exception e) {
  lock.unlock();
  Throwables.propagateIfInstanceOf(e, InterruptedException.class);
  throw Throwables.propagate(e);
 }
}
origin: apache/twill

@Override
public void lockInterruptibly() throws InterruptedException {
 lock.lockInterruptibly();
 try {
  acquire(true, true);
 } catch (Exception e) {
  lock.unlock();
  Throwables.propagateIfInstanceOf(e, InterruptedException.class);
  throw Throwables.propagate(e);
 }
}
origin: apache/twill

@Override
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
 long startTime = System.nanoTime();
 if (!lock.tryLock(time, unit)) {
  return false;
 }
 long timeoutNano = unit.toNanos(time) - (System.nanoTime() - startTime);
 try {
  if (acquire(true, true, timeoutNano, TimeUnit.NANOSECONDS)) {
   return true;
  }
  lock.unlock();
  return false;
 } catch (ExecutionException e) {
  lock.unlock();
  throw Throwables.propagate(e.getCause());
 } catch (TimeoutException e) {
  lock.unlock();
  return false;
 }
}
origin: org.apache.twill/twill-zookeeper

@Override
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException {
 long startTime = System.nanoTime();
 if (!lock.tryLock(time, unit)) {
  return false;
 }
 long timeoutNano = unit.toNanos(time) - (System.nanoTime() - startTime);
 try {
  if (acquire(true, true, timeoutNano, TimeUnit.NANOSECONDS)) {
   return true;
  }
  lock.unlock();
  return false;
 } catch (ExecutionException e) {
  lock.unlock();
  throw Throwables.propagate(e.getCause());
 } catch (TimeoutException e) {
  lock.unlock();
  return false;
 }
}
org.apache.twill.internal.zookeeperReentrantDistributedLock

Javadoc

A reentrant distributed lock implementation that uses ZooKeeper. It uses the recipe 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.

Popular in Java

  • Running tasks concurrently on multiple threads
  • putExtra (Intent)
  • getSharedPreferences (Context)
  • getSystemService (Context)
  • Table (com.google.common.collect)
    A collection that associates an ordered pair of keys, called a row key and a column key, with a sing
  • Kernel (java.awt.image)
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Top Vim plugins
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