ozone core API

org.ozoneDB.core
Class Transaction

java.lang.Object
  |
  +--org.ozoneDB.core.Transaction
All Implemented Interfaces:
Locker

public final class Transaction
extends java.lang.Object
implements Locker

This class represents an internal transaction.

Most methods of this class are synchronized. In fact, this is not strictly needed because a transaction is invoked by one thread (associated with this transaction) only.

All public methods are wrapped into try/catch statements to convert thrown exception into OzoneInternalExc. So the client gets OzoneRemoteExc, if an object could not be found or something; OzoneInternalExc, if there was a critical internal error; any other exceptions were thrown by the user code.

Version:
$Revision: 1.4 $Date: 2002/07/26 12:29:22 $
Author:
SMB
, Medium.net

Field Summary
protected  int acquireCount
           
protected  ObjectID blocker
          The ID of the object (container) that blocks this transaction.
protected  org.ozoneDB.data.SimpleArrayList callStack
          The list of ObjectContainers which are called by this transactions but where the call is not completed.
protected  int commandCount
           
private  java.lang.Object data
          Data that the StoreManager implementation uses to hold data that is associated with this transaction.
protected  boolean deadlocked
          Are we deadlocked?
protected  long deadlockWaitTimeMaximum
          The maximum time (in milliseconds) to wait after a deadlock.
protected static long deadlockWaitTimeMaximumMaximum
          The maximum deadlockWaitTimeMaximum can have.
protected static long deadlockWaitTimeMaximumMinimum
          The minimum deadlockWaitTimeMaximum can have.
protected  Env env
          The environment of this object.
static int HASHTABLE_INIT_SIZE
           
protected  int maxLockLevel
           
protected  User owner
           
protected  java.lang.String ownerName
           
protected  boolean rollbackOnly
           
protected  boolean sleeping
          Is this thread sleeping?
protected  long startTime
           
protected  int status
           
static int STATUS_ABORTED
          Status of a transaction: transaction has been aborted.
static int STATUS_ABORTING
          Status of a transaction: transaction is about to abort.
static int STATUS_COMMITED
          Status of a transaction: transaction has been successfully committed.
static int STATUS_COMMITING
          Status of a transaction: transaction is about to commit.
static int STATUS_NONE
          Status of a transaction: transaction is not active.
static int STATUS_PREPARED
          Status of a transaction: transaction has been successfully prepared.
static int STATUS_PREPARING
          Status of a transaction: transaction is about to prepare.
static int STATUS_STARTED
          Status of a transaction: transaction has been started.
protected  boolean stopped
           
protected  TransactionID taID
           
 
Constructor Summary
Transaction(Env _env, User _owner)
          Construct a new transaction.
Transaction(TransactionID _taID)
          Construct a new transaction.
 
Method Summary
 void abort(DbCommand command)
          Once this method is called it MUST cleanup the entire transaction stuff without exception.
protected  ObjectContainer acquireContainer(ObjectContainer container, int lockLevel)
           
 ObjectContainer acquireObjectAndPin(ObjectID id, int lockLevel)
          Set a lock on the container specified by the given object ID and join the container to this transaction.
 Lockable blockedByAndPin()
          Helper method to implement the Locker interface to support deadlock recognition via core.dr package
 void commit()
          Commit this transaction.
 ObjectContainer copyObjectAndPin(ObjectID id)
           
 ObjectContainer createObjectAndPin(java.lang.String className, int access, java.lang.String name, java.lang.String sig, java.lang.Object[] args, ObjectID id)
          Create a new database object.
 void deleteObject(ObjectID id)
           
 boolean equals(java.lang.Object obj)
           
 void finalize()
           
 org.ozoneDB.data.SimpleArrayList getCallStack()
           
 java.lang.Object getData()
           
protected  long getDeadlockWaitTimeMaximum()
           
 TransactionManager getManager()
           
protected  long increaseDeadlockWaitTimeMaximum()
           
 java.lang.Object invokeObject(ObjectID id, int methodIndex, java.lang.Object[] args, int lockLevel)
           
 java.lang.Object invokeObject(ObjectID id, java.lang.String methodName, java.lang.String sig, java.lang.Object[] args, int lockLevel)
           
 boolean isBlocked()
          Returns wether this locker is blocked.
 boolean isDeadlocked()
           
protected  boolean isSleeping()
           
 int maxLockLevel()
           
 void nameObject(ObjectID id, java.lang.String name)
           
 org.ozoneDB.OzoneProxy objectForID(ObjectID id)
           
 org.ozoneDB.OzoneProxy objectForName(java.lang.String name)
           
 User owner()
           
 boolean performCommand(DbCommand command)
           
 void prepareCommit()
           
 void releaseObjectAndUnpin(ObjectContainer objectContainer)
          The corresponding method to acquireObjectAndPin(org.ozoneDB.core.ObjectID, int).
 void reset()
           
protected  void setData(java.lang.Object to)
           
 void setDeadlocked(boolean to)
           
protected  void setDeadlockWaitTimeMaximum(long to)
           
 void sleep(long millis)
           
 int status()
           
 void stop()
           
 TransactionID taID()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATUS_NONE

public static final int STATUS_NONE
Status of a transaction: transaction is not active.

See Also:
Constant Field Values

STATUS_STARTED

public static final int STATUS_STARTED
Status of a transaction: transaction has been started.

See Also:
Constant Field Values

STATUS_PREPARING

public static final int STATUS_PREPARING
Status of a transaction: transaction is about to prepare.

See Also:
Constant Field Values

STATUS_PREPARED

public static final int STATUS_PREPARED
Status of a transaction: transaction has been successfully prepared.

See Also:
Constant Field Values

STATUS_COMMITING

public static final int STATUS_COMMITING
Status of a transaction: transaction is about to commit.

See Also:
Constant Field Values

STATUS_COMMITED

public static final int STATUS_COMMITED
Status of a transaction: transaction has been successfully committed.

See Also:
Constant Field Values

STATUS_ABORTING

public static final int STATUS_ABORTING
Status of a transaction: transaction is about to abort.

See Also:
Constant Field Values

STATUS_ABORTED

public static final int STATUS_ABORTED
Status of a transaction: transaction has been aborted.

See Also:
Constant Field Values

HASHTABLE_INIT_SIZE

public static final int HASHTABLE_INIT_SIZE
See Also:
Constant Field Values

env

protected transient Env env
The environment of this object.


taID

protected TransactionID taID

ownerName

protected java.lang.String ownerName

owner

protected User owner

status

protected int status

rollbackOnly

protected boolean rollbackOnly

maxLockLevel

protected int maxLockLevel

data

private java.lang.Object data
Data that the StoreManager implementation uses to hold data that is associated with this transaction. Usually this is a table of all containers that are currently joined to this transaction.


commandCount

protected int commandCount

blocker

protected ObjectID blocker
The ID of the object (container) that blocks this transaction.


startTime

protected long startTime

acquireCount

protected int acquireCount

stopped

protected boolean stopped

deadlocked

protected boolean deadlocked
Are we deadlocked?


deadlockWaitTimeMaximumMinimum

protected static final long deadlockWaitTimeMaximumMinimum
The minimum deadlockWaitTimeMaximum can have. (default: 1 second)

See Also:
Constant Field Values

deadlockWaitTimeMaximumMaximum

protected static final long deadlockWaitTimeMaximumMaximum
The maximum deadlockWaitTimeMaximum can have. (default: 30 minutes)

See Also:
Constant Field Values

deadlockWaitTimeMaximum

protected long deadlockWaitTimeMaximum
The maximum time (in milliseconds) to wait after a deadlock.


sleeping

protected boolean sleeping
Is this thread sleeping?


callStack

protected org.ozoneDB.data.SimpleArrayList callStack
The list of ObjectContainers which are called by this transactions but where the call is not completed. The last object called is represented by the ObjectContainer with the greatest index in the list.

Constructor Detail

Transaction

public Transaction(Env _env,
                   User _owner)
Construct a new transaction.

Parameters:
_env - Environment of this transaction.
_owner - User that has started this transaction.

Transaction

public Transaction(TransactionID _taID)
Construct a new transaction. THIS TRANSACTION CAN BE USED FOR TESTING ONLY!

Method Detail

stop

public void stop()

reset

public void reset()

setDeadlockWaitTimeMaximum

protected void setDeadlockWaitTimeMaximum(long to)

getDeadlockWaitTimeMaximum

protected long getDeadlockWaitTimeMaximum()

increaseDeadlockWaitTimeMaximum

protected long increaseDeadlockWaitTimeMaximum()

setDeadlocked

public void setDeadlocked(boolean to)
Specified by:
setDeadlocked in interface Locker

isDeadlocked

public boolean isDeadlocked()
Specified by:
isDeadlocked in interface Locker

status

public int status()

owner

public User owner()

maxLockLevel

public int maxLockLevel()

releaseObjectAndUnpin

public void releaseObjectAndUnpin(ObjectContainer objectContainer)
The corresponding method to acquireObjectAndPin(org.ozoneDB.core.ObjectID, int).
Currently, it just unpins the container.


acquireObjectAndPin

public ObjectContainer acquireObjectAndPin(ObjectID id,
                                           int lockLevel)
                                    throws org.ozoneDB.ObjectNotFoundExc,
                                           java.io.IOException,
                                           java.lang.ClassNotFoundException,
                                           org.ozoneDB.TransactionExc,
                                           TransactionError
Set a lock on the container specified by the given object ID and join the container to this transaction. If a container is returned, it is pinned. Thus, it has to be unpinned by the caller.

Parameters:
id - ObjectID of the container which we try to join to this transaction.
lockLevel - The lock level we need on this object (container).
Returns:
The container for the specified id, if all was ok.
Throws:
org.ozoneDB.ObjectNotFoundExc - If there is no such object.
java.io.IOException
java.lang.ClassNotFoundException
org.ozoneDB.TransactionExc
TransactionError

acquireContainer

protected ObjectContainer acquireContainer(ObjectContainer container,
                                           int lockLevel)
                                    throws PermissionError,
                                           org.ozoneDB.TransactionExc,
                                           TransactionError,
                                           java.io.IOException,
                                           org.ozoneDB.ObjectNotFoundExc,
                                           java.lang.ClassNotFoundException
PermissionError
org.ozoneDB.TransactionExc
TransactionError
java.io.IOException
org.ozoneDB.ObjectNotFoundExc
java.lang.ClassNotFoundException

performCommand

public boolean performCommand(DbCommand command)

prepareCommit

public void prepareCommit()
                   throws java.io.IOException,
                          java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException

commit

public void commit()
            throws java.io.IOException,
                   java.lang.ClassNotFoundException
Commit this transaction. The transaction has to be in PREPARED state. Ones this method is called it MUST commit the entire transaction stuff without any exception.

java.io.IOException
java.lang.ClassNotFoundException

setData

protected void setData(java.lang.Object to)

getData

public java.lang.Object getData()

abort

public void abort(DbCommand command)
           throws java.io.IOException,
                  java.lang.ClassNotFoundException
Once this method is called it MUST cleanup the entire transaction stuff without exception. An exception signals an internal server error.

Note: This may be called after/from prepareCommit() !

java.io.IOException
java.lang.ClassNotFoundException

blockedByAndPin

public Lockable blockedByAndPin()
Helper method to implement the Locker interface to support deadlock recognition via core.dr package

Specified by:
blockedByAndPin in interface Locker

isBlocked

public boolean isBlocked()
Returns wether this locker is blocked.

Specified by:
isBlocked in interface Locker

createObjectAndPin

public ObjectContainer createObjectAndPin(java.lang.String className,
                                          int access,
                                          java.lang.String name,
                                          java.lang.String sig,
                                          java.lang.Object[] args,
                                          ObjectID id)
                                   throws java.lang.Exception,
                                          org.ozoneDB.ExceptionInOzoneObjectException
Create a new database object. If the className is null, an empty container is created.

Parameters:
className -
access -
name -
id - The ID of the new container or null.
Throws:
org.ozoneDB.PermissionDeniedExc - If user in invalid, name is already in use, target is not OzoneCompatible...
java.lang.Exception
org.ozoneDB.ExceptionInOzoneObjectException

copyObjectAndPin

public ObjectContainer copyObjectAndPin(ObjectID id)
                                 throws java.lang.Exception
java.lang.Exception

deleteObject

public void deleteObject(ObjectID id)
                  throws org.ozoneDB.ObjectNotFoundExc,
                         java.io.IOException,
                         java.lang.ClassNotFoundException,
                         org.ozoneDB.TransactionExc,
                         TransactionError,
                         org.ozoneDB.OzoneRemoteExc,
                         org.ozoneDB.OzoneInternalExc,
                         org.ozoneDB.ExceptionInOzoneObjectException
org.ozoneDB.ObjectNotFoundExc
java.io.IOException
java.lang.ClassNotFoundException
org.ozoneDB.TransactionExc
TransactionError
org.ozoneDB.OzoneRemoteExc
org.ozoneDB.OzoneInternalExc
org.ozoneDB.ExceptionInOzoneObjectException

invokeObject

public java.lang.Object invokeObject(ObjectID id,
                                     java.lang.String methodName,
                                     java.lang.String sig,
                                     java.lang.Object[] args,
                                     int lockLevel)
                              throws java.lang.Exception,
                                     org.ozoneDB.ExceptionInOzoneObjectException
Parameters:
id -
methodName -
sig -
lockLevel -
Returns:
java.lang.Exception
org.ozoneDB.ExceptionInOzoneObjectException

invokeObject

public java.lang.Object invokeObject(ObjectID id,
                                     int methodIndex,
                                     java.lang.Object[] args,
                                     int lockLevel)
                              throws java.lang.Exception,
                                     org.ozoneDB.ExceptionInOzoneObjectException
java.lang.Exception
org.ozoneDB.ExceptionInOzoneObjectException

nameObject

public void nameObject(ObjectID id,
                       java.lang.String name)
                throws java.lang.Exception
java.lang.Exception

objectForName

public org.ozoneDB.OzoneProxy objectForName(java.lang.String name)
                                     throws java.lang.Exception
java.lang.Exception

objectForID

public org.ozoneDB.OzoneProxy objectForID(ObjectID id)
                                   throws java.lang.Exception
java.lang.Exception

sleep

public void sleep(long millis)

isSleeping

protected boolean isSleeping()

taID

public TransactionID taID()

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

finalize

public void finalize()
              throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
java.lang.Throwable

getCallStack

public org.ozoneDB.data.SimpleArrayList getCallStack()

getManager

public TransactionManager getManager()

ozone core API

Copyright (C) The Ozone Database Project - www.ozone-db.org. All rights reserved.