tyrex.tm.impl

Class TransactionImpl

final class TransactionImpl extends Object implements TyrexTransaction, Status

Implements a global transaction. This transaction supports X/A resources (see XAResource), can be part of an OTS global transaction (see ResourceImpl) and can contain OTS subtransactions (see Resource). Tightly integrated with TransactionManagerImpl and TransactionServer.

Synchronizations are called in the reverse order in which they are added.

Version: $Revision: 1.50 $ $Date: 2005/11/30 13:20:14 $

Author: Assaf Arkin

See Also: InternalXAResourceHolder TransactionManagerImpl TransactionDomain ResourceImpl

Field Summary
protected int_hashCode
The transaction hash code derived from the transaction identifier.
protected int_heuristic
The heuristic decision made by the transaction after a call to TransactionImpl, TransactionImpl, TransactionImpl.
protected TransactionImpl_nextEntry
The next entry in the hashtable maintained by TransactionDomain.
protected TransactionImpl_parent
If this transaction is a subtransaction of some global transaction, this variable will reference the parent transaction.
protected long_started
Indicates when the transaction started as system clock.
protected int_status
Holds the current status of the transaction.
protected SystemException_sysError
Held during a commit/rollback process to indicate that an unexpected error occured.
protected long_timeout
Indicates when the transaction will timeout as system clock.
protected TransactionDomainImpl_txDomain
The domain to which this transaction belongs.
protected BaseXid_xid
The transaction identifier.
Constructor Summary
TransactionImpl(BaseXid xid, TransactionImpl parent, TransactionDomainImpl txDomain, long timeout)
Hidden constructor used by TransactionDomain to create a new transaction.
TransactionImpl(BaseXid xid, PropagationContext pgContext, TransactionDomainImpl txDomain, long timeout)
Hidden constructor used by TransactionDomain to create a new transaction.
TransactionImpl(BaseXid xid, int heuristic, TransactionDomainImpl txDomain)
Hidden constructor used by TransactionDomain to recreate a transaction during recovery.
Method Summary
protected voidaddRecovery(XAResource xaResource, Xid xid)
Called during recovery to add a resource.
voidasyncCommit()
voidasyncRollback()
booleancanUseOnePhaseCommit()
voidcommit()
booleandelistResource(XAResource xaResource, int flag)
protected voidendResources()
Called to end the resources as part of the one phase commit protocol.
booleanenlistResource(XAResource xaResource)
booleanenlistResource(XAResource xaResource, XAResourceCallback callback)
booleanequals(Object other)
protected voidforget(int ignoreHeuristic)
Called to forget about the transaction at the end of either a commit or rollback.
ControlgetControl()
protected intgetHeuristic()
Returns the heuristic decision of this transaction after it has been prepared, commited or rolledback.
TransactiongetParent()
protected PropagationContextgetPropagationContext()
Returns the propagation context used to import this transaction or null if the transaction was not imported.
longgetStarted()
intgetStatus()
protected booleangetTimedOut()
Returns true if the transaction has timed out and rolled back.
longgetTimeout()
TransactiongetTopLevel()
XidgetXid()
inthashCode()
protected voidinternalCommit(boolean onePhaseCommit)
Performs the second part of the two phase commit, after a call to TransactionImpl returned a heuristic decision to commit.
protected voidinternalRollback()
Called to perform the actual rollback on the transaction.
protected voidinternalSetTransactionTimeout(int seconds)
Called by TransactionDomain to change the timeout for the transaction's resources to the new value.
protected String[]listResources()
Returns a listing of the resources associated with this transaction.
protected intnormalize(int heuristic)
Returns a normalized heuristic decision based on the supplied non-normalized heuristic.
voidonePhaseCommit()
protected voidprepare()
Called to prepare the resource as part of the two phase commit protocol.
protected voidregisterResource(Resource resource)
Called to register an OTS resource with the transaction.
voidregisterSynchronization(Synchronization sync)
protected voidresumeAndEnlistResources(XAResourceHolder[] xaResourceHolders)
Resume previously suspended resources in the transaction and enlist the new specified resources in the transaction.
voidrollback()
voidsetRollbackOnly()
voidsetTransactionTimeout(int seconds)
Change the timeout for the transaction's resources to the new value.
protected voidsuspendResources()
Suspend the resources associated with the transaction.
protected voidtimedOut()
Indicates that the transaction has been rolled back due to time out.
StringtoString()

Field Detail

_hashCode

protected final int _hashCode
The transaction hash code derived from the transaction identifier.

_heuristic

protected int _heuristic
The heuristic decision made by the transaction after a call to TransactionImpl, TransactionImpl, TransactionImpl. Held in case the operation is repeated to return a consistent heuristic decision. Defaults to read-only (i.e. no heuristic decision).

_nextEntry

protected TransactionImpl _nextEntry
The next entry in the hashtable maintained by TransactionDomain.

_parent

protected final TransactionImpl _parent
If this transaction is a subtransaction of some global transaction, this variable will reference the parent transaction. Subtransactions cannot commit or rollback directly, only as nested subtransactions.

_started

protected final long _started
Indicates when the transaction started as system clock.

_status

protected int _status
Holds the current status of the transaction.

_sysError

protected SystemException _sysError
Held during a commit/rollback process to indicate that an unexpected error occured. Will throw that exception if there is no other more important exception to report (e.g. RollbackException).

_timeout

protected long _timeout
Indicates when the transaction will timeout as system clock.

_txDomain

protected final TransactionDomainImpl _txDomain
The domain to which this transaction belongs. The domain is notified of the outcome of the transaction and any request to commit/rollback the transaction.

_xid

protected final BaseXid _xid
The transaction identifier. This must be of type BaseXid.

Constructor Detail

TransactionImpl

TransactionImpl(BaseXid xid, TransactionImpl parent, TransactionDomainImpl txDomain, long timeout)
Hidden constructor used by TransactionDomain to create a new transaction. A transaction can only be created through TransactionDomain or TransactionManager which take care of several necessary housekeeping duties.

Parameters: xid The Xid for this transaction parent The parent of this transaction if this is a nested transaction, null if this is a top level transaction txDomain The transaction domain timeout The timeout for this transaction, in milliseconds

TransactionImpl

TransactionImpl(BaseXid xid, PropagationContext pgContext, TransactionDomainImpl txDomain, long timeout)
Hidden constructor used by TransactionDomain to create a new transaction. A transaction can only be created through TransactionDomain or TransactionManager which take care of several necessary housekeeping duties. This transaction is created to import an OTS transaction using the propagation context.

Parameters: xid The Xid for this transaction pgContext The propagation context txDomain The transaction domain timeout The timeout for this transaction, in milliseconds

Throws: Inactive The parent transaction has rolled back or is inactive

TransactionImpl

TransactionImpl(BaseXid xid, int heuristic, TransactionDomainImpl txDomain)
Hidden constructor used by TransactionDomain to recreate a transaction during recovery. The transaction state and heuristic decision are restored from information available in the recovery log.

Parameters: xid The Xid for this transaction heuristic The recorded heuristic decision txDomain The transaction domain

Method Detail

addRecovery

protected void addRecovery(XAResource xaResource, Xid xid)
Called during recovery to add a resource. This method is called for every resource that reports a transaction branch during recovery. The resource's Xid is preserved and the resource is not started in the transaction. If an error occurs, the transaction heuristic decision is changed to hazard (not knowing whether the resource commits or rollsback).

Parameters: xaResource The XA resource xid The Xid for the transaction branch

asyncCommit

public void asyncCommit()

asyncRollback

public void asyncRollback()

canUseOnePhaseCommit

public boolean canUseOnePhaseCommit()

commit

public void commit()

delistResource

public boolean delistResource(XAResource xaResource, int flag)

endResources

protected void endResources()
Called to end the resources as part of the one phase commit protocol. On entry the status must be either ) or ).

The heuristic decision can be any of the following:

Throws: IllegalStateException The transaction is not active or is in the process of being commited, or prepared for two phase commit.

enlistResource

public boolean enlistResource(XAResource xaResource)

enlistResource

boolean enlistResource(XAResource xaResource, XAResourceCallback callback)

equals

public boolean equals(Object other)

forget

protected void forget(int ignoreHeuristic)
Called to forget about the transaction at the end of either a commit or rollback. This method servers three purposes. First, it will tell all the resources to forget about the transaction and release them if the appropriate heuristic exception occurred. Second, it will notify all the synchronziation objects that the transaction has completed with the transaction's status. Last, it will release any objects held by the transaction and dissocaite it from the list of available transactions.

The ignoreHeuristic argument is used to determine what heuristic outcomes cause forget to be called on the resources associated with the transaction. For instance if transaction commit has been called and the outcome is Heuristic.COMMIT then resource forget should be not be called. In this case resource forget should be called on all other heuristic outcomes like Heuristic.ROLLBACK for instance. Similarly if transaction rollback has been called and the outcome is Heuristic.ROLLBACK then resource forget should not be called. In this case resource forget should be called on all other heuristic outcomes like Heuristic.COMMIT.

Forget always gets called if we are doing two-phase commit.

Parameters: ignoreHeuristic the heuristic to ignore

Throws: IllegalStateException The transaction has not commited or rolledback yet

See Also: HeuristicExceptions

getControl

public Control getControl()

getHeuristic

protected int getHeuristic()
Returns the heuristic decision of this transaction after it has been prepared, commited or rolledback. At all other times this method will return .READONLY.

Returns: The heuristic decision of this transaction

getParent

public Transaction getParent()

getPropagationContext

protected PropagationContext getPropagationContext()
Returns the propagation context used to import this transaction or null if the transaction was not imported.

getStarted

public long getStarted()

getStatus

public int getStatus()

getTimedOut

protected boolean getTimedOut()
Returns true if the transaction has timed out and rolled back.

getTimeout

public long getTimeout()

getTopLevel

public Transaction getTopLevel()

getXid

public Xid getXid()

hashCode

public int hashCode()

internalCommit

protected void internalCommit(boolean onePhaseCommit)
Performs the second part of the two phase commit, after a call to TransactionImpl returned a heuristic decision to commit. Will attempt to commit on all the resources that are not read-only. The end result is described in a heuristic decision. Multiple calls are supported.

The heuristic decision can be any of the following:

Parameters: onePhaseCommit True if one phase commit is to be used

Throws: IllegalStateException Transaction has not been prepared

internalRollback

protected void internalRollback()
Called to perform the actual rollback on the transaction. Will force a rollback on all the enlisted resources and delisted resources and return the heuristic decision of the rollback. Multiple calls are supported.

The heuristic decision can be any of the following:

Throws: IllegalStateException The transaction is not active

internalSetTransactionTimeout

protected void internalSetTransactionTimeout(int seconds)
Called by TransactionDomain to change the timeout for the transaction's resources to the new value. This might or might not have an effect on the underlying resources. All consistency checks are made by the server.

Parameters: secods The new timeout in seconds

See Also: TransactionDomain#setTransactionTimeout

listResources

protected String[] listResources()
Returns a listing of the resources associated with this transaction. Provides an identification of all the XA resources, OTS resources and subtransactions.

Returns: Array of description of all resources enlisted with this transaction

normalize

protected int normalize(int heuristic)
Returns a normalized heuristic decision based on the supplied non-normalized heuristic. A normalized heuristic has at most one flag set it in. For example, if both commit and rollback flags are set, the outcome is a mixed heuristic. If both commit and mixed are set, the outcome is again a mixed heuristic.

Parameters: heuristic A non-normalized heuristic decision

Returns: A normalized heuristic decision

onePhaseCommit

public void onePhaseCommit()

prepare

protected void prepare()
Called to prepare the resource as part of the two phase commit protocol. On entry the status must be either ) or ).

All enlisted resources are notified that the transaction has ended, and are they asked to prepare it. If a resource succeeds we will commit it (unless we decide to rollback the entire transaction). If a resource is read-only (or shared) we will mark it as read-only. If at least one resource fails to prepare, or any other error is encountered, we stop preparation and return a heuristic decision.

The heuristic decision can be any of the following:

Throws: IllegalStateException The transaction is not active or is in the process of being commited

registerResource

protected void registerResource(Resource resource)
Called to register an OTS resource with the transaction. Used internally to perform nested transactions and exposed through the OTS interface.

Parameters: res The OTS resource to register

registerSynchronization

public void registerSynchronization(Synchronization sync)

resumeAndEnlistResources

protected void resumeAndEnlistResources(XAResourceHolder[] xaResourceHolders)
Resume previously suspended resources in the transaction and enlist the new specified resources in the transaction. The resources may already be enlisted.

Active resources (ie non-suspended) are not affected.

Parameters: xaResources The resources to be enlisted in the transaction, may be bull

rollback

public void rollback()

setRollbackOnly

public void setRollbackOnly()

setTransactionTimeout

public void setTransactionTimeout(int seconds)
Change the timeout for the transaction's resources to the new value.

Parameters: seconds The new timeout in seconds

See Also: TransactionDomain#setTransactionTimeout

suspendResources

protected void suspendResources()
Suspend the resources associated with the transaction.

The resources that are already suspended are not affected.

timedOut

protected void timedOut()
Indicates that the transaction has been rolled back due to time out. Automatically performs a rollback on the transaction. We only reach this state if the transaction is active.

toString

public String toString()
Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.