fr.dyade.aaa.util
Class ATransaction

java.lang.Object
  extended by fr.dyade.aaa.util.AbstractTransaction
      extended by fr.dyade.aaa.util.ATransaction
All Implemented Interfaces:
ATransactionMBean, Transaction, TransactionMBean, java.lang.Runnable

public final class ATransaction
extends AbstractTransaction
implements ATransactionMBean, java.lang.Runnable


Nested Class Summary
 
Nested classes/interfaces inherited from class fr.dyade.aaa.util.AbstractTransaction
AbstractTransaction.Context
 
Field Summary
private static java.io.ByteArrayOutputStream baos
           
(package private) static int CLEANUP_THRESHOLD_COMMIT
           
(package private) static int CLEANUP_THRESHOLD_OPERATION
           
(package private) static int CLEANUP_THRESHOLD_SIZE
           
private  java.util.Hashtable clog
          Log of all operations already commited but not reported on disk by the "garbage" Thread.
private  int commitCount
           
private  int cumulativeSize
           
(package private) static boolean debug
           
private  java.io.File dir
           
private static java.io.DataOutputStream dos
           
private static byte[] emptyUTFString
           
private  boolean garbage
           
private  java.lang.Thread gThread
           
private  boolean isRunning
           
private  java.lang.Object lock
           
private static java.lang.String LOCK
           
private  java.io.File lockFile
           
private static java.lang.String LOG
           
protected  java.io.FileDescriptor logFD
           
protected  java.io.RandomAccessFile logFile
           
protected  java.io.File logFilePN
           
private static org.objectweb.util.monolog.api.Logger logmon
           
private  int operationCount
           
private  java.util.Hashtable plog
          Log currently used by "garbage" Thread, its thread reports all operation it contents on disk, then it deletes it.
private static java.lang.String PLOG
           
protected  java.io.File plogFilePN
           
 
Fields inherited from class fr.dyade.aaa.util.AbstractTransaction
OOS_STREAM_HEADER, perThreadContext, phase
 
Fields inherited from interface fr.dyade.aaa.util.Transaction
COMMIT, FINALIZE, FREE, GARBAGE, INIT, Kb, Mb, PhaseInfo, ROLLBACK, RUN
 
Constructor Summary
ATransaction()
           
 
Method Summary
 void _stop()
           
 void close()
          Close the transaction module.
 void commit(boolean release)
          Commit the current transaction.
private  void commit(java.util.Hashtable log)
          Reports all logged operations on disk.
 void delete(java.lang.String dirName, java.lang.String name)
          Deletes the specified object.
private  void deleteDir(java.io.File dir)
          Delete the specified directory if it is empty.
 java.io.File getDir()
           
private  byte[] getFromLog(java.util.Hashtable log, java.lang.Object key)
           
private  byte[] getFromLog(java.lang.String dirName, java.lang.String name)
           
 java.lang.String[] getList(java.lang.String prefix)
          Returns an array of strings naming the objects in the component started by this prefix.
 void init(java.lang.String path)
          Initializes the atomic storage component.
 boolean isPersistent()
          Tests if the Transaction component is persistent.
 byte[] loadByteArray(java.lang.String dirName, java.lang.String name)
          Load the specified byte array.
protected  void newLogFile()
           
 void release()
          Release the mutual exclusion.
private  void restart(java.util.Hashtable log, java.io.File logFilePN)
           
 void rollback()
           
 void run()
           
protected  void saveInLog(byte[] buf, java.lang.String dirName, java.lang.String name, java.util.Hashtable log, boolean copy, boolean first)
          Register the specified object in transaction log.
protected  void setPhase(int newPhase)
          Changes the transaction state.
 void stop()
          Stops the transaction module.
protected  void syncLogFile()
           
private  void wakeup()
           
 
Methods inherited from class fr.dyade.aaa.util.AbstractTransaction
begin, create, create, createByteArray, createByteArray, delete, getPhase, getPhaseInfo, load, load, loadByteArray, save, save, save, saveByteArray, saveByteArray, saveByteArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface fr.dyade.aaa.util.TransactionMBean
getPhase, getPhaseInfo
 

Field Detail

logmon

private static org.objectweb.util.monolog.api.Logger logmon

CLEANUP_THRESHOLD_COMMIT

static final int CLEANUP_THRESHOLD_COMMIT
See Also:
Constant Field Values

CLEANUP_THRESHOLD_OPERATION

static final int CLEANUP_THRESHOLD_OPERATION
See Also:
Constant Field Values

CLEANUP_THRESHOLD_SIZE

static final int CLEANUP_THRESHOLD_SIZE
See Also:
Constant Field Values

commitCount

private int commitCount

operationCount

private int operationCount

cumulativeSize

private int cumulativeSize

clog

private java.util.Hashtable clog
Log of all operations already commited but not reported on disk by the "garbage" Thread. On event (at least previous log plog must be empty), it is moved to plog.


plog

private java.util.Hashtable plog
Log currently used by "garbage" Thread, its thread reports all operation it contents on disk, then it deletes it.


dir

private java.io.File dir

LOCK

private static final java.lang.String LOCK
See Also:
Constant Field Values

LOG

private static final java.lang.String LOG
See Also:
Constant Field Values

PLOG

private static final java.lang.String PLOG
See Also:
Constant Field Values

lockFile

private java.io.File lockFile

logFilePN

protected java.io.File logFilePN

plogFilePN

protected java.io.File plogFilePN

garbage

private boolean garbage

lock

private java.lang.Object lock

isRunning

private boolean isRunning

gThread

private java.lang.Thread gThread

debug

static final boolean debug
See Also:
Constant Field Values

emptyUTFString

private static final byte[] emptyUTFString

baos

private static java.io.ByteArrayOutputStream baos

dos

private static java.io.DataOutputStream dos

logFile

protected java.io.RandomAccessFile logFile

logFD

protected java.io.FileDescriptor logFD
Constructor Detail

ATransaction

public ATransaction()
Method Detail

isPersistent

public boolean isPersistent()
Description copied from interface: TransactionMBean
Tests if the Transaction component is persistent.

Specified by:
isPersistent in interface Transaction
Specified by:
isPersistent in interface TransactionMBean
Returns:
true if the component is persistent; false otherwise.

init

public final void init(java.lang.String path)
                throws java.io.IOException
Description copied from interface: Transaction
Initializes the atomic storage component.

Specified by:
init in interface Transaction
Throws:
java.io.IOException

restart

private final void restart(java.util.Hashtable log,
                           java.io.File logFilePN)
                    throws java.io.IOException
Throws:
java.io.IOException

getDir

public final java.io.File getDir()

setPhase

protected final void setPhase(int newPhase)
Description copied from class: AbstractTransaction
Changes the transaction state.

Specified by:
setPhase in class AbstractTransaction
Parameters:
newPhase - the new transaction state.

getList

public final java.lang.String[] getList(java.lang.String prefix)
Description copied from interface: Transaction
Returns an array of strings naming the objects in the component started by this prefix.

Specified by:
getList in interface Transaction
Returns:
an array of strings naming the objects in the component started by this prefix.

saveInLog

protected final void saveInLog(byte[] buf,
                               java.lang.String dirName,
                               java.lang.String name,
                               java.util.Hashtable log,
                               boolean copy,
                               boolean first)
                        throws java.io.IOException
Description copied from class: AbstractTransaction
Register the specified object in transaction log.

Specified by:
saveInLog in class AbstractTransaction
Parameters:
buf - the byte array containing the state of the object.
dirName - the directory name of the object.
name - the name of the object.
log - the log to use.
copy - the byte array can be modified, copy it.
first - the object is a new one.
Throws:
java.io.IOException

getFromLog

private final byte[] getFromLog(java.util.Hashtable log,
                                java.lang.Object key)
                         throws java.io.IOException
Throws:
java.io.IOException

getFromLog

private final byte[] getFromLog(java.lang.String dirName,
                                java.lang.String name)
                         throws java.io.IOException
Throws:
java.io.IOException

loadByteArray

public final byte[] loadByteArray(java.lang.String dirName,
                                  java.lang.String name)
                           throws java.io.IOException
Description copied from interface: Transaction
Load the specified byte array.

Specified by:
loadByteArray in interface Transaction
Parameters:
dirName - the directory name of the object.
name - the name of the object.
Returns:
the loaded byte array.
Throws:
java.io.IOException

delete

public final void delete(java.lang.String dirName,
                         java.lang.String name)
Description copied from interface: Transaction
Deletes the specified object.

Specified by:
delete in interface Transaction
Parameters:
dirName - the directory name of the object.
name - the name of the object.

commit

public void commit(boolean release)
            throws java.io.IOException
Description copied from interface: Transaction
Commit the current transaction.

Specified by:
commit in interface Transaction
Parameters:
release - if true releases the transaction at the end of the commit.
Throws:
java.io.IOException

newLogFile

protected void newLogFile()
                   throws java.io.IOException
Throws:
java.io.IOException

syncLogFile

protected void syncLogFile()
                    throws java.io.IOException
Throws:
java.io.IOException

rollback

public final void rollback()

release

public final void release()
                   throws java.io.IOException
Description copied from class: AbstractTransaction
Release the mutual exclusion.

Specified by:
release in interface Transaction
Overrides:
release in class AbstractTransaction
Throws:
java.io.IOException
See Also:
Transaction.release()

commit

private final void commit(java.util.Hashtable log)
                   throws java.io.IOException
Reports all logged operations on disk.

Throws:
java.io.IOException

deleteDir

private final void deleteDir(java.io.File dir)
Delete the specified directory if it is empty. Also recursively delete the parent directories if they are empty.


_stop

public final void _stop()

stop

public final void stop()
Description copied from interface: Transaction
Stops the transaction module. It waits all transactions termination, then the module is kept in a FREE 'ready to use' state.

Specified by:
stop in interface Transaction

close

public void close()
Close the transaction module. It waits all transactions termination, the module will be initialized anew before reusing it.

Specified by:
close in interface Transaction

run

public void run()
Specified by:
run in interface java.lang.Runnable

wakeup

private final void wakeup()
                   throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2010 ScalAgent D.T.. All Rights Reserved.