Package fr.dyade.aaa.util
Class ATransaction
- java.lang.Object
-
- fr.dyade.aaa.util.BaseTransaction
-
- fr.dyade.aaa.util.AbstractTransaction
-
- fr.dyade.aaa.util.ATransaction
-
- All Implemented Interfaces:
ATransactionMBean,Transaction,TransactionMBean,Runnable
public final class ATransaction extends AbstractTransaction implements ATransactionMBean, Runnable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class fr.dyade.aaa.util.AbstractTransaction
AbstractTransaction.Context
-
-
Field Summary
Fields Modifier and Type Field Description private static ByteArrayOutputStreambaos(package private) static intCLEANUP_THRESHOLD_COMMIT(package private) static intCLEANUP_THRESHOLD_OPERATION(package private) static intCLEANUP_THRESHOLD_SIZEprivate HashtableclogLog of all operations already commited but not reported on disk by the "garbage" Thread.private intcommitCountNumber of commit operation since starting up.private intcumulativeSize(package private) static booleandebugprivate static DataOutputStreamdosprivate static byte[]emptyUTFStringprivate booleangarbageprivate ThreadgThreadprivate booleanisRunningprivate Objectlockprivate static StringLOG_NAMEprotected FileDescriptorlogFDprotected RandomAccessFilelogFileprotected FilelogFilePNprivate intoperationCountprivate HashtableplogLog currently used by "garbage" Thread, its thread reports all operation it contents on disk, then it deletes it.private static StringPLOG_NAMEprotected FileplogFilePN-
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 ATransaction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void_release()void_stop()Stringbackup(String path)Backups the content of Transaction module.voidclose()Close the transaction module.voidcommit(boolean release)Commit the current transaction.private voidcommit(Hashtable log)Reports all logged operations on disk.voiddelete(String dirName, String name)Deletes the specified object.private voiddeleteDir(File dir)Delete the specified directory if it is empty.intgetCommitCount()Returns the number of commit operation since starting up.FilegetDir()private byte[]getFromLog(String dirName, String name)private byte[]getFromLog(Hashtable log, Object key)String[]getList(String prefix)Returns an array of strings naming the objects in the component started by this prefix.voidinitRepository()byte[]loadByteArray(String dirName, String name)Load the specified byte array.protected voidnewLogFile()voidrelease()Release the mutual exclusion.private voidrestart(Hashtable log, File logFilePN)voidrollback()voidrun()protected voidsaveInLog(byte[] buf, String dirName, String name, Hashtable log, boolean copy, boolean first)Register the specified object in transaction log.protected voidsetPhase(int newPhase)Changes the transaction state.voidstop()Stops the transaction module.protected voidsyncLogFile()private voidwakeup()-
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, 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, toString, wait, wait, wait
-
Methods inherited from interface fr.dyade.aaa.util.TransactionMBean
dumpObjectList, getObject, getObjectList, getPhase, getPhaseInfo, getStartTime, isPersistent, useLoadAll
-
-
-
-
Field Detail
-
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
-
operationCount
private int operationCount
-
cumulativeSize
private int cumulativeSize
-
commitCount
private int commitCount
Number of commit operation since starting up.
-
clog
private 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 Hashtable plog
Log currently used by "garbage" Thread, its thread reports all operation it contents on disk, then it deletes it.
-
LOG_NAME
private static final String LOG_NAME
- See Also:
- Constant Field Values
-
PLOG_NAME
private static final String PLOG_NAME
- See Also:
- Constant Field Values
-
logFilePN
protected File logFilePN
-
plogFilePN
protected File plogFilePN
-
garbage
private boolean garbage
-
lock
private Object lock
-
isRunning
private boolean isRunning
-
gThread
private Thread gThread
-
debug
static final boolean debug
- See Also:
- Constant Field Values
-
emptyUTFString
private static final byte[] emptyUTFString
-
baos
private static ByteArrayOutputStream baos
-
dos
private static DataOutputStream dos
-
logFile
protected RandomAccessFile logFile
-
logFD
protected FileDescriptor logFD
-
-
Method Detail
-
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.
-
initRepository
public final void initRepository() throws IOException- Specified by:
initRepositoryin classAbstractTransaction- Throws:
IOException
-
restart
private final void restart(Hashtable log, File logFilePN) throws IOException
- Throws:
IOException
-
getDir
public final File getDir()
-
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 final String[] getList(String prefix)
Description copied from interface:TransactionReturns an array of strings naming the objects in the component started by this prefix.- Specified by:
getListin interfaceTransaction- Parameters:
prefix- the prefix of searched objects.- Returns:
- an array of strings naming the objects in the component started by this prefix.
-
saveInLog
protected final void saveInLog(byte[] buf, String dirName, String name, Hashtable log, boolean copy, boolean first) throws IOExceptionDescription copied from class:AbstractTransactionRegister the specified object in transaction log.- 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 final 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 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.
-
newLogFile
protected void newLogFile() throws IOException- Throws:
IOException
-
syncLogFile
protected void syncLogFile() throws IOException- Throws:
IOException
-
rollback
public final void rollback()
-
release
public final void release() throws IOExceptionDescription copied from class:AbstractTransactionRelease the mutual exclusion.- Specified by:
releasein interfaceTransaction- Overrides:
releasein classAbstractTransaction- Throws:
IOException- an error occurs.- See Also:
Transaction.release()
-
commit
private final void commit(Hashtable log) throws IOException
Reports all logged operations on disk.- Parameters:
log- the log object.- Throws:
IOException- an error occurs.
-
deleteDir
private final void deleteDir(File dir)
Delete the specified directory if it is empty. Also recursively delete the parent directories if they are empty.- Parameters:
dir- the directory to delete.
-
_stop
public final void _stop()
-
stop
public final void stop()
Description copied from interface:TransactionStops the transaction module. It waits all transactions termination, then the module is kept in a FREE 'ready to use' state.- 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.- Specified by:
closein interfaceTransaction
-
_release
private void _release() throws IOException- Throws:
IOException
-
wakeup
private final void wakeup() throws IOException- Throws:
IOException
-
backup
public String backup(String path) throws Exception
Backups the content of Transaction module. Produces a generic Backup/Restore file containing all living objects. Currently not implemented, throws an UnsupportedOperationException.- 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.
-
-