com.kuka.resource.locking
Interface ILockable


public interface ILockable

Interface describing a resource that can be locked by a task.


Method Summary
 void addLockListener(ILockListener listener)
          Add a listener to be notified of locking state changes of the resource.
 LockPriority getLockPriority()
          Provides the priority of the task holding the lock.
 boolean isLocked()
          Checks whether the resource is locked by any task.
 void lock()
          Obtains the exclusive lock on this resource.
 boolean ownsLock()
          Checks whether the calling task (thread group) holds this lock.
 void removeLockListener(ILockListener listener)
          Removes a previously registered locking state listener.
 void unlock()
          Releases the lock if the calling task (thread group) owns it.
 

Method Detail

lock

void lock()
          throws LockException,
                 InterruptedException
Obtains the exclusive lock on this resource.

Locking task is identified by its thread group. Once locked, no other task can obtain the lock. A task with higher priority can force the lock by calling #forceLock().

This function call blocks until the lock is successful or timeout expires.

Keep in mind to release the lock with unlock() once the lock is not needed anymore.

Throws:
LockTimeoutException - if the locking attempt timed out.
ResourceAlreadyLockedException - if the resource is already locked by another task.
LockException - if locking failed for some reason.
InterruptedException - if the thread was interrupted while waiting for the lock.

unlock

void unlock()
Releases the lock if the calling task (thread group) owns it. Otherwise the method returns without any changes.

Only the task (thread group) that holds the lock can unlock the resource.

Unlocking might not be completed yet on method return, but any following lock() or #forceLock() on this resource will wait for the unlock to complete.


isLocked

boolean isLocked()
Checks whether the resource is locked by any task.

If it is of interest if the resource is locked by the calling task, please use the ownsLock().

Returns:
true if resource is locked; otherwise false.

ownsLock

boolean ownsLock()
Checks whether the calling task (thread group) holds this lock.

Returns:
true if calling task (thread group) holds this lock; otherwise false.

getLockPriority

LockPriority getLockPriority()
Provides the priority of the task holding the lock.

Returns:
the priority of the task holding the lock, or -1, if the resource is not locked.

addLockListener

void addLockListener(ILockListener listener)
Add a listener to be notified of locking state changes of the resource.

Parameters:
listener - The listener to call.

removeLockListener

void removeLockListener(ILockListener listener)
Removes a previously registered locking state listener.

Parameters:
listener - The listener to remove.


Copyright © 2019. All rights reserved.