Tabnine Logo
Monitor$Guard
Code IndexAdd Tabnine to your IDE (free)

How to use
Monitor$Guard
in
com.google.common.util.concurrent

Best Java code snippets using com.google.common.util.concurrent.Monitor$Guard (Showing top 20 results out of 315)

Refine searchRefine arrow

  • Monitor
  • ReentrantLock
  • GuardedBy
  • Condition
origin: google/guava

final long timeoutNanos = toSafeNanos(time, unit);
if (guard.monitor != this) {
 throw new IllegalMonitorStateException();
boolean reentrant = lock.isHeldByCurrentThread();
long startTime = 0L;
   throw new InterruptedException();
  if (lock.tryLock()) {
   break locked;
 startTime = initNanoTime(timeoutNanos);
 if (!lock.tryLock(time, unit)) {
  return false;
try {
 satisfied =
   guard.isSatisfied()
     || awaitNanos(
       guard,
       (startTime == 0L) ? timeoutNanos : remainingNanos(startTime, timeoutNanos),
origin: google/guava

/**
 * Enters this monitor if the guard is satisfied. Blocks indefinitely acquiring the lock, but does
 * not wait for the guard to be satisfied.
 *
 * @return whether the monitor was entered, which guarantees that the guard is now satisfied
 */
public boolean enterIf(Guard guard) {
 if (guard.monitor != this) {
  throw new IllegalMonitorStateException();
 }
 final ReentrantLock lock = this.lock;
 lock.lock();
 boolean satisfied = false;
 try {
  return satisfied = guard.isSatisfied();
 } finally {
  if (!satisfied) {
   lock.unlock();
  }
 }
}
origin: google/guava

@GuardedBy("lock")
private void await(Guard guard, boolean signalBeforeWaiting) throws InterruptedException {
 if (signalBeforeWaiting) {
  signalNextWaiter();
 }
 beginWaitingFor(guard);
 try {
  do {
   guard.condition.await();
  } while (!guard.isSatisfied());
 } finally {
  endWaitingFor(guard);
 }
}
origin: google/guava

/**
 * Enters this monitor if the guard is satisfied. Blocks at most the given time acquiring the
 * lock, but does not wait for the guard to be satisfied, and may be interrupted.
 *
 * @return whether the monitor was entered, which guarantees that the guard is now satisfied
 */
@SuppressWarnings("GoodTime") // should accept a java.time.Duration
public boolean enterIfInterruptibly(Guard guard, long time, TimeUnit unit)
  throws InterruptedException {
 if (guard.monitor != this) {
  throw new IllegalMonitorStateException();
 }
 final ReentrantLock lock = this.lock;
 if (!lock.tryLock(time, unit)) {
  return false;
 }
 boolean satisfied = false;
 try {
  return satisfied = guard.isSatisfied();
 } finally {
  if (!satisfied) {
   lock.unlock();
  }
 }
}
origin: google/guava

/**
 * Enters this monitor if the guard is satisfied. Blocks at most the given time acquiring the
 * lock, but does not wait for the guard to be satisfied.
 *
 * @return whether the monitor was entered, which guarantees that the guard is now satisfied
 */
@SuppressWarnings("GoodTime") // should accept a java.time.Duration
public boolean enterIf(Guard guard, long time, TimeUnit unit) {
 if (guard.monitor != this) {
  throw new IllegalMonitorStateException();
 }
 if (!enter(time, unit)) {
  return false;
 }
 boolean satisfied = false;
 try {
  return satisfied = guard.isSatisfied();
 } finally {
  if (!satisfied) {
   lock.unlock();
  }
 }
}
origin: google/guava

/** Enters this monitor when the guard is satisfied. Blocks indefinitely. */
public void enterWhenUninterruptibly(Guard guard) {
 if (guard.monitor != this) {
  throw new IllegalMonitorStateException();
 }
 final ReentrantLock lock = this.lock;
 boolean signalBeforeWaiting = lock.isHeldByCurrentThread();
 lock.lock();
 boolean satisfied = false;
 try {
  if (!guard.isSatisfied()) {
   awaitUninterruptibly(guard, signalBeforeWaiting);
  }
  satisfied = true;
 } finally {
  if (!satisfied) {
   leave();
  }
 }
}
origin: google/guava

/**
 * Enters this monitor if the guard is satisfied. Blocks indefinitely acquiring the lock, but does
 * not wait for the guard to be satisfied, and may be interrupted.
 *
 * @return whether the monitor was entered, which guarantees that the guard is now satisfied
 * @throws InterruptedException if interrupted while waiting
 */
public boolean enterIfInterruptibly(Guard guard) throws InterruptedException {
 if (guard.monitor != this) {
  throw new IllegalMonitorStateException();
 }
 final ReentrantLock lock = this.lock;
 lock.lockInterruptibly();
 boolean satisfied = false;
 try {
  return satisfied = guard.isSatisfied();
 } finally {
  if (!satisfied) {
   lock.unlock();
  }
 }
}
origin: google/j2objc

/**
 * A boolean condition for which a thread may wait. A {@code Guard} is associated with a single
 * {@code Monitor}. The monitor may check the guard at arbitrary times from any thread occupying
 * the monitor, so code should not be written to rely on how often a guard might or might not be
 * checked.
 *
 * <p>If a {@code Guard} is passed into any method of a {@code Monitor} other than the one it is
 * associated with, an {@link IllegalMonitorStateException} is thrown.
 *
 * @since 10.0
 */
@Beta
public abstract static class Guard {
 @Weak final Monitor monitor;
 final Condition condition;
 @GuardedBy("monitor.lock")
 int waiterCount = 0;
 /** The next active guard */
 @GuardedBy("monitor.lock")
 @NullableDecl Guard next;
 protected Guard(Monitor monitor) {
  this.monitor = checkNotNull(monitor, "monitor");
  this.condition = monitor.lock.newCondition();
 }
 /**
origin: google/guava

 /** Caller should check before calling that guard is not satisfied. */
 @GuardedBy("lock")
 private boolean awaitNanos(Guard guard, long nanos, boolean signalBeforeWaiting)
   throws InterruptedException {
  boolean firstTime = true;
  try {
   do {
    if (nanos <= 0L) {
     return false;
    }
    if (firstTime) {
     if (signalBeforeWaiting) {
      signalNextWaiter();
     }
     beginWaitingFor(guard);
     firstTime = false;
    }
    nanos = guard.condition.awaitNanos(nanos);
   } while (!guard.isSatisfied());
   return true;
  } finally {
   if (!firstTime) {
    endWaitingFor(guard);
   }
  }
 }
}
origin: org.hudsonci.lib.guava/guava

@GuardedBy("lock")
private void signalConditionsOfSatisfiedGuards(@Nullable Guard interruptedGuard) {
 final ArrayList<Guard> guards = this.activeGuards;
 final int guardCount = guards.size();
 try {
  for (int i = 0; i < guardCount; i++) {
   Guard guard = guards.get(i);
   if ((guard == interruptedGuard) && (guard.waiterCount == 1)) {
    // That one waiter was just interrupted and is throwing InterruptedException rather than
    // paying attention to the guard being satisfied, so find another waiter on another guard.
    continue;
   }
   if (guard.isSatisfied()) {
    guard.condition.signal();
    return;
   }
  }
 } catch (Throwable throwable) {
  for (int i = 0; i < guardCount; i++) {
   Guard guard = guards.get(i);
   guard.condition.signalAll();
  }
  throw Throwables.propagate(throwable);
 }
}

origin: google/guava

@GuardedBy("lock")
private void awaitUninterruptibly(Guard guard, boolean signalBeforeWaiting) {
 if (signalBeforeWaiting) {
  signalNextWaiter();
 }
 beginWaitingFor(guard);
 try {
  do {
   guard.condition.awaitUninterruptibly();
  } while (!guard.isSatisfied());
 } finally {
  endWaitingFor(guard);
 }
}
origin: org.sonatype.sisu/sisu-guava

@GuardedBy("lock")
private void waitInterruptibly(Guard guard, boolean signalBeforeWaiting)
  throws InterruptedException {
 if (!guard.isSatisfied()) {
  if (signalBeforeWaiting) {
   signalConditionsOfSatisfiedGuards(null);
  }
  incrementWaiters(guard);
  try {
   final Condition condition = guard.condition;
   do {
    try {
     condition.await();
    } catch (InterruptedException interrupt) {
     try {
      signalConditionsOfSatisfiedGuards(guard);
     } catch (Throwable throwable) {
      Thread.currentThread().interrupt();
      throw Throwables.propagate(throwable);
     }
     throw interrupt;
    }
   } while (!guard.isSatisfied());
  } finally {
   decrementWaiters(guard);
  }
 }
}
origin: org.sonatype.sisu/sisu-guava

@GuardedBy("lock")
private boolean waitInterruptibly(Guard guard, long remainingNanos, boolean signalBeforeWaiting)
  throws InterruptedException {
 if (!guard.isSatisfied()) {
  if (signalBeforeWaiting) {
   signalConditionsOfSatisfiedGuards(null);
  incrementWaiters(guard);
  try {
   final Condition condition = guard.condition;
     remainingNanos = condition.awaitNanos(remainingNanos);
    } catch (InterruptedException interrupt) {
     try {
      signalConditionsOfSatisfiedGuards(guard);
     } catch (Throwable throwable) {
      Thread.currentThread().interrupt();
   } while (!guard.isSatisfied());
  } finally {
   decrementWaiters(guard);
origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * Exactly like guard.isSatisfied(), but in addition signals all waiting threads in the
 * (hopefully unlikely) event that isSatisfied() throws.
 */
@GuardedBy("lock")
private boolean isSatisfied(Guard guard) {
 try {
  return guard.isSatisfied();
 } catch (Throwable throwable) {
  signalAllWaiters();
  throw Throwables.propagate(throwable);
 }
}
origin: google/guava

/**
 * Waits for the guard to be satisfied. Waits indefinitely. May be called only by a thread
 * currently occupying this monitor.
 */
public void waitForUninterruptibly(Guard guard) {
 if (!((guard.monitor == this) & lock.isHeldByCurrentThread())) {
  throw new IllegalMonitorStateException();
 }
 if (!guard.isSatisfied()) {
  awaitUninterruptibly(guard, true);
 }
}
origin: google/guava

/**
 * Waits for the guard to be satisfied. Waits indefinitely, but may be interrupted. May be called
 * only by a thread currently occupying this monitor.
 *
 * @throws InterruptedException if interrupted while waiting
 */
public void waitFor(Guard guard) throws InterruptedException {
 if (!((guard.monitor == this) & lock.isHeldByCurrentThread())) {
  throw new IllegalMonitorStateException();
 }
 if (!guard.isSatisfied()) {
  await(guard, true);
 }
}
origin: google/guava

/**
 * Enters this monitor when the guard is satisfied. Blocks indefinitely, but may be interrupted.
 *
 * @throws InterruptedException if interrupted while waiting
 */
public void enterWhen(Guard guard) throws InterruptedException {
 if (guard.monitor != this) {
  throw new IllegalMonitorStateException();
 }
 final ReentrantLock lock = this.lock;
 boolean signalBeforeWaiting = lock.isHeldByCurrentThread();
 lock.lockInterruptibly();
 boolean satisfied = false;
 try {
  if (!guard.isSatisfied()) {
   await(guard, signalBeforeWaiting);
  }
  satisfied = true;
 } finally {
  if (!satisfied) {
   leave();
  }
 }
}
origin: org.hudsonci.lib.guava/guava

@GuardedBy("lock")
private void waitUninterruptibly(Guard guard, boolean signalBeforeWaiting) {
 if (!guard.isSatisfied()) {
  if (signalBeforeWaiting) {
   signalConditionsOfSatisfiedGuards(null);
  }
  incrementWaiters(guard);
  try {
   final Condition condition = guard.condition;
   do {
    condition.awaitUninterruptibly();
   } while (!guard.isSatisfied());
  } finally {
   decrementWaiters(guard);
  }
 }
}
origin: google/guava

final long timeoutNanos = toSafeNanos(time, unit);
if (!((guard.monitor == this) & lock.isHeldByCurrentThread())) {
 throw new IllegalMonitorStateException();
if (guard.isSatisfied()) {
 return true;
final long startTime = initNanoTime(timeoutNanos);
boolean interrupted = Thread.interrupted();
try {
 for (long remainingNanos = timeoutNanos; ; ) {
  try {
   return awaitNanos(guard, remainingNanos, signalBeforeWaiting);
  } catch (InterruptedException interrupt) {
   interrupted = true;
   if (guard.isSatisfied()) {
    return true;
origin: google/guava

/**
 * Waits for the guard to be satisfied. Waits at most the given time, and may be interrupted. May
 * be called only by a thread currently occupying this monitor.
 *
 * @return whether the guard is now satisfied
 * @throws InterruptedException if interrupted while waiting
 */
@SuppressWarnings("GoodTime") // should accept a java.time.Duration
public boolean waitFor(Guard guard, long time, TimeUnit unit) throws InterruptedException {
 final long timeoutNanos = toSafeNanos(time, unit);
 if (!((guard.monitor == this) & lock.isHeldByCurrentThread())) {
  throw new IllegalMonitorStateException();
 }
 if (guard.isSatisfied()) {
  return true;
 }
 if (Thread.interrupted()) {
  throw new InterruptedException();
 }
 return awaitNanos(guard, timeoutNanos, true);
}
com.google.common.util.concurrentMonitor$Guard

Javadoc

A boolean condition for which a thread may wait. A Guard is associated with a single Monitor. The monitor may check the guard at arbitrary times from any thread occupying the monitor, so code should not be written to rely on how often a guard might or might not be checked.

If a Guard is passed into any method of a Monitor other than the one it is associated with, an IllegalMonitorStateException is thrown.

Most used methods

  • isSatisfied
    Evaluates this guard's boolean condition. This method is always called with the associated monitor a

Popular in Java

  • Start an intent from android
  • setContentView (Activity)
  • requestLocationUpdates (LocationManager)
  • notifyDataSetChanged (ArrayAdapter)
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Table (org.hibernate.mapping)
    A relational table
  • Top plugins for WebStorm
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