class Txn extends Object implements TransactableMgr, TransactionConstants, StorableObject
Modifier and Type | Field and Description |
---|---|
private long |
id
The internal id Outrigger as assigned to the transaction
|
private static Logger |
logger
Logger for logging transaction related information
|
private TxnMonitorTask |
monitorTask
The task responsible for monitoring to see if this
transaction has been aborted with us being told, or
null if no such task as been allocated.
|
private int |
state
What state we think the transaction is in
|
private boolean |
stateChangeWaiting
true if there is a blocked state change. |
private int |
stateReaders
Count of number of threads holding a read lock on state
|
private ServerTransaction |
tr
Cached
ServerTransaction object for
the transaction this object is fronting for. |
private long |
trId
The id the transaction manager assigned to this transaction
|
private StorableReference |
trm
The transaction manager associated with the transaction
this object is fronting for.
|
private List |
txnables
The list of
Transactable participating in
this transaction. |
READ, stateNames, TAKE, WRITE
ABORTED, ACTIVE, COMMITTED, NOTCHANGED, PREPARED, VOTING
Constructor and Description |
---|
Txn(long id)
Used in recovery
|
Txn(ServerTransaction tr,
long id)
Create a new
Txn that represents our state in the
given ServerTransaction . |
Modifier and Type | Method and Description |
---|---|
(package private) void |
abort(OutriggerServerImpl space)
Abort the transaction.
|
Transactable |
add(Transactable t)
Caution: see locking discussion at the class level.
|
(package private) void |
allowStateChange()
Release the read lock created by an
ensureActive
call. |
private void |
cleanup()
Clean up any state when the transaction is finished.
|
(package private) void |
commit(OutriggerServerImpl space)
Having prepared, roll the changes
forward.
|
(package private) void |
ensureActive()
Atomically checks that this transaction is in the active
state and locks the transaction in the active state.
|
(package private) Long |
getId()
Get the id for this txn.
|
(package private) TransactionManager |
getManager()
Return the manager associated with this transaction.
|
(package private) int |
getState()
Return our local view of the current state.
|
ServerTransaction |
getTransaction(ProxyPreparer preparer)
Return the
ServerTransaction which this manager
handles. |
(package private) long |
getTransactionId()
We keep the transaction ID around because we may need it
to identify a broken transaction after recovery.
|
(package private) void |
makeInactive()
Prevents new operations from being started under this
transaction and blocks until in process operations are
completed.
|
(package private) TxnMonitorTask |
monitorTask()
Return the monitor task for this object.
|
(package private) void |
monitorTask(TxnMonitorTask task)
Set the monitor task for this object.
|
(package private) int |
prepare(OutriggerServerImpl space)
Prepare for transaction commit.
|
void |
restore(ObjectInputStream in)
Restore the persistent fields
|
void |
store(ObjectOutputStream out)
Store the persistent fields
|
private final long id
private int state
private StorableReference trm
private ServerTransaction tr
ServerTransaction
object for
the transaction this object is fronting for.private long trId
private final List txnables
Transactable
participating in
this transaction.private TxnMonitorTask monitorTask
private int stateReaders
private boolean stateChangeWaiting
true
if there is a blocked state change. Used
to give writers priority.private static final Logger logger
Txn(ServerTransaction tr, long id)
Txn
that represents our state in the
given ServerTransaction
.Txn(long id)
Long getId()
ServerTransaction
object) we create
our own internal id to make txns unique. This is needed since we
may not have the Transaction
unmarshalled.long getTransactionId()
int getState()
ensureActive
to get the current value.void ensureActive() throws CannotJoinException
allowStateChange
.
Each call to this method should be paired with a call to
allowStateChange
in a finally block.CannotJoinException
- if the transaction
is not active or a state change is pending.void allowStateChange()
ensureActive
call. Does nothing if the transaction is not active or there is
a state change pending and thus is safe to call even if the
corresponding ensureActive
call threw
CannotJoinException
.void makeInactive()
int prepare(OutriggerServerImpl space)
makeInactive
must have
been called on this transaction first.void abort(OutriggerServerImpl space)
prepare
because if a Transactable
votes ABORT
, this method is called to make that
happen. makeInactive
must have been called on this
transaction first.void commit(OutriggerServerImpl space)
makeInactive
must have been called on
this transaction first.public Transactable add(Transactable t)
add
in interface TransactableMgr
public ServerTransaction getTransaction(ProxyPreparer preparer) throws IOException, ClassNotFoundException
TransactableMgr
ServerTransaction
which this manager
handles. If necessary deserialize the manager and optionally
prepare it. Will only deserialize the manager if it has not
already been deserialized. Will only prepare the manager if
preparer
is non-null and no previous call to
getTransaction
has succeeded. If this method
throws an exception, preparation has not succeeded. If a
previous call to this method has succeed, all future calls will
succeed and return the same object as the first successful
call.getTransaction
in interface TransactableMgr
preparer
- the ProxyPreparer
to
be used to prepare the reference. May
be null
.ServerTransaction
which this manager
handles.IOException
- if the unmarshalling fails. Will
also throw RemoteException
if preparer.prepareProxy
does.ClassNotFoundException
- if unmarshalling fails
with one.TransactionManager getManager()
IllegalStateException
- if this Txn
is still broken.TxnMonitorTask monitorTask()
monitorTask(TxnMonitorTask)
are both called
from the same thread.void monitorTask(TxnMonitorTask task)
monitorTask()
are
both called from the same thread.private void cleanup()
public void store(ObjectOutputStream out) throws IOException
StorableObject
store
in interface StorableObject
IOException
public void restore(ObjectInputStream in) throws IOException, ClassNotFoundException
StorableObject
restore
in interface StorableObject
IOException
ClassNotFoundException
Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.