org.objectweb.jonas_ejb.container
Class JEntitySwitch

java.lang.Object
  extended byorg.objectweb.jonas_ejb.container.JEntitySwitch
Direct Known Subclasses:
JEntitySwitchCRC, JEntitySwitchCRU, JEntitySwitchCS, JEntitySwitchDB

public abstract class JEntitySwitch
extends java.lang.Object

JEntitySwitch is used internally to synchronize accesses to the entity context and thus to the entity bean instance. All parts common to EJBObject and EJBLocalObject should be here. Different policies can be applied to manage context/instance pairs: - only 1 pair (container manages the transaction isolation) - 1 pair for each transaction (transaction isolation managed by DataBase) - 2 pairs (1 for transactional accesses, 1 for non transaction accesses)

Author:
Philippe Durieux, Philippe Coq

Field Summary
protected  JEntityFactory bf
          The Factory for this bean
protected  javax.transaction.Transaction blockedtx
          last transaction blocked by synchronization.
protected static int counter
           
protected  int countIH
          nb of non transacted requests running
protected  boolean discarded
          True when context/instance has been discarded, to avoids that passivate store its state on storage Meaningful only outside tx
protected  java.lang.String ident
           
protected  boolean inDirtyList
          True if this instance may have been modified outside transactions.
protected  boolean isremoved
           
protected  boolean lazyregister
          true if we can differ the registration at first write.
protected  JEntityLocal local
          The EJBLocalObject, or null if bean has no local interface.
protected  int lockpolicy
          Lock policy used for this entity bean.
protected  boolean mustReload
          True if instance has been modified by a Transaction.
protected  javax.ejb.TimerService myTimerService
          The Timer Service
protected  java.lang.Object pk
          The Primary Key for this bean instance.
protected  JEntityRemote remote
          The EJBObject, or null if bean has no remote interface.
protected  javax.transaction.Transaction runningtx
           
protected  boolean shared
          shared=true if the bean can be modify outside this container.
protected  boolean txUpdates
          True if a transaction is mandatory for all modifying methods.
protected  int waiters
          nb of threads waiting (synchronization)
protected  javax.transaction.Transaction writingtx
           
 
Constructor Summary
JEntitySwitch()
          empty constructor.
 
Method Summary
 void bindICtx(javax.transaction.Transaction tx, JEntityContext bctx)
          bind a JEntityContext for a create method.
 void discardICtx(javax.transaction.Transaction tx)
          Discard a context/instance at end of request.
abstract  void endIH()
           
 JFactory getBeanFactory()
           
 javax.transaction.Transaction getBlockedTx()
           
 javax.transaction.Transaction getBlockingTx()
           
 javax.ejb.TimerService getEntityTimerService()
          Obtains the TimerService associated for this Entity Bean (one / pk)
 JEntityContext getICtx(javax.transaction.Transaction tx)
          Get a context/instance associated with this transaction Called at each request on the bean (including remove)
 JEntityContext getICtx(javax.transaction.Transaction tx, JEntityContext newctx)
          bind a JEntityContext for a remove method.
 JEntityLocal getLocal()
           
 int getPolicy()
           
 java.lang.Object getPrimaryKey()
           
 JEntityRemote getRemote()
           
abstract  int getState()
           
 void init(JEntityFactory bf, java.lang.Object pk)
          constructor.
protected abstract  void initpolicy(JEntityFactory bf)
           
 JEntityContext mapICtx(javax.transaction.Transaction tx, JEntityContext bctx, boolean forced, boolean holdit)
          Map a context and its instance.
protected  void noLongerUsed()
          Remove this EJB and UnExport the remote object.
 void notifyTimeout(javax.ejb.Timer timer)
          Notify a timeout for this bean and this Pk
abstract  void notifyWriting(javax.transaction.Transaction tx, JEntityContext bctx)
           
abstract  boolean passivateIH(boolean passivation)
           
protected  void registerCtx(javax.transaction.Transaction tx, JEntityContext bctx)
          register a Context on the transaction, as a Synchronization.
abstract  void releaseICtx(javax.transaction.Transaction tx)
           
 boolean terminate(javax.transaction.Transaction tx)
          Release completely this object, since another one will be used.
 boolean tryBindICtx(javax.transaction.Transaction tx, JEntityContext bctx)
          Try to bind a JEntityContext if none already bound.
 void txCompleted(javax.transaction.Transaction tx, boolean committed)
          This transaction is now over.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bf

protected JEntityFactory bf
The Factory for this bean


pk

protected java.lang.Object pk
The Primary Key for this bean instance.


local

protected JEntityLocal local
The EJBLocalObject, or null if bean has no local interface.


remote

protected JEntityRemote remote
The EJBObject, or null if bean has no remote interface.


shared

protected boolean shared
shared=true if the bean can be modify outside this container.


lockpolicy

protected int lockpolicy
Lock policy used for this entity bean. Possible values are 0 = LOCK_CONTAINER_READ_UNCOMMITTED (1 instance) 1 = LOCK_CONTAINER_SERIALIZED (1 instance) 2 = LOCK_CONTAINER_READ_COMMITTED (2 instances) 3 = LOCK_DATABASE (n instances)


txUpdates

protected boolean txUpdates
True if a transaction is mandatory for all modifying methods. In this case, all methods outside tranction is considered as read-only.


myTimerService

protected javax.ejb.TimerService myTimerService
The Timer Service


countIH

protected int countIH
nb of non transacted requests running


waiters

protected int waiters
nb of threads waiting (synchronization)


inDirtyList

protected boolean inDirtyList
True if this instance may have been modified outside transactions. Avoids to put it twice in dirty list.


mustReload

protected boolean mustReload
True if instance has been modified by a Transaction. This means that reading outside transaction should reload it before use. Always false for policies CS and CRU (only 1 instance)


discarded

protected boolean discarded
True when context/instance has been discarded, to avoids that passivate store its state on storage Meaningful only outside tx


runningtx

protected javax.transaction.Transaction runningtx

writingtx

protected javax.transaction.Transaction writingtx

blockedtx

protected javax.transaction.Transaction blockedtx
last transaction blocked by synchronization. this is to do a very basic deadlock detection.


isremoved

protected boolean isremoved

counter

protected static int counter

ident

protected java.lang.String ident

lazyregister

protected boolean lazyregister
true if we can differ the registration at first write.

Constructor Detail

JEntitySwitch

public JEntitySwitch()
empty constructor. Object is initialized via init() because it is implemented differently according to jorm mappers.

Method Detail

initpolicy

protected abstract void initpolicy(JEntityFactory bf)

passivateIH

public abstract boolean passivateIH(boolean passivation)

endIH

public abstract void endIH()

notifyWriting

public abstract void notifyWriting(javax.transaction.Transaction tx,
                                   JEntityContext bctx)

releaseICtx

public abstract void releaseICtx(javax.transaction.Transaction tx)

init

public void init(JEntityFactory bf,
                 java.lang.Object pk)
constructor. A new object is build when a new PK is known in the container, either when a new bean is created, or when a find occurs. For create(), PK is not known yet when this object is build.

Parameters:
bf - The Entity Factory
pk - The Primary Key

getLocal

public JEntityLocal getLocal()
Returns:
the underlaying EJBLocalObject

getRemote

public JEntityRemote getRemote()
Returns:
the underlaying EJBObject

getEntityTimerService

public javax.ejb.TimerService getEntityTimerService()
Obtains the TimerService associated for this Entity Bean (one / pk)

Returns:
a JTimerService instance.

notifyTimeout

public void notifyTimeout(javax.ejb.Timer timer)
Notify a timeout for this bean and this Pk

Parameters:
timer - timer whose expiration caused this notification.

getPrimaryKey

public java.lang.Object getPrimaryKey()
Returns:
the Primary Key Object for this instance.

bindICtx

public void bindICtx(javax.transaction.Transaction tx,
                     JEntityContext bctx)
bind a JEntityContext for a create method.

Parameters:
tx - - the Transaction object
bctx - - the JEntityContext to bind

tryBindICtx

public boolean tryBindICtx(javax.transaction.Transaction tx,
                           JEntityContext bctx)
                    throws javax.ejb.ObjectNotFoundException
Try to bind a JEntityContext if none already bound. Called by finder methods

Parameters:
tx - - the Transaction object
bctx - The Entity Context
Returns:
true if context has been bound to this EntitySwitch.
Throws:
javax.ejb.ObjectNotFoundException

getICtx

public JEntityContext getICtx(javax.transaction.Transaction tx,
                              JEntityContext newctx)
bind a JEntityContext for a remove method. called in case of remove(pk) or remove(handle)

Parameters:
tx - - the Transaction object
newctx - - the JEntityContext to bind
Returns:
the BeanContext

getICtx

public JEntityContext getICtx(javax.transaction.Transaction tx)
Get a context/instance associated with this transaction Called at each request on the bean (including remove)

Parameters:
tx - - the Transaction object
Returns:
the BeanContext

terminate

public boolean terminate(javax.transaction.Transaction tx)
Release completely this object, since another one will be used. this occurs in case of create, when another EntitySwitch exist already.

Parameters:
tx - - the Transaction object

mapICtx

public JEntityContext mapICtx(javax.transaction.Transaction tx,
                              JEntityContext bctx,
                              boolean forced,
                              boolean holdit)
Map a context and its instance.

Parameters:
tx - - the Transaction object
bctx - - the JEntityContext to bind if not null
forced - - force to take this context. (case of create)
holdit - - increment count to hold it, a release will be called later.
Returns:
JEntityContext actually mapped

getBlockedTx

public javax.transaction.Transaction getBlockedTx()

getBlockingTx

public javax.transaction.Transaction getBlockingTx()

discardICtx

public void discardICtx(javax.transaction.Transaction tx)
Discard a context/instance at end of request. A problem occured on this insance and it must be discarded.

Parameters:
tx - - transaction associated to this context

txCompleted

public void txCompleted(javax.transaction.Transaction tx,
                        boolean committed)
This transaction is now over. We can dispose of the instance for another transaction or discard it.

Parameters:
tx - the transaction object
committed - true if transaction was committed.

noLongerUsed

protected void noLongerUsed()
Remove this EJB and UnExport the remote object.


registerCtx

protected void registerCtx(javax.transaction.Transaction tx,
                           JEntityContext bctx)
register a Context on the transaction, as a Synchronization. this will be used later to store instance state when needed : before a finder, or at beforeCompletion, and to release instance at commit.

Parameters:
tx - Transaction object
bctx - The Context to be registered

getPolicy

public int getPolicy()
Returns:
lock policy for this bean

getState

public abstract int getState()
Returns:
State of this instance. State values are 0=in-tx, 1=out-tx, 2=idle, 3=passive, 4=removed. we don't synchronize this method to avoid jadmin blocks

getBeanFactory

public JFactory getBeanFactory()
Returns:
the JFactory