Class ActionResourceLock

java.lang.Object
edu.tufts.hrilab.action.lock.ActionResourceLock
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ActionResourceLockLinear, ActionResourceLockPreempt

public abstract class ActionResourceLock extends Object implements Serializable
ActionResourceLock is the base class for Action's resource locks.
See Also:
  • Field Details

  • Constructor Details

    • ActionResourceLock

      public ActionResourceLock(String name)
      Constructor for a resource lock.
      Parameters:
      name - the lock's name
  • Method Details

    • getLock

      public static ActionResourceLock getLock(String lockName)
      Get a resource lock.
      Parameters:
      lockName - the name of the lock to get
      Returns:
      the lock
    • acquire

      public abstract boolean acquire(ActionInterpreter actionInt, int count)
      Must be implemented by subclass.
    • getLockName

      public String getLockName()
    • blockingAcquire

      public boolean blockingAcquire(ActionInterpreter actionInt)
      Acquire the resource lock, waiting indefinitely for it to become available.
      Parameters:
      actionInt - the ActionInterpreter requesting the lock
      Returns:
      true if the lock is acquired
    • nonBlockingAcquire

      public boolean nonBlockingAcquire(ActionInterpreter actionInt)
      Attempt to acquire the resource lock, but do not block if it is unavailable.
      Parameters:
      actionInt - the ActionInterpreter requesting the lock
      Returns:
      true if the lock is acquired, false otherwise
    • release

      public void release(ActionInterpreter actionInt)
      Release the resource lock, ensuring that the current AI is the current holder. This version releases only one level of recursive acquire; if an enclosing script also acquired the lock, actionInt will still hold it.
      Parameters:
      actionInt - the ActionInterpreter releasing the lock
    • deepRelease

      public void deepRelease(ActionInterpreter actionInt)
      Release the resource lock, ensuring that the current AI is the current holder. This version ensures the lock will be released, regardless of how many recursive acquires the owner has made.
      Parameters:
      actionInt - the ActionInterpreter releasing the lock
    • getOwner

      public ActionInterpreter getOwner()
      Get the interpreter currently holding the lock.
      Returns:
      the owner
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • deepReleaseAll

      public static void deepReleaseAll(ActionInterpreter ai)