uPortal 2.4.1
API Documentation

org.jasig.portal.services
Class EntityLockService

java.lang.Object
  extended byorg.jasig.portal.services.EntityLockService

public class EntityLockService
extends java.lang.Object

This is a bootstrap class and facade for the IEntityLockService implementation. It presents a simple api for acquiring lock objects, IEntityLocks, that can be used to control concurrent access to portal entities in a multi-server environment. (See org.jasig.portal.concurrency.IEntityLockService for a fuller description.)

Currently supported lock types are IEntityLockService.READ_LOCK and IEntityLockService.WRITE_LOCK.

If I want to lock an entity for update, I ask the service for a write lock:

Class type = anEntity.getClass(); // maybe hard-coded(?)
String key = anEntity.getKey();
EntityIdentifier ei = new EntityIdentifier(key, type);
String owner = getThePortalUserId();
IEntityLock lock = EntityLockService.instance().newWriteLock(ei, owner);

Or maybe:

IEntityLock lock = EntityLockService.instance().newWriteLock(ei, owner, duration);

If there are no conflicting locks on the entity, the service returns the requested lock. If I acquire the lock, I know that no other client will be able to get a conflicting lock, and from then on, I communicate with the service via the lock:

lock.convert(int newType); // See IEntityLockService for types.
lock.isValid();
lock.release();
lock.renew();

A READ lock guarantees shared access; other clients can get READ locks but not WRITE locks. A WRITE lock guarantees exclusive access; no other clients can get either READ or WRITE locks on the entity.

Version:
$Revision: 1.8 $
Author:
Dan Ellentuck

Method Summary
static EntityLockService instance()
           
 IEntityLock newReadLock(java.lang.Class entityType, java.lang.String entityKey, java.lang.String owner)
          Returns a read lock for the entity type, entity key and owner.
 IEntityLock newReadLock(java.lang.Class entityType, java.lang.String entityKey, java.lang.String owner, int duration)
          Returns a read lock for the entity type, entity key and owner.
 IEntityLock newReadLock(EntityIdentifier entityID, java.lang.String owner)
          Returns a read lock for the IBasicEntity and owner.
 IEntityLock newReadLock(EntityIdentifier entityID, java.lang.String owner, int durationSecs)
          Returns a read lock for the IBasicEntity, owner and duration.
 IEntityLock newWriteLock(java.lang.Class entityType, java.lang.String entityKey, java.lang.String owner)
          Returns a write lock for the entity type, entity key and owner.
 IEntityLock newWriteLock(java.lang.Class entityType, java.lang.String entityKey, java.lang.String owner, int durationSecs)
          Returns a write lock for the entity type, entity key and owner.
 IEntityLock newWriteLock(EntityIdentifier entityID, java.lang.String owner)
          Returns a write lock for the IBasicEntity and owner.
 IEntityLock newWriteLock(EntityIdentifier entityID, java.lang.String owner, int durationSecs)
          Returns a write lock for the IBasicEntity, owner and duration.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static EntityLockService instance()
                                  throws LockingException
Throws:
LockingException

newReadLock

public IEntityLock newReadLock(java.lang.Class entityType,
                               java.lang.String entityKey,
                               java.lang.String owner)
                        throws LockingException
Returns a read lock for the entity type, entity key and owner.

Parameters:
entityType - Class
entityKey - String
owner - String
Returns:
org.jasig.portal.concurrency.locking.IEntityLock
Throws:
LockingException

newReadLock

public IEntityLock newReadLock(java.lang.Class entityType,
                               java.lang.String entityKey,
                               java.lang.String owner,
                               int duration)
                        throws LockingException
Returns a read lock for the entity type, entity key and owner.

Parameters:
entityType - Class
entityKey - String
owner - String
duration - int (in seconds)
Returns:
org.jasig.portal.concurrency.locking.IEntityLock
Throws:
LockingException

newReadLock

public IEntityLock newReadLock(EntityIdentifier entityID,
                               java.lang.String owner)
                        throws LockingException
Returns a read lock for the IBasicEntity and owner.

Parameters:
entityID - EntityIdentifier
owner - String
Returns:
org.jasig.portal.concurrency.locking.IEntityLock
Throws:
LockingException

newReadLock

public IEntityLock newReadLock(EntityIdentifier entityID,
                               java.lang.String owner,
                               int durationSecs)
                        throws LockingException
Returns a read lock for the IBasicEntity, owner and duration.

Parameters:
entityID - EntityIdentifier
owner - String
durationSecs - int
Returns:
org.jasig.portal.concurrency.locking.IEntityLock
Throws:
LockingException

newWriteLock

public IEntityLock newWriteLock(java.lang.Class entityType,
                                java.lang.String entityKey,
                                java.lang.String owner)
                         throws LockingException
Returns a write lock for the entity type, entity key and owner.

Parameters:
entityType - Class
entityKey - String
owner - String
Returns:
org.jasig.portal.concurrency.locking.IEntityLock
Throws:
LockingException

newWriteLock

public IEntityLock newWriteLock(java.lang.Class entityType,
                                java.lang.String entityKey,
                                java.lang.String owner,
                                int durationSecs)
                         throws LockingException
Returns a write lock for the entity type, entity key and owner.

Parameters:
entityType - Class
entityKey - String
owner - String
durationSecs - int
Returns:
org.jasig.portal.concurrency.locking.IEntityLock
Throws:
LockingException

newWriteLock

public IEntityLock newWriteLock(EntityIdentifier entityID,
                                java.lang.String owner)
                         throws LockingException
Returns a write lock for the IBasicEntity and owner.

Parameters:
entityID - EntityIdentifier
owner - String
Returns:
org.jasig.portal.concurrency.locking.IEntityLock
Throws:
LockingException

newWriteLock

public IEntityLock newWriteLock(EntityIdentifier entityID,
                                java.lang.String owner,
                                int durationSecs)
                         throws LockingException
Returns a write lock for the IBasicEntity, owner and duration.

Parameters:
entityID - EntityIdentifier
owner - String
durationSecs - int
Returns:
org.jasig.portal.concurrency.locking.IEntityLock
Throws:
LockingException

uPortal 2.4.1
API Documentation