fr.dyade.aaa.util
Class NGTransaction

java.lang.Object
  extended by fr.dyade.aaa.util.AbstractTransaction
      extended by fr.dyade.aaa.util.NGTransaction
All Implemented Interfaces:
NGTransactionMBean, Transaction

public final class NGTransaction
extends AbstractTransaction
implements NGTransactionMBean

The NGTransaction class implements a transactional storage. For efficiency it uses multiples files for its transaction journal, the final storage is provided through the Repository interface on filesystem or database.

Be Careful, the configuration properties don't work for the transaction component: these properties are saved in the transaction repository so they can not be used to configure it.

See Also:
Transaction, Repository, FileRepository, DBRepository, MySqlDBRepository

Nested Class Summary
static class NGTransaction.LogFile
           
(package private) static class NGTransaction.LogManager
          This class manages the memory log of operations and the multiples log files.
 
Nested classes/interfaces inherited from class fr.dyade.aaa.util.AbstractTransaction
AbstractTransaction.Context
 
Field Summary
(package private)  java.io.File dir
           
(package private)  NGTransaction.LogManager logManager
           
(package private) static int LogMemoryCapacity
          Global in memory log initial capacity, by default 4096.
private static org.objectweb.util.monolog.api.Logger logmon
           
(package private) static int LogThresholdOperation
          Number of pooled operation, by default 1000.
(package private) static int MaxLogFileSize
          Maximum size of disk log in Mb, by default 16Mb.
(package private) static int nbLogFile
          Maximum number of disk log used by the Transaction component, by default 4.
(package private)  Repository repository
           
(package private)  java.lang.String repositoryImpl
          The Repository classname implementation.
(package private)  long startTime
           
 
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
NGTransaction()
           
 
Method Summary
 void close()
          Close the transaction module.
 void commit(boolean release)
          Commit the current transaction.
 void delete(java.lang.String dirName, java.lang.String name)
          Deletes the specified object.
 int getCommitCount()
          Returns the number of commit operation since starting up.
private  byte[] getFromLog(java.util.Hashtable log, java.lang.Object key)
           
private  byte[] getFromLog(java.lang.String dirName, java.lang.String name)
           
 int getGarbageCount()
          Returns the number of garbage operation since starting up.
 int getGarbageRatio()
          Returns the ratio of garbage operations since starting up.
 long getGarbageTime()
          Returns the cumulated time of garbage operations since starting up.
 java.lang.String[] getList(java.lang.String prefix)
          Returns an array of strings naming the persistent objects denoted by a name that satisfy the specified prefix.
 int getLogFileSize()
          Returns the current size of disk log in Kb.
 int getLogMemoryCapacity()
          Returns the initial capacity of global in memory log (by default 4096).
 int getLogMemorySize()
          Returns the number of operation in the memory log.
 int getLogThresholdOperation()
          Returns the pool size for operation objects, by default 1000.
 int getMaxLogFileSize()
          Returns the maximum size of disk log in Mb, by default 16Mb.
 int getNbBadDeletedObjects()
          Returns the number of useless delete operation on repository.
 int getNbDeletedObjects()
          Returns the number of delete operation on repository.
 int getNbLoadedFromLog()
          Returns the number of load operation from a log file since last start.
 int getNbLoadedObjects()
          Returns the number of load operation from repository.
 int getNbLogFiles()
          Returns the number of rolled log files.
 int getNbSavedObjects()
          Returns the number of save operation to repository.
 java.lang.String getPersistenceDir()
          Returns the path of persistence directory.
 java.lang.String getRepositoryImpl()
          Returns the Repository classname implementation.
 long getStartTime()
          Returns the starting time.
 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 saveInLog(byte[] buf, java.lang.String dirName, java.lang.String name, java.util.Hashtable log, boolean copy, boolean first)
          Save an object state already serialized.
 void setMaxLogFileSize(int size)
          Sets the maximum size of disk log in Mb.
protected  void setPhase(int newPhase)
          Changes the transaction state.
 void stop()
          Stops the transaction module.
 java.lang.String toString()
          Returns a string representation for this object.
 
Methods inherited from class fr.dyade.aaa.util.AbstractTransaction
begin, create, create, createByteArray, createByteArray, delete, getPhase, getPhaseInfo, load, load, loadByteArray, release, save, save, save, saveByteArray, saveByteArray, saveByteArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface fr.dyade.aaa.util.NGTransactionMBean
getPhase, getPhaseInfo
 

Field Detail

logmon

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

LogMemoryCapacity

static int LogMemoryCapacity
Global in memory log initial capacity, by default 4096. This value can be adjusted for a particular server by setting Transaction.LogMemoryCapacity specific property.

This property can be fixed only from java launching command, or through System.property method.


MaxLogFileSize

static int MaxLogFileSize
Maximum size of disk log in Mb, by default 16Mb. This value can be adjusted (Mb) for a particular server by setting Transaction.MaxLogFileSize specific property.

This property can be fixed only from java launching command, or through System.property method.


nbLogFile

static int nbLogFile
Maximum number of disk log used by the Transaction component, by default 4. This value can be adjusted for a particular server by setting Transaction.NbLogFile specific property.

This property can be fixed only from java launching command, or through System.property method.


LogThresholdOperation

static int LogThresholdOperation
Number of pooled operation, by default 1000. This value can be adjusted for a particular server by setting Transaction.LogThresholdOperation specific property.

This property can be fixed only from java launching command, or through System.property method.


repositoryImpl

java.lang.String repositoryImpl
The Repository classname implementation. This value can be set for a particular server by setting the Transaction.RepositoryImpl specific property. By default its value is "fr.dyade.aaa.util.FileRepository".

This property can be fixed only from java launching command, or through System.property method.


startTime

long startTime

dir

java.io.File dir

logManager

NGTransaction.LogManager logManager

repository

Repository repository
Constructor Detail

NGTransaction

public NGTransaction()
Method Detail

getLogMemoryCapacity

public final int getLogMemoryCapacity()
Returns the initial capacity of global in memory log (by default 4096).

Specified by:
getLogMemoryCapacity in interface NGTransactionMBean
Returns:
The initial capacity of global in memory log.

getLogMemorySize

public int getLogMemorySize()
Returns the number of operation in the memory log.

Specified by:
getLogMemorySize in interface NGTransactionMBean
Returns:
The number of operation in the memory log.

getMaxLogFileSize

public final int getMaxLogFileSize()
Returns the maximum size of disk log in Mb, by default 16Mb.

Specified by:
getMaxLogFileSize in interface NGTransactionMBean
Returns:
The maximum size of disk log in Mb.

setMaxLogFileSize

public final void setMaxLogFileSize(int size)
Sets the maximum size of disk log in Mb.

Specified by:
setMaxLogFileSize in interface NGTransactionMBean
Parameters:
size - The maximum size of disk log in Mb.

getLogFileSize

public final int getLogFileSize()
Returns the current size of disk log in Kb.

Specified by:
getLogFileSize in interface NGTransactionMBean
Returns:
The size of disk log in Kb.

getNbLogFiles

public final int getNbLogFiles()
Returns the number of rolled log files.

Specified by:
getNbLogFiles in interface NGTransactionMBean
Returns:
The number of rolled log files.

getLogThresholdOperation

public final int getLogThresholdOperation()
Returns the pool size for operation objects, by default 1000.

Specified by:
getLogThresholdOperation in interface NGTransactionMBean
Returns:
The pool size for operation objects.

getCommitCount

public final int getCommitCount()
Returns the number of commit operation since starting up.

Specified by:
getCommitCount in interface NGTransactionMBean
Returns:
The number of commit operation.

getGarbageCount

public final int getGarbageCount()
Returns the number of garbage operation since starting up.

Specified by:
getGarbageCount in interface NGTransactionMBean
Returns:
The number of garbage operation.

getGarbageTime

public long getGarbageTime()
Returns the cumulated time of garbage operations since starting up.

Specified by:
getGarbageTime in interface NGTransactionMBean
Returns:
The cumulated time of garbage operations since starting up.

getNbLoadedFromLog

public int getNbLoadedFromLog()
Returns the number of load operation from a log file since last start.

Specified by:
getNbLoadedFromLog in interface NGTransactionMBean
Returns:
The number of load operation from a log file.

getGarbageRatio

public int getGarbageRatio()
Returns the ratio of garbage operations since starting up.

Specified by:
getGarbageRatio in interface NGTransactionMBean
Returns:
The ratio of garbage operations since starting up.

getRepositoryImpl

public java.lang.String getRepositoryImpl()
Returns the Repository classname implementation.

Specified by:
getRepositoryImpl in interface NGTransactionMBean
Returns:
The Repository classname implementation.

getNbSavedObjects

public int getNbSavedObjects()
Returns the number of save operation to repository.

Specified by:
getNbSavedObjects in interface NGTransactionMBean
Returns:
The number of save operation to repository.

getNbDeletedObjects

public int getNbDeletedObjects()
Returns the number of delete operation on repository.

Specified by:
getNbDeletedObjects in interface NGTransactionMBean
Returns:
The number of delete operation on repository.

getNbBadDeletedObjects

public int getNbBadDeletedObjects()
Returns the number of useless delete operation on repository.

Specified by:
getNbBadDeletedObjects in interface NGTransactionMBean
Returns:
The number of useless delete operation on repository.

getNbLoadedObjects

public int getNbLoadedObjects()
Returns the number of load operation from repository.

Specified by:
getNbLoadedObjects in interface NGTransactionMBean
Returns:
The number of load operation from repository.

getStartTime

public long getStartTime()
Returns the starting time.

Specified by:
getStartTime in interface NGTransactionMBean
Returns:
The starting time.

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

isPersistent

public boolean isPersistent()
Tests if the Transaction component is persistent.

Specified by:
isPersistent in interface Transaction
Returns:
true.

getPersistenceDir

public java.lang.String getPersistenceDir()
Returns the path of persistence directory.

Returns:
The path of persistence directory.

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 java.lang.String[] getList(java.lang.String prefix)
Returns an array of strings naming the persistent objects denoted by a name that satisfy the specified prefix. Each string is an object name.

Specified by:
getList in interface Transaction
Parameters:
prefix - the prefix
Returns:
An array of strings naming the persistent objects denoted by a name that satisfy the specified prefix. The array will be empty if no names match.

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
Save an object state already serialized. The byte array in parameter may be modified so we must duplicate it.

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 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 final 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

stop

public void stop()
Stops the transaction module. It waits all transactions termination, then the module is kept in a FREE 'ready to use' state. The log file is garbaged, all operations are reported to disk.

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. The log file is garbaged then closed.

Specified by:
close in interface Transaction

toString

public java.lang.String toString()
Returns a string representation for this object.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this object.


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