Interface StateLock

All Known Implementing Classes:
EventStateHandler, JobStateHandler, ParentStateHandler, ServiceStateHandler, StateHandler, TimerStateHandler

public interface StateLock
A mechanism for allowing actions to be performed synchronously with respect to state change.
Author:
rob
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    callLocked(Callable<T> callable)
    Wait to acquire the lock and execute the Callable while holding the lock.
    void
    runLocked(Runnable runnable)
    Wait to acquire the lock and execute the Runnable while holding the lock.
    <T> T
    supplyLocked(Supplier<T> supplier)
    Wait to acquire the lock and execute the Supplier while holding the lock.
    boolean
    Try to acquire the lock, and then do something when the condition is true.
    boolean
    Wait to do something when the condition is true.
  • Method Details

    • tryToWhen

      boolean tryToWhen(StateCondition when, Runnable runnable) throws OddjobLockedException
      Try to acquire the lock, and then do something when the condition is true. Both the condition evaluation and the performing of the action are done in the context of the same state lock. If the lock can not be acquired an OddjobLockedException is thrown.
      Parameters:
      when - The condition.
      runnable - The action.
      Returns:
      true if the condition was true and the action executed. False otherwise.
      Throws:
      OddjobLockedException - If the lock can not be acquired.
    • waitToWhen

      boolean waitToWhen(StateCondition when, Runnable runnable)
      Wait to do something when the condition is true. Both the condition evaluation and the performing of the action are done in the context of the same state lock. If the lock can not be acquired then the lock is waited for.
      Parameters:
      when - The condition.
      runnable - The action.
      Returns:
      true if the condition was true and the action executed.
    • runLocked

      void runLocked(Runnable runnable)
      Wait to acquire the lock and execute the Runnable while holding the lock.
      Parameters:
      runnable - The Runnable.
    • callLocked

      <T> T callLocked(Callable<T> callable) throws Exception
      Wait to acquire the lock and execute the Callable while holding the lock.
      Parameters:
      callable - The callable.
      Returns:
      The result of the callable.
      Throws:
      Exception - from the callable.
    • supplyLocked

      <T> T supplyLocked(Supplier<T> supplier)
      Wait to acquire the lock and execute the Supplier while holding the lock.
      Parameters:
      supplier - The Supplier.
      Returns:
      The result from the Supplier.