org.jasig.cas.ticket.registry.support
Class JpaLockingStrategy

java.lang.Object
  extended by org.jasig.cas.ticket.registry.support.JpaLockingStrategy
All Implemented Interfaces:
LockingStrategy

public class JpaLockingStrategy
extends Object
implements LockingStrategy

JPA 2.0 implementation of an exclusive, non-reintrant lock.

Version:
$Revision: $
Author:
Marvin S. Addison

Nested Class Summary
static class JpaLockingStrategy.Lock
          Describes a database lock.
 
Field Summary
static int DEFAULT_LOCK_TIMEOUT
          Default lock timeout is 1 hour.
protected  javax.persistence.EntityManager entityManager
          Transactional entity manager from Spring context.
 
Constructor Summary
JpaLockingStrategy()
           
 
Method Summary
 boolean acquire()
          Attempt to acquire the lock.
 String getOwner()
          Gets the current owner of the lock as determined by querying for uniqueId.
 void release()
          Release the lock if held.
 void setApplicationId(String id)
           
 void setLockTimeout(int seconds)
           
 void setUniqueId(String id)
           
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_LOCK_TIMEOUT

public static final int DEFAULT_LOCK_TIMEOUT
Default lock timeout is 1 hour.

See Also:
Constant Field Values

entityManager

@NotNull
protected javax.persistence.EntityManager entityManager
Transactional entity manager from Spring context.

Constructor Detail

JpaLockingStrategy

public JpaLockingStrategy()
Method Detail

setApplicationId

public void setApplicationId(String id)
Parameters:
id - Application identifier that identifies a row in the lock table for which multiple clients vie to hold the lock. This must be the same for all clients contending for a particular lock.

setUniqueId

public void setUniqueId(String id)
Parameters:
id - Identifier used to identify this instance in a row of the lock table. Must be unique across all clients vying for locks for a given application ID.

setLockTimeout

public void setLockTimeout(int seconds)
Parameters:
seconds - Maximum amount of time in seconds lock may be held. A value of zero indicates that locks are held indefinitely. Use of a reasonable timeout facilitates recovery from node failures, so setting to zero is discouraged.

acquire

@Transactional(readOnly=false)
public boolean acquire()
Attempt to acquire the lock.

Specified by:
acquire in interface LockingStrategy
Returns:
True if lock was successfully acquired, false otherwise.

release

@Transactional(readOnly=false)
public void release()
Release the lock if held. If the lock is not held nothing is done.

Specified by:
release in interface LockingStrategy

getOwner

@Transactional(readOnly=true)
public String getOwner()
Gets the current owner of the lock as determined by querying for uniqueId.

Returns:
Current lock owner or null if no one presently owns lock.

toString

public String toString()

Overrides:
toString in class Object


Copyright © 2004-2013 Jasig. All Rights Reserved.