Package fr.dyade.aaa.ext
Class NGTransaction
- java.lang.Object
-
- fr.dyade.aaa.util.BaseTransaction
-
- fr.dyade.aaa.util.AbstractTransaction
-
- fr.dyade.aaa.ext.NGTransaction
-
- All Implemented Interfaces:
NGTransactionMBean,Transaction,TransactionMBean
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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNGTransaction.LogFile(package private) static classNGTransaction.LogManagerThis 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
Fields Modifier and Type Field Description (package private) NGTransaction.LogManagerlogManager(package private) static intLogMemoryCapacityGlobal in memory log initial capacity, by default 4096.(package private) intLogThresholdOperationNumber of pooled operation, by default 1000.(package private) static intMaxLogFileSizeMaximum size of disk log in Mb, by default 16Mb.(package private) static intminObjInLogMinimum number of 'live' objects in a disk log before a garbage, by default 64.(package private) static intnbLogFileMaximum number of disk log used by the Transaction component, by default 4.(package private) Repositoryrepository(package private) StringrepositoryImplThe Repository classname implementation.(package private) booleansyncOnWriteIf true every write in the log file is synced to disk, by default false.-
Fields inherited from class fr.dyade.aaa.util.AbstractTransaction
average, dir, logmon, MONITOR, OOS_STREAM_HEADER, PERIODS, perThreadContext, phase, startTime
-
Fields inherited from class fr.dyade.aaa.util.BaseTransaction
DEBUG
-
-
Constructor Summary
Constructors Constructor Description NGTransaction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringbackup(String path)Backups the content of Transaction module.voidbackupPhase1(File backupDir, BackupFile backupFile)First phase of the backup: - Get all objects in repositoryvoidbackupPhase2(File backupDir, RestoreFile restoreFile, BackupFile backupFile)Second phase of the backup, compacts all logs in one then produces a unique backup file.voidclose()Close the transaction module.voidcommit(boolean release)Commit the current transaction.voiddelete(String dirName, String name)Deletes the specified object.(package private) booleandeleteDirectory(File directoryToBeDeleted)voidgarbage(int idx)intgetCommitCount()Returns the number of commit operation since starting up.private byte[]getFromLog(String dirName, String name)private byte[]getFromLog(Hashtable log, Object key)intgetGarbageCount()Returns the number of garbage operation since starting up.intgetGarbageRatio()Returns the ratio of garbage operations since starting up.longgetGarbageTime()Returns the cumulated time of garbage operations since starting up.String[]getList(String prefix)Returns an array of strings naming the persistent objects denoted by a name that satisfy the specified prefix.intgetLogFileSize()Returns the current size of disk log in Kb.intgetLogMemoryCapacity()Returns the initial capacity of global in memory log (by default 4096).intgetLogMemorySize()Returns the number of operation in the memory log.intgetLogThresholdOperation()Returns the pool size foroperationobjects, by default 1000.intgetMaxLogFileSize()Returns the maximum size of disk log in Mb, by default 16Mb.intgetNbBadDeletedObjects()Returns the number of useless delete operation on repository.intgetNbDeletedObjects()Returns the number of delete operation on repository.intgetNbLoadedFromLog()Returns the number of load operation from a log file since last start.intgetNbLoadedObjects()Returns the number of load operation from repository.intgetNbLogFiles()Returns the number of rolled log files.intgetNbSavedObjects()Returns the number of save operation to repository.StringgetPersistenceDir()Returns the path of persistence directory.StringgetRepositoryImpl()Returns the Repository classname implementation.voidinitRepository()booleanisSyncOnWrite()Returns true if every write in the log file is synced to disk.byte[]loadByteArray(String dirName, String name)Load the specified byte array.StringlogContent(int idx)StringlogCounters()voidresetGarbageRatio()protected voidsaveInLog(byte[] buf, String dirName, String name, Hashtable log, boolean copy, boolean first)Save an object state already serialized.voidsetMaxLogFileSize(int size)Sets the maximum size of disk log in Mb.protected voidsetPhase(int newPhase)Changes the transaction state.voidstop()Stops the transaction module.StringtoString()Returns a string representation for this object.-
Methods inherited from class fr.dyade.aaa.util.AbstractTransaction
begin, containsOperations, create, create, createByteArray, createByteArray, delete, getAverageCommitTime, getOperationCount, getPhase, getPhaseInfo, getStartTime, init, isPersistent, load, load, loadAll, loadByteArray, loadFromByteArray, release, save, save, save, saveByteArray, saveByteArray, saveByteArray, useLoadAll
-
Methods inherited from class fr.dyade.aaa.util.BaseTransaction
dumpObjectList, freeze, getBoolean, getInteger, getInteger, getObject, getObjectList, getProperty, getProperty, loadProperties, saveProperties
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface fr.dyade.aaa.ext.NGTransactionMBean
getAverageCommitTime
-
Methods inherited from interface fr.dyade.aaa.util.TransactionMBean
dumpObjectList, getObject, getObjectList, getPhase, getPhaseInfo, getStartTime, isPersistent, useLoadAll
-
-
-
-
Field Detail
-
LogMemoryCapacity
static int LogMemoryCapacity
Global in memory log initial capacity, by default 4096. This value can be adjusted for a particular server by settingTransaction.LogMemoryCapacityspecific property.This property can be set only at first launching.
-
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 settingTransaction.MaxLogFileSizespecific property.This property can be set only at first launching.
-
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 settingTransaction.NbLogFilespecific property.This property can be set only at first launching.
-
minObjInLog
static int minObjInLog
Minimum number of 'live' objects in a disk log before a garbage, by default 64. This value can be adjusted for a particular server by settingTransaction.minObjInLogspecific property.This property can be set only at first launching.
-
syncOnWrite
boolean syncOnWrite
If true every write in the log file is synced to disk, by default false. This value can be adjusted for a particular server by settingTransaction.SyncOnWritespecific property.This property can be set only at first launching.
-
LogThresholdOperation
int LogThresholdOperation
Number of pooled operation, by default 1000. This value can be adjusted for a particular server by settingTransaction.LogThresholdOperationspecific property.This property can be set only at first launching.
-
repositoryImpl
String repositoryImpl
The Repository classname implementation. This value can be set for a particular server by setting theTransaction.RepositoryImplspecific property. By default its value is "fr.dyade.aaa.util.FileRepository".This property can be set only at first launching.
-
logManager
NGTransaction.LogManager logManager
-
repository
Repository repository
-
-
Method Detail
-
getLogMemoryCapacity
public final int getLogMemoryCapacity()
Returns the initial capacity of global in memory log (by default 4096).- Specified by:
getLogMemoryCapacityin interfaceNGTransactionMBean- Returns:
- The initial capacity of global in memory log.
-
getLogMemorySize
public int getLogMemorySize()
Returns the number of operation in the memory log.- Specified by:
getLogMemorySizein interfaceNGTransactionMBean- 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:
getMaxLogFileSizein interfaceNGTransactionMBean- 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:
setMaxLogFileSizein interfaceNGTransactionMBean- 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:
getLogFileSizein interfaceNGTransactionMBean- Returns:
- The size of disk log in Kb.
-
getNbLogFiles
public final int getNbLogFiles()
Returns the number of rolled log files.- Specified by:
getNbLogFilesin interfaceNGTransactionMBean- Returns:
- The number of rolled log files.
-
isSyncOnWrite
public boolean isSyncOnWrite()
Description copied from interface:NGTransactionMBeanReturns true if every write in the log file is synced to disk.- Specified by:
isSyncOnWritein interfaceNGTransactionMBean- Returns:
- the syncOnWrite value.
-
getLogThresholdOperation
public final int getLogThresholdOperation()
Returns the pool size foroperationobjects, by default 1000.- Specified by:
getLogThresholdOperationin interfaceNGTransactionMBean- Returns:
- The pool size for
operationobjects.
-
getCommitCount
public final int getCommitCount()
Returns the number of commit operation since starting up.- Specified by:
getCommitCountin interfaceTransaction- Specified by:
getCommitCountin interfaceTransactionMBean- Returns:
- The number of commit operation.
-
getGarbageCount
public final int getGarbageCount()
Returns the number of garbage operation since starting up.- Specified by:
getGarbageCountin interfaceNGTransactionMBean- Returns:
- The number of garbage operation.
-
getGarbageTime
public long getGarbageTime()
Returns the cumulated time of garbage operations since starting up.- Specified by:
getGarbageTimein interfaceNGTransactionMBean- 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:
getNbLoadedFromLogin interfaceNGTransactionMBean- 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:
getGarbageRatioin interfaceNGTransactionMBean- Returns:
- The ratio of garbage operations since starting up.
-
resetGarbageRatio
public void resetGarbageRatio()
-
getRepositoryImpl
public String getRepositoryImpl()
Returns the Repository classname implementation.- Specified by:
getRepositoryImplin interfaceNGTransactionMBean- Returns:
- The Repository classname implementation.
-
getNbSavedObjects
public int getNbSavedObjects()
Returns the number of save operation to repository.- Specified by:
getNbSavedObjectsin interfaceNGTransactionMBean- Returns:
- The number of save operation to repository.
-
getNbDeletedObjects
public int getNbDeletedObjects()
Returns the number of delete operation on repository.- Specified by:
getNbDeletedObjectsin interfaceNGTransactionMBean- Returns:
- The number of delete operation on repository.
-
getNbBadDeletedObjects
public int getNbBadDeletedObjects()
Returns the number of useless delete operation on repository.- Specified by:
getNbBadDeletedObjectsin interfaceNGTransactionMBean- Returns:
- The number of useless delete operation on repository.
-
getNbLoadedObjects
public int getNbLoadedObjects()
Returns the number of load operation from repository.- Specified by:
getNbLoadedObjectsin interfaceNGTransactionMBean- Returns:
- The number of load operation from repository.
-
initRepository
public final void initRepository() throws IOException- Specified by:
initRepositoryin classAbstractTransaction- Throws:
IOException
-
getPersistenceDir
public 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:AbstractTransactionChanges the transaction state.- Specified by:
setPhasein classAbstractTransaction- Parameters:
newPhase- the new transaction state.
-
getList
public String[] getList(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:
getListin interfaceTransaction- 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, String dirName, String name, Hashtable log, boolean copy, boolean first) throws IOExceptionSave an object state already serialized. The byte array in parameter may be modified so we must duplicate it.- Specified by:
saveInLogin classAbstractTransaction- 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:
IOException- an error occurs.
-
getFromLog
private final byte[] getFromLog(Hashtable log, Object key) throws IOException
- Throws:
IOException
-
getFromLog
private final byte[] getFromLog(String dirName, String name) throws IOException
- Throws:
IOException
-
loadByteArray
public byte[] loadByteArray(String dirName, String name) throws IOException
Description copied from interface:TransactionLoad the specified byte array.- Specified by:
loadByteArrayin interfaceTransaction- Parameters:
dirName- the directory name of the object.name- the name of the object.- Returns:
- the loaded byte array.
- Throws:
IOException- an error occurs.
-
delete
public final void delete(String dirName, String name)
Description copied from interface:TransactionDeletes the specified object.- Specified by:
deletein interfaceTransaction- Parameters:
dirName- the directory name of the object.name- the name of the object.
-
commit
public final void commit(boolean release) throws IOExceptionDescription copied from interface:TransactionCommit the current transaction.- Specified by:
commitin interfaceTransaction- Parameters:
release- if true releases the transaction at the end of the commit.- Throws:
IOException- an error occurs.
-
deleteDirectory
boolean deleteDirectory(File directoryToBeDeleted)
-
backup
public String backup(String path) throws Exception
Backups the content of Transaction module. Produces a generic Backup/Restore file containing all living objects.- Specified by:
backupin interfaceTransaction- Specified by:
backupin interfaceTransactionMBean- Parameters:
path- Directory path to store the backup.- Returns:
- the name of created backup file.
- Throws:
Exception- An error occurs during backup.
-
backupPhase1
public void backupPhase1(File backupDir, BackupFile backupFile) throws IOException
First phase of the backup: - Get all objects in repository. - Copy all log files. Need to be synchronized to avoid any transaction operation.- Throws:
IOException
-
backupPhase2
public void backupPhase2(File backupDir, RestoreFile restoreFile, BackupFile backupFile) throws IOException
Second phase of the backup, compacts all logs in one then produces a unique backup file. No need to be synchronized, should be no access on handled data.- Parameters:
backupDir-restoreFile-backupFile-- Throws:
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:
stopin interfaceTransaction
-
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:
closein interfaceTransaction
-
toString
public String toString()
Returns a string representation for this object.
-
logCounters
public String logCounters()
- Specified by:
logCountersin interfaceNGTransactionMBean
-
logContent
public String logContent(int idx) throws IOException
- Specified by:
logContentin interfaceNGTransactionMBean- Throws:
IOException
-
garbage
public void garbage(int idx) throws IOException- Specified by:
garbagein interfaceNGTransactionMBean- Throws:
IOException
-
-