public final class ATransaction extends AbstractTransaction implements ATransactionMBean, Runnable
AbstractTransaction.Context
Modifier and Type | Field and Description |
---|---|
private static ByteArrayOutputStream |
baos |
(package private) static int |
CLEANUP_THRESHOLD_COMMIT |
(package private) static int |
CLEANUP_THRESHOLD_OPERATION |
(package private) static int |
CLEANUP_THRESHOLD_SIZE |
private Hashtable |
clog
Log of all operations already commited but not reported on disk
by the "garbage" Thread.
|
private int |
commitCount
Number of commit operation since starting up.
|
private int |
cumulativeSize |
(package private) static boolean |
debug |
private static DataOutputStream |
dos |
private static byte[] |
emptyUTFString |
private boolean |
garbage |
private Thread |
gThread |
private boolean |
isRunning |
private Object |
lock |
private static String |
LOG |
protected FileDescriptor |
logFD |
protected RandomAccessFile |
logFile |
protected File |
logFilePN |
private int |
operationCount |
private Hashtable |
plog
Log currently used by "garbage" Thread, its thread reports all
operation it contents on disk, then it deletes it.
|
private static String |
PLOG |
protected File |
plogFilePN |
dir, OOS_STREAM_HEADER, perThreadContext, phase, startTime
logmon
Constructor and Description |
---|
ATransaction() |
Modifier and Type | Method and Description |
---|---|
private void |
_release() |
void |
_stop() |
String |
backup(String path)
Backups the content of Transaction module.
|
void |
close()
Close the transaction module.
|
void |
commit(boolean release)
Commit the current transaction.
|
private void |
commit(Hashtable log)
Reports all logged operations on disk.
|
void |
delete(String dirName,
String name)
Deletes the specified object.
|
private void |
deleteDir(File dir)
Delete the specified directory if it is empty.
|
int |
getCommitCount()
Returns the number of commit operation since starting up.
|
File |
getDir() |
private byte[] |
getFromLog(Hashtable log,
Object key) |
private byte[] |
getFromLog(String dirName,
String name) |
String[] |
getList(String prefix)
Returns an array of strings naming the objects in the component started by this prefix.
|
void |
initRepository() |
byte[] |
loadByteArray(String dirName,
String name)
Load the specified byte array.
|
protected void |
newLogFile() |
void |
release()
Release the mutual exclusion.
|
private void |
restart(Hashtable log,
File logFilePN) |
void |
rollback() |
void |
run() |
protected void |
saveInLog(byte[] buf,
String dirName,
String name,
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() |
begin, containsOperations, create, create, createByteArray, createByteArray, delete, getOperationCount, getPhase, getPhaseInfo, getStartTime, init, isPersistent, load, load, loadAll, loadByteArray, loadFromByteArray, save, save, save, saveByteArray, saveByteArray, saveByteArray, useLoadAll
freeze, getBoolean, getInteger, getInteger, getProperty, getProperty, loadProperties, saveProperties
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getPhase, getPhaseInfo, getStartTime, isPersistent, useLoadAll
static final int CLEANUP_THRESHOLD_COMMIT
static final int CLEANUP_THRESHOLD_OPERATION
static final int CLEANUP_THRESHOLD_SIZE
private int operationCount
private int cumulativeSize
private int commitCount
private Hashtable clog
private Hashtable plog
private static final String LOG
private static final String PLOG
protected File logFilePN
protected File plogFilePN
private boolean garbage
private Object lock
private boolean isRunning
private Thread gThread
static final boolean debug
private static final byte[] emptyUTFString
private static ByteArrayOutputStream baos
private static DataOutputStream dos
protected RandomAccessFile logFile
protected FileDescriptor logFD
public final int getCommitCount()
getCommitCount
in interface Transaction
getCommitCount
in interface TransactionMBean
public final void initRepository() throws IOException
initRepository
in class AbstractTransaction
IOException
private final void restart(Hashtable log, File logFilePN) throws IOException
IOException
public final File getDir()
protected final void setPhase(int newPhase)
AbstractTransaction
setPhase
in class AbstractTransaction
newPhase
- the new transaction state.public final String[] getList(String prefix)
Transaction
getList
in interface Transaction
prefix
- the prefix of searched objects.protected final void saveInLog(byte[] buf, String dirName, String name, Hashtable log, boolean copy, boolean first) throws IOException
AbstractTransaction
saveInLog
in class AbstractTransaction
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.IOException
- an error occurs.private final byte[] getFromLog(Hashtable log, Object key) throws IOException
IOException
private final byte[] getFromLog(String dirName, String name) throws IOException
IOException
public final byte[] loadByteArray(String dirName, String name) throws IOException
Transaction
loadByteArray
in interface Transaction
dirName
- the directory name of the object.name
- the name of the object.IOException
- an error occurs.public final void delete(String dirName, String name)
Transaction
delete
in interface Transaction
dirName
- the directory name of the object.name
- the name of the object.public void commit(boolean release) throws IOException
Transaction
commit
in interface Transaction
release
- if true releases the transaction at the end of the commit.IOException
- an error occurs.protected void newLogFile() throws IOException
IOException
protected void syncLogFile() throws IOException
IOException
public final void rollback()
public final void release() throws IOException
AbstractTransaction
release
in interface Transaction
release
in class AbstractTransaction
IOException
- an error occurs.Transaction.release()
private final void commit(Hashtable log) throws IOException
log
- the log object.IOException
- an error occurs.private final void deleteDir(File dir)
dir
- the directory to delete.public final void _stop()
public final void stop()
Transaction
stop
in interface Transaction
public void close()
close
in interface Transaction
private void _release() throws IOException
IOException
private final void wakeup() throws IOException
IOException
public String backup(String path) throws Exception
backup
in interface Transaction
backup
in interface TransactionMBean
path
- Directory path to store the backup.Exception
- An error occurs during backup.Copyright © 2021 ScalAgent D.T.. All rights reserved.