Package com.sun.enterprise.transaction
Class JavaEETransactionManagerSimplified
- java.lang.Object
-
- com.sun.enterprise.transaction.JavaEETransactionManagerSimplified
-
- All Implemented Interfaces:
JavaEETransactionManager
,jakarta.transaction.TransactionManager
,org.glassfish.hk2.api.PostConstruct
@Service @ContractsProvided({jakarta.transaction.TransactionManager.class,JavaEETransactionManager.class}) @Rank(50) public class JavaEETransactionManagerSimplified extends Object implements JavaEETransactionManager, org.glassfish.hk2.api.PostConstruct
Implementation of jakarta.transaction.TransactionManager interface. This class provides non-XA local transaction support and delegates to implementation of the JavaEETransactionManagerDelegate for XA or LAO optimization, and complete JTS implementation.- Author:
- Tony Ng, Marina Vatkina
-
-
Field Summary
Fields Modifier and Type Field Description protected Logger
_logger
protected InvocationManager
invMgr
-
Constructor Summary
Constructors Constructor Description JavaEETransactionManagerSimplified()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
begin()
void
begin(int timeout)
This method is introduced as part of implementing the local transaction timeout capability.void
checkTransactionExport(boolean isLocal)
Called from the CORBA Interceptors on the client-side when a client makes a call to a remote object (not in the same JVM).void
checkTransactionImport()
Called from the CORBA Interceptors on the server-side when the server is replying to the client (local + remote client).void
cleanTxnTimeout()
void
clearThreadTx()
Clears the transaction associated with the caller threadvoid
commit()
void
componentDestroyed(Object instance)
This is called by Container to indicate that a component is being destroyed.void
componentDestroyed(Object instance, ComponentInvocation inv)
This is called by Container to indicate that a component is being destroyed.void
componentDestroyed(ResourceHandler rh)
This is called by Container to indicate that a component is being destroyed.JavaEETransaction
createImportedTransaction(TransactionInternal jtsTx)
void
delistComponentResources(boolean suspend)
This is called by the Container to ask the Transaction Manager to delist all resources held by a component The TM finds the component through the InvocationManagerboolean
delistResource(jakarta.transaction.Transaction tran, TransactionalResource h, int flag)
Delist the resource specified from the transactionvoid
enlistComponentResources()
This is called by the Container to ask the Transaction Manager to enlist all resources held by a component and to associate the current Transaction with the current Invocation The TM finds the component through the InvocationManagerboolean
enlistResource(jakarta.transaction.Transaction tran, TransactionalResource h)
Enlist the resource specified with the transactionprotected boolean
enlistXAResource(jakarta.transaction.Transaction tran, TransactionalResource h)
void
forceRollback(String txnId)
void
freeze()
ArrayList
getActiveTransactions()
JavaEETransaction
getCurrentTransaction()
Return JavaEETransaction instance associated with the current thread.int
getEffectiveTimeout()
List
getExistingResourceList(Object instance, ComponentInvocation inv)
Returns a list of resource handles held by the componentLogger
getLogger()
int
getPurgeCancelledTtransactionsAfter()
Returns the value to be used to purge transaction tasks after the specified number of cancelled tasks.List
getResourceList(Object instance, ComponentInvocation inv)
get the resources being used in the calling component's invocation contextint
getStatus()
static String
getStatusAsString(int status)
jakarta.transaction.Transaction
getTransaction()
TransactionAdminBean
getTransactionAdminBean(jakarta.transaction.Transaction tran)
String
getTxLogLocation()
Return location of transaction logsXAResourceWrapper
getXAResourceWrapper(String clName)
Return XAResourceWrapper instance specific to this datasource class name that can be used instead of the driver provided version for transaction recovery.jakarta.resource.spi.XATerminator
getXATerminator()
This is used by importing transactions via the Connector contract.void
handlePropertyUpdate(String name, Object value)
Handle configuration change.void
initRecovery(boolean force)
Initialize recovery frameworkboolean
isDelegate(JavaEETransactionManagerDelegate d)
boolean
isFrozen()
XXX ???boolean
isInvocationStackEmpty()
boolean
isNullTransaction()
Return true if a "null transaction context" was received from the client.boolean
isTimedOut()
Utility for the ejb container to check if the transaction is marked for rollback because of timeout.void
monitorTxBegin(jakarta.transaction.Transaction tx)
void
monitorTxCompleted(Object obj, boolean b)
void
postConstruct()
void
postInvoke(ComponentInvocation curr, ComponentInvocation prev)
Called by InvocationManagervoid
preInvoke(ComponentInvocation prev)
Called by InvocationManagervoid
recover(XAResource[] resourceList)
boolean
recoverIncompleteTx(boolean delegated, String logPath, XAResource[] xaresArray)
Called by the ResourceRecoveryManager to recover the populated array of XAResource.void
recreate(Xid xid, long timeout)
Recreate a transaction based on the Xid.void
registerComponentResource(TransactionalResource h)
void
registerRecoveryResourceHandler(XAResource xaResource)
Allows an arbitrary XAResource to register for recoveryvoid
registerSynchronization(jakarta.transaction.Synchronization sync)
register a synchronization object with the transaction associated with the current threadvoid
release(Xid xid)
Release a transaction.boolean
resourceEnlistable(TransactionalResource h)
void
resume(jakarta.transaction.Transaction tobj)
void
rollback()
void
setCurrentTransaction(JavaEETransaction t)
Update JavaEETransaction associated with the current thread.void
setDefaultTransactionTimeout(int seconds)
void
setDelegate(JavaEETransactionManagerDelegate d)
Explicitly set the JavaEETransactionManagerDelegate instance for implementation-specific callbacks.void
setMonitoringEnabled(boolean enabled)
void
setPurgeCancelledTtransactionsAfter(int num)
Modify the value to be used to purge transaction tasks after the specified number of cancelled tasks.void
setRollbackOnly()
void
setTransactionCompeting(boolean b)
void
setTransactionTimeout(int seconds)
Modify the value of the timeout value that is associated with the transactions started by the current thread with the begin method.void
shutdown()
Perform shutdown cleanup.void
startJTSTx(JavaEETransaction t)
jakarta.transaction.Transaction
suspend()
void
unfreeze()
void
unregisterComponentResource(TransactionalResource h)
-
-
-
Field Detail
-
_logger
protected Logger _logger
-
invMgr
@Inject protected InvocationManager invMgr
-
-
Method Detail
-
postConstruct
public void postConstruct()
- Specified by:
postConstruct
in interfaceorg.glassfish.hk2.api.PostConstruct
-
clearThreadTx
public void clearThreadTx()
Clears the transaction associated with the caller thread- Specified by:
clearThreadTx
in interfaceJavaEETransactionManager
-
getTxLogLocation
public String getTxLogLocation()
Return location of transaction logs- Specified by:
getTxLogLocation
in interfaceJavaEETransactionManager
- Returns:
- String location of transaction logs
-
registerRecoveryResourceHandler
public void registerRecoveryResourceHandler(XAResource xaResource)
Allows an arbitrary XAResource to register for recovery- Specified by:
registerRecoveryResourceHandler
in interfaceJavaEETransactionManager
- Parameters:
xaResource
- XAResource to register for recovery
-
isNullTransaction
public boolean isNullTransaction()
Return true if a "null transaction context" was received from the client. See EJB2.0 spec section 19.6.2.1. A null tx context has no Coordinator objref. It indicates that the client had an active tx but the client container did not support tx interop.- Specified by:
isNullTransaction
in interfaceJavaEETransactionManager
-
shutdown
public void shutdown()
Description copied from interface:JavaEETransactionManager
Perform shutdown cleanup.- Specified by:
shutdown
in interfaceJavaEETransactionManager
-
initRecovery
public void initRecovery(boolean force)
Description copied from interface:JavaEETransactionManager
Initialize recovery framework- Specified by:
initRecovery
in interfaceJavaEETransactionManager
- Parameters:
force
- if true, forces initialization, otherwise relies on the TimerService configuration.
-
recover
public void recover(XAResource[] resourceList)
- Specified by:
recover
in interfaceJavaEETransactionManager
-
enlistResource
public boolean enlistResource(jakarta.transaction.Transaction tran, TransactionalResource h) throws jakarta.transaction.RollbackException, IllegalStateException, jakarta.transaction.SystemException
Description copied from interface:JavaEETransactionManager
Enlist the resource specified with the transaction- Specified by:
enlistResource
in interfaceJavaEETransactionManager
- Parameters:
tran
- The transaction objecth
- The resource handle object- Returns:
- true if the resource was enlisted successfully; otherwise * false.
- Throws:
jakarta.transaction.RollbackException
- Thrown to indicate that the transaction has been marked for rollback only.IllegalStateException
- Thrown if the transaction in the target object is in prepared state or the transaction is inactive.jakarta.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition
-
unregisterComponentResource
public void unregisterComponentResource(TransactionalResource h)
- Specified by:
unregisterComponentResource
in interfaceJavaEETransactionManager
-
startJTSTx
public void startJTSTx(JavaEETransaction t) throws jakarta.transaction.RollbackException, IllegalStateException, jakarta.transaction.SystemException
- Throws:
jakarta.transaction.RollbackException
IllegalStateException
jakarta.transaction.SystemException
-
getResourceList
public List getResourceList(Object instance, ComponentInvocation inv)
get the resources being used in the calling component's invocation context- Specified by:
getResourceList
in interfaceJavaEETransactionManager
- Parameters:
instance
- Calling component instanceinv
- Calling component's invocation information- Returns:
- List of resources
-
enlistComponentResources
public void enlistComponentResources() throws RemoteException
Description copied from interface:JavaEETransactionManager
This is called by the Container to ask the Transaction Manager to enlist all resources held by a component and to associate the current Transaction with the current Invocation The TM finds the component through the InvocationManager- Specified by:
enlistComponentResources
in interfaceJavaEETransactionManager
- Throws:
RemoteException
-
delistResource
public boolean delistResource(jakarta.transaction.Transaction tran, TransactionalResource h, int flag) throws IllegalStateException, jakarta.transaction.SystemException
Description copied from interface:JavaEETransactionManager
Delist the resource specified from the transaction- Specified by:
delistResource
in interfaceJavaEETransactionManager
- Parameters:
tran
- The transaction objecth
- The resource handle objectflag
- One of the values of TMSUCCESS, TMSUSPEND, or TMFAIL.- Throws:
IllegalStateException
- Thrown if the transaction in the target object is inactive.jakarta.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition
-
delistComponentResources
public void delistComponentResources(boolean suspend) throws RemoteException
Description copied from interface:JavaEETransactionManager
This is called by the Container to ask the Transaction Manager to delist all resources held by a component The TM finds the component through the InvocationManager- Specified by:
delistComponentResources
in interfaceJavaEETransactionManager
- Parameters:
suspend
- true if the resources should be delisted with TMSUSPEND flag; false otherwise- Throws:
RemoteException
-
registerComponentResource
public void registerComponentResource(TransactionalResource h)
- Specified by:
registerComponentResource
in interfaceJavaEETransactionManager
-
getExistingResourceList
public List getExistingResourceList(Object instance, ComponentInvocation inv)
Description copied from interface:JavaEETransactionManager
Returns a list of resource handles held by the component- Specified by:
getExistingResourceList
in interfaceJavaEETransactionManager
-
preInvoke
public void preInvoke(ComponentInvocation prev) throws InvocationException
Description copied from interface:JavaEETransactionManager
Called by InvocationManager- Specified by:
preInvoke
in interfaceJavaEETransactionManager
- Throws:
InvocationException
-
postInvoke
public void postInvoke(ComponentInvocation curr, ComponentInvocation prev) throws InvocationException
Description copied from interface:JavaEETransactionManager
Called by InvocationManager- Specified by:
postInvoke
in interfaceJavaEETransactionManager
- Throws:
InvocationException
-
componentDestroyed
public void componentDestroyed(Object instance)
Description copied from interface:JavaEETransactionManager
This is called by Container to indicate that a component is being destroyed. All resources registered in the context should be released- Specified by:
componentDestroyed
in interfaceJavaEETransactionManager
- Parameters:
instance
- The component instance
-
componentDestroyed
public void componentDestroyed(Object instance, ComponentInvocation inv)
Description copied from interface:JavaEETransactionManager
This is called by Container to indicate that a component is being destroyed. All resources registered in the context should be released. The ComponentInvocation will be used for callback to calculate the resource table key.- Specified by:
componentDestroyed
in interfaceJavaEETransactionManager
- Parameters:
instance
- The component instanceinv
- The ComponentInvocation
-
componentDestroyed
public void componentDestroyed(ResourceHandler rh)
Description copied from interface:JavaEETransactionManager
This is called by Container to indicate that a component is being destroyed. All resources registered with this ResourceHandler should be released.- Specified by:
componentDestroyed
in interfaceJavaEETransactionManager
- Parameters:
rh
- The ResourceHandler
-
isTimedOut
public boolean isTimedOut()
Description copied from interface:JavaEETransactionManager
Utility for the ejb container to check if the transaction is marked for rollback because of timeout. This is applicable only for local transactions as jts transaction will rollback instead of setting the txn for rollback- Specified by:
isTimedOut
in interfaceJavaEETransactionManager
-
checkTransactionImport
public void checkTransactionImport()
Called from the CORBA Interceptors on the server-side when the server is replying to the client (local + remote client). Check if there is an active transaction and remove it from TLS.- Specified by:
checkTransactionImport
in interfaceJavaEETransactionManager
-
checkTransactionExport
public void checkTransactionExport(boolean isLocal)
Called from the CORBA Interceptors on the client-side when a client makes a call to a remote object (not in the same JVM). Check if there is an active, exportable transaction.- Specified by:
checkTransactionExport
in interfaceJavaEETransactionManager
- Throws:
RuntimeException
- if the transaction is not exportable
-
getXATerminator
public jakarta.resource.spi.XATerminator getXATerminator()
This is used by importing transactions via the Connector contract. Should not be called- Specified by:
getXATerminator
in interfaceJavaEETransactionManager
- Returns:
- a
XATerminator
instance. - Throws:
UnsupportedOperationException
-
release
public void release(Xid xid) throws jakarta.resource.spi.work.WorkException
Release a transaction. This call causes the calling thread to be dissociated from the specified transaction.This is used by importing transactions via the Connector contract.
- Specified by:
release
in interfaceJavaEETransactionManager
- Parameters:
xid
- the Xid object representing a transaction.- Throws:
jakarta.resource.spi.work.WorkException
-
recreate
public void recreate(Xid xid, long timeout) throws jakarta.resource.spi.work.WorkException
Recreate a transaction based on the Xid. This call causes the calling thread to be associated with the specified transaction.This is used by importing transactions via the Connector contract.
- Specified by:
recreate
in interfaceJavaEETransactionManager
- Parameters:
xid
- the Xid object representing a transaction.- Throws:
jakarta.resource.spi.work.WorkException
-
registerSynchronization
public void registerSynchronization(jakarta.transaction.Synchronization sync) throws IllegalStateException, jakarta.transaction.SystemException
Description copied from interface:JavaEETransactionManager
register a synchronization object with the transaction associated with the current thread- Specified by:
registerSynchronization
in interfaceJavaEETransactionManager
- Parameters:
sync
- the synchronization object- Throws:
IllegalStateException
- Thrown if the transaction in the target object is in prepared state or the transaction is inactive.jakarta.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition
-
begin
public void begin() throws jakarta.transaction.NotSupportedException, jakarta.transaction.SystemException
- Specified by:
begin
in interfacejakarta.transaction.TransactionManager
- Throws:
jakarta.transaction.NotSupportedException
jakarta.transaction.SystemException
-
begin
public void begin(int timeout) throws jakarta.transaction.NotSupportedException, jakarta.transaction.SystemException
This method is introduced as part of implementing the local transaction timeout capability. Implementation of begin() moved here. Previpusly there is no timeout infrastructure for local txns, so when ever a timeout required for local txn, it uses the globaltxn timeout infrastructure by doing an XA simulation.- Specified by:
begin
in interfaceJavaEETransactionManager
- Throws:
jakarta.transaction.NotSupportedException
jakarta.transaction.SystemException
-
commit
public void commit() throws jakarta.transaction.RollbackException, jakarta.transaction.HeuristicMixedException, jakarta.transaction.HeuristicRollbackException, SecurityException, IllegalStateException, jakarta.transaction.SystemException
- Specified by:
commit
in interfacejakarta.transaction.TransactionManager
- Throws:
jakarta.transaction.RollbackException
jakarta.transaction.HeuristicMixedException
jakarta.transaction.HeuristicRollbackException
SecurityException
IllegalStateException
jakarta.transaction.SystemException
-
rollback
public void rollback() throws IllegalStateException, SecurityException, jakarta.transaction.SystemException
- Specified by:
rollback
in interfacejakarta.transaction.TransactionManager
- Throws:
IllegalStateException
SecurityException
jakarta.transaction.SystemException
-
getStatus
public int getStatus() throws jakarta.transaction.SystemException
- Specified by:
getStatus
in interfacejakarta.transaction.TransactionManager
- Throws:
jakarta.transaction.SystemException
-
getTransaction
public jakarta.transaction.Transaction getTransaction() throws jakarta.transaction.SystemException
- Specified by:
getTransaction
in interfacejakarta.transaction.TransactionManager
- Throws:
jakarta.transaction.SystemException
-
setRollbackOnly
public void setRollbackOnly() throws IllegalStateException, jakarta.transaction.SystemException
- Specified by:
setRollbackOnly
in interfacejakarta.transaction.TransactionManager
- Throws:
IllegalStateException
jakarta.transaction.SystemException
-
suspend
public jakarta.transaction.Transaction suspend() throws jakarta.transaction.SystemException
- Specified by:
suspend
in interfacejakarta.transaction.TransactionManager
- Throws:
jakarta.transaction.SystemException
-
resume
public void resume(jakarta.transaction.Transaction tobj) throws jakarta.transaction.InvalidTransactionException, IllegalStateException, jakarta.transaction.SystemException
- Specified by:
resume
in interfacejakarta.transaction.TransactionManager
- Throws:
jakarta.transaction.InvalidTransactionException
IllegalStateException
jakarta.transaction.SystemException
-
setTransactionTimeout
public void setTransactionTimeout(int seconds) throws jakarta.transaction.SystemException
Modify the value of the timeout value that is associated with the transactions started by the current thread with the begin method.If an application has not called this method, the transaction service uses some default value for the transaction timeout.
- Specified by:
setTransactionTimeout
in interfacejakarta.transaction.TransactionManager
- Throws:
jakarta.transaction.SystemException
- Thrown if the transaction manager encounters an unexpected error condition
-
setPurgeCancelledTtransactionsAfter
public void setPurgeCancelledTtransactionsAfter(int num)
Modify the value to be used to purge transaction tasks after the specified number of cancelled tasks.- Specified by:
setPurgeCancelledTtransactionsAfter
in interfaceJavaEETransactionManager
-
getPurgeCancelledTtransactionsAfter
public int getPurgeCancelledTtransactionsAfter()
Returns the value to be used to purge transaction tasks after the specified number of cancelled tasks.- Specified by:
getPurgeCancelledTtransactionsAfter
in interfaceJavaEETransactionManager
-
getCurrentTransaction
public JavaEETransaction getCurrentTransaction()
Description copied from interface:JavaEETransactionManager
Return JavaEETransaction instance associated with the current thread.- Specified by:
getCurrentTransaction
in interfaceJavaEETransactionManager
- Returns:
- the JavaEETransaction associated with the current thread or null if it there is none.
-
setCurrentTransaction
public void setCurrentTransaction(JavaEETransaction t)
Description copied from interface:JavaEETransactionManager
Update JavaEETransaction associated with the current thread.- Specified by:
setCurrentTransaction
in interfaceJavaEETransactionManager
- Parameters:
t
- the JavaEETransaction associated with the current thread or null if the existing transaction had been completed.
-
getXAResourceWrapper
public XAResourceWrapper getXAResourceWrapper(String clName)
Description copied from interface:JavaEETransactionManager
Return XAResourceWrapper instance specific to this datasource class name that can be used instead of the driver provided version for transaction recovery.- Specified by:
getXAResourceWrapper
in interfaceJavaEETransactionManager
- Parameters:
clName
- the class name of a datasource.- Returns:
- the XAResourceWrapper instance specific to this datasource class name or null if there is no special wrapper available.
-
handlePropertyUpdate
public void handlePropertyUpdate(String name, Object value)
Description copied from interface:JavaEETransactionManager
Handle configuration change. Actual change will be performed by the delegate.- Specified by:
handlePropertyUpdate
in interfaceJavaEETransactionManager
- Parameters:
name
- the name of the configuration property.value
- the ne value of the configuration.
-
recoverIncompleteTx
public boolean recoverIncompleteTx(boolean delegated, String logPath, XAResource[] xaresArray) throws Exception
Description copied from interface:JavaEETransactionManager
Called by the ResourceRecoveryManager to recover the populated array of XAResource.- Specified by:
recoverIncompleteTx
in interfaceJavaEETransactionManager
- Parameters:
delegated
-true
if the recovery process is owned by this instance.logPath
- the name of the transaction logging directoryxaresArray
- the array of XA Resources to be recovered.- Returns:
- true if the recovery has been successful.
- Throws:
Exception
-
freeze
public void freeze()
- Specified by:
freeze
in interfaceJavaEETransactionManager
-
unfreeze
public void unfreeze()
- Specified by:
unfreeze
in interfaceJavaEETransactionManager
-
isFrozen
public boolean isFrozen()
XXX ???- Specified by:
isFrozen
in interfaceJavaEETransactionManager
-
cleanTxnTimeout
public void cleanTxnTimeout()
- Specified by:
cleanTxnTimeout
in interfaceJavaEETransactionManager
-
getEffectiveTimeout
public int getEffectiveTimeout()
-
setDefaultTransactionTimeout
public void setDefaultTransactionTimeout(int seconds)
- Specified by:
setDefaultTransactionTimeout
in interfaceJavaEETransactionManager
-
getActiveTransactions
public ArrayList getActiveTransactions()
- Specified by:
getActiveTransactions
in interfaceJavaEETransactionManager
-
getTransactionAdminBean
public TransactionAdminBean getTransactionAdminBean(jakarta.transaction.Transaction tran) throws jakarta.transaction.SystemException
- Throws:
jakarta.transaction.SystemException
-
forceRollback
public void forceRollback(String txnId) throws IllegalStateException, jakarta.transaction.SystemException
- Specified by:
forceRollback
in interfaceJavaEETransactionManager
- Throws:
IllegalStateException
jakarta.transaction.SystemException
-
setMonitoringEnabled
public void setMonitoringEnabled(boolean enabled)
- Specified by:
setMonitoringEnabled
in interfaceJavaEETransactionManager
-
getStatusAsString
public static String getStatusAsString(int status)
-
enlistXAResource
protected boolean enlistXAResource(jakarta.transaction.Transaction tran, TransactionalResource h) throws jakarta.transaction.RollbackException, IllegalStateException, jakarta.transaction.SystemException
- Throws:
jakarta.transaction.RollbackException
IllegalStateException
jakarta.transaction.SystemException
-
isDelegate
public boolean isDelegate(JavaEETransactionManagerDelegate d)
-
setDelegate
public void setDelegate(JavaEETransactionManagerDelegate d)
Description copied from interface:JavaEETransactionManager
Explicitly set the JavaEETransactionManagerDelegate instance for implementation-specific callbacks.- Specified by:
setDelegate
in interfaceJavaEETransactionManager
- Parameters:
d
- the JavaEETransactionManagerDelegate instance.
-
getLogger
public Logger getLogger()
-
monitorTxCompleted
public void monitorTxCompleted(Object obj, boolean b)
-
monitorTxBegin
public void monitorTxBegin(jakarta.transaction.Transaction tx)
-
resourceEnlistable
public boolean resourceEnlistable(TransactionalResource h)
-
isInvocationStackEmpty
public boolean isInvocationStackEmpty()
-
setTransactionCompeting
public void setTransactionCompeting(boolean b)
-
createImportedTransaction
public JavaEETransaction createImportedTransaction(TransactionInternal jtsTx) throws jakarta.transaction.SystemException
- Throws:
jakarta.transaction.SystemException
-
-