org.garret.jipc
Interface JIPCLock

All Superinterfaces:
JIPCPrimitive

public interface JIPCLock
extends JIPCPrimitive

Synchronization object for setting exlusive and shared locks. Locks are not nested - if session sets the same lock several time, all lock requests are succeed but single unlock request will unlock the object. It is possible to upgrade the lock: if session first lock object in shared mode and then in exclusive mode, lock will be upgraded to exclusive (Attention! upgrading locks can easily cause a deadlock if several session will try to upgrade their shared locks simultaneously).
It is not possible to downgrade the lock - locking of object in shared mode after granted exlusive lock has no effect.
Locks are granted in FIFO order - it means that if object is locked shared mode, then request for exclusive lock comes and is blocked and then if yet another request for shared lock is received, it will be also blocked and placed inqueue after excusive lock request. Server is able to detect deadlock for this primitive.

Semantic of methods inherited from JIPCPrimitive:

waitFor
set exlusive lock
reset
removes all locks (shared or exclusive). It is not required that session, invoking reset method be owner of this lock


Field Summary
 
Fields inherited from interface org.garret.jipc.JIPCPrimitive
DEFAULT_RANK
 
Method Summary
 void exclusiveLock()
          Set exlusive lock.
 boolean exclusiveLock(long timeout)
          Set exclusive lock with timeout.
 void priorityExclusiveLock(int rank)
          Set exlusive lock.
 boolean priorityExclusiveLock(int rank, long timeout)
          Set exclusive lock with timeout.
 void prioritySharedLock(int rank)
          Set shared lock.
 boolean prioritySharedLock(int rank, long timeout)
          Set shared lock with timeout.
 void sharedLock()
          Set shared lock.
 boolean sharedLock(long timeout)
          Set shared lock with timeout.
 void unlock()
          Remove lock from the object
 
Methods inherited from interface org.garret.jipc.JIPCPrimitive
alreadyExists, close, getName, priorityWait, priorityWait, reset, waitFor, waitFor
 

Method Detail

exclusiveLock

public void exclusiveLock()
                   throws JIPCException,
                          java.io.IOException
Set exlusive lock. No other session can set exclusive or shared lock.

JIPCException
java.io.IOException

exclusiveLock

public boolean exclusiveLock(long timeout)
                      throws JIPCException,
                             java.io.IOException
Set exclusive lock with timeout. If lock can not be graned within specifed time, request is failed.

Parameters:
timeout - time in milliseconds
Returns:
true if lock is granted, false of timeout is expired
JIPCException
java.io.IOException

priorityExclusiveLock

public void priorityExclusiveLock(int rank)
                           throws JIPCException,
                                  java.io.IOException
Set exlusive lock. No other session can set exclusive or shared lock.

Parameters:
rank - processes will be placed in wait queue in the order of increasing rank value and in the same order will be taken from the queue.
JIPCException
java.io.IOException

priorityExclusiveLock

public boolean priorityExclusiveLock(int rank,
                                     long timeout)
                              throws JIPCException,
                                     java.io.IOException
Set exclusive lock with timeout. If lock can not be graned within specifed time, request is failed.

Parameters:
rank - processes will be placed in wait queue in the order of increasing rank value and in the same order will be taken from the queue.
timeout - time in milliseconds
Returns:
true if lock is granted, false of timeout is expired
JIPCException
java.io.IOException

prioritySharedLock

public void prioritySharedLock(int rank)
                        throws JIPCException,
                               java.io.IOException
Set shared lock. No other session can set exclusive lock but other shared locks are possible.

Parameters:
rank - processes will be placed in wait queue in the order of increasing rank value and in the same order will be taken from the queue.
JIPCException
java.io.IOException

prioritySharedLock

public boolean prioritySharedLock(int rank,
                                  long timeout)
                           throws JIPCException,
                                  java.io.IOException
Set shared lock with timeout. If lock can not be graned within specifed time, request is failed.

Parameters:
rank - processes will be placed in wait queue in the order of increasing rank value and in the same order will be taken from the queue.
timeout - time in milliseconds
Returns:
true if lock is granted, false of timeout is expired
JIPCException
java.io.IOException

sharedLock

public void sharedLock()
                throws JIPCException,
                       java.io.IOException
Set shared lock. No other session can set exclusive lock but other shared locks are possible.

JIPCException
java.io.IOException

sharedLock

public boolean sharedLock(long timeout)
                   throws JIPCException,
                          java.io.IOException
Set shared lock with timeout. If lock can not be graned within specifed time, request is failed.

Parameters:
timeout - time in milliseconds
Returns:
true if lock is granted, false of timeout is expired
JIPCException
java.io.IOException

unlock

public void unlock()
            throws JIPCException,
                   java.io.IOException
Remove lock from the object

JIPCException
java.io.IOException