org.jboss.ejb.plugins.lock
Class BeanLockSupport

java.lang.Object
  extended byorg.jboss.ejb.plugins.lock.BeanLockSupport
All Implemented Interfaces:
BeanLock (src) , BeanLockExt (src) , Resource (src)
Direct Known Subclasses:
NoLock (src) , QueuedPessimisticEJBLock (src) , SimpleReadWriteEJBLock (src)

public abstract class BeanLockSupport
extends java.lang.Object
implements Resource (src) , BeanLockExt (src)

Support for the BeanLock


Field Summary
protected  Container (src) container
           
protected  java.lang.Object id
          The Cachekey corresponding to this Bean
protected  int refs
          Number of threads that retrieved this lock from the manager (0 means removing)
protected  java.lang.Thread synched
           
protected  int synchedDepth
           
protected  Transaction (src) tx
          Transaction holding lock on bean
protected  int txTimeout
           
 
Constructor Summary
BeanLockSupport()
           
 
Method Summary
 void addRef()
          Increment the reference count of this lock.
 boolean attemptSync()
          A non-blocking method that checks if the calling thread will be able to acquire the sync lock based on the calling thread.
abstract  void endInvocation(Invocation (src)  mi)
          Callback to the BeanLock to inform it that a method invocation has ended.
abstract  void endTransaction(Transaction (src)  tx)
          Informs the lock that the given transaction has ended.
 java.lang.Object getId()
          Get the bean instance cache id for the bean we are locking for.
 int getRefs()
          Get the current reference count of this lock.
 java.lang.Object getResourceHolder()
           
 Transaction (src) getTransaction()
          Get the transaction currently associated with this lock.
 void releaseSync()
          Release exclusive access to this lock instance.
 void removeRef()
          Decrement the reference count of this lock.
abstract  void schedule(Invocation (src)  mi)
          This method implements the actual logic of the lock.
 void setContainer(Container (src)  container)
          set the ejb container of this lock.
 void setId(java.lang.Object id)
          Set the bean instance cache id for the bean we are locking for.
 void setTimeout(int timeout)
          Change long we should wait for a lock.
 void setTransaction(Transaction (src)  tx)
          The setTransaction associates a transaction with the lock.
 void sync()
          A method that checks if the calling thread has the lock, and if it does not blocks until the lock is available.
abstract  void wontSynchronize(Transaction (src)  tx)
          Signifies to the lock that the transaction will not Synchronize (Tx demarcation not seen).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

container

protected Container (src)  container

refs

protected int refs
Number of threads that retrieved this lock from the manager (0 means removing)


id

protected java.lang.Object id
The Cachekey corresponding to this Bean


tx

protected Transaction (src)  tx
Transaction holding lock on bean


synched

protected java.lang.Thread synched

synchedDepth

protected int synchedDepth

txTimeout

protected int txTimeout
Constructor Detail

BeanLockSupport

public BeanLockSupport()
Method Detail

setId

public void setId(java.lang.Object id)
Description copied from interface: BeanLock (src)
Set the bean instance cache id for the bean we are locking for.

Specified by:
setId in interface BeanLock (src)
Parameters:
id - The cache key for the bean instance we are locking for.

getId

public java.lang.Object getId()
Description copied from interface: BeanLock (src)
Get the bean instance cache id for the bean we are locking for.

Specified by:
getId in interface BeanLock (src)
Returns:
The cache key for the bean instance we are locking for.

setTimeout

public void setTimeout(int timeout)
Description copied from interface: BeanLock (src)
Change long we should wait for a lock.

Specified by:
setTimeout in interface BeanLock (src)

setContainer

public void setContainer(Container (src)  container)
Description copied from interface: BeanLock (src)
set the ejb container of this lock.

Specified by:
setContainer in interface BeanLock (src)

getResourceHolder

public java.lang.Object getResourceHolder()
Specified by:
getResourceHolder in interface Resource (src)

attemptSync

public boolean attemptSync()
A non-blocking method that checks if the calling thread will be able to acquire the sync lock based on the calling thread.

Specified by:
attemptSync in interface BeanLockExt (src)
Returns:
true if the calling thread can obtain the sync lock in which case it will, false if another thread already has the lock.

sync

public void sync()
A method that checks if the calling thread has the lock, and if it does not blocks until the lock is available. If there is no current owner of the lock, or the calling thread already owns the lock then the calling thread will immeadiately acquire the lock.

Specified by:
sync in interface BeanLock (src)

releaseSync

public void releaseSync()
Description copied from interface: BeanLock (src)
Release exclusive access to this lock instance.

Specified by:
releaseSync in interface BeanLock (src)

schedule

public abstract void schedule(Invocation (src)  mi)
                       throws java.lang.Exception
Description copied from interface: BeanLock (src)
This method implements the actual logic of the lock. In the case of an EJB lock it must at least implement the serialization of calls

Specified by:
schedule in interface BeanLock (src)
Parameters:
mi - The method invocation that needs a lock.
Throws:
java.lang.Exception

setTransaction

public void setTransaction(Transaction (src)  tx)
The setTransaction associates a transaction with the lock. The current transaction is associated by the schedule call.

Specified by:
setTransaction in interface BeanLock (src)
Parameters:
tx - The transaction to associate with this lock.

getTransaction

public Transaction (src)  getTransaction()
Description copied from interface: BeanLock (src)
Get the transaction currently associated with this lock.

Specified by:
getTransaction in interface BeanLock (src)
Returns:
The transaction currently associated with this lock, or null if no transaction is currently associated with this lock.

endTransaction

public abstract void endTransaction(Transaction (src)  tx)
Description copied from interface: BeanLock (src)
Informs the lock that the given transaction has ended.

Specified by:
endTransaction in interface BeanLock (src)
Parameters:
tx - The transaction that has ended.

wontSynchronize

public abstract void wontSynchronize(Transaction (src)  tx)
Description copied from interface: BeanLock (src)
Signifies to the lock that the transaction will not Synchronize (Tx demarcation not seen).

OSH: This method does not seem to be called from anywhere. What is it meant for? To be called on a timeout before the transaction has terminated?

Specified by:
wontSynchronize in interface BeanLock (src)

endInvocation

public abstract void endInvocation(Invocation (src)  mi)
Description copied from interface: BeanLock (src)
Callback to the BeanLock to inform it that a method invocation has ended. A common use of this method is to release a method lock.

Specified by:
endInvocation in interface BeanLock (src)

addRef

public void addRef()
Description copied from interface: BeanLock (src)
Increment the reference count of this lock.

Specified by:
addRef in interface BeanLock (src)

removeRef

public void removeRef()
Description copied from interface: BeanLock (src)
Decrement the reference count of this lock.

Specified by:
removeRef in interface BeanLock (src)

getRefs

public int getRefs()
Description copied from interface: BeanLock (src)
Get the current reference count of this lock.

Specified by:
getRefs in interface BeanLock (src)
Returns:
The current reference count.