public abstract class AbstractTransaction extends BaseTransaction
Transaction
Modifier and Type | Class and Description |
---|---|
class |
AbstractTransaction.Context |
Modifier and Type | Field and Description |
---|---|
protected File |
dir |
private static byte |
ENCODING_TAG |
private static byte |
JAVA_SERIALIZATION_TAG |
private boolean |
onlyUseJavaSerialization |
protected static byte[] |
OOS_STREAM_HEADER
The OOS_STREAM_HEADER allows to reset an ObjectOutputStream built on top of
a ByteArrayOutputStream.
|
protected ThreadLocal<AbstractTransaction.Context> |
perThreadContext
ThreadLocal variable used to get the log to associate state with each
thread.
|
protected int |
phase |
protected long |
startTime |
logmon
Constructor and Description |
---|
AbstractTransaction() |
Modifier and Type | Method and Description |
---|---|
void |
begin()
Start a transaction validation, the validation phase needs 3 phases: begin, commit
and release.
|
boolean |
containsOperations()
Indicates whether some operations have been done in
this transaction.
|
void |
create(Serializable obj,
String name)
Register the state of a newly created object in the current transaction.
|
void |
create(Serializable obj,
String dirName,
String name)
Register the state of a newly created object in the current transaction.
|
void |
createByteArray(byte[] buf,
String name)
Register a new byte array in the current transaction.
|
void |
createByteArray(byte[] buf,
String dirName,
String name)
Register a new byte array in the current transaction.
|
private Object |
decode(byte[] buf,
int offset) |
void |
delete(String name)
Deletes the specified object.
|
private Object |
deserialize(byte[] buf,
int offset) |
int |
getOperationCount()
Returns the number of operations to be committed.
|
int |
getPhase()
Returns the transaction state.
|
String |
getPhaseInfo()
Returns a string representation of the transaction state.
|
long |
getStartTime()
Returns the starting time.
|
void |
init(String path)
Initializes the atomic storage component.
|
abstract void |
initRepository() |
private Encodable |
isEncodable(Object object) |
boolean |
isPersistent()
Tests if the Transaction component is persistent.
|
Object |
load(String name)
Load the specified object.
|
Object |
load(String dirName,
String name)
Load the specified object.
|
void |
loadAll(String prefix,
Map map)
Fills the map with all objects of the component whose name begins with the prefix.
|
byte[] |
loadByteArray(String name)
Load the specified byte array.
|
protected Object |
loadFromByteArray(byte[] buf) |
void |
release()
Release the mutual exclusion.
|
void |
save(Serializable obj,
String name)
Register the modified state of an object in the current transaction.
|
void |
save(Serializable obj,
String dirName,
String name)
Register the modified state of an object in the current transaction.
|
void |
save(Serializable obj,
String dirName,
String name,
boolean first)
Register the state of an object in the current transaction.
|
void |
saveByteArray(byte[] buf,
String name)
Register a modified byte array in the current transaction.
|
void |
saveByteArray(byte[] buf,
String dirName,
String name)
Register a modified byte array in the current transaction.
|
void |
saveByteArray(byte[] buf,
String dirName,
String name,
boolean copy,
boolean first)
Register a modified byte array in the current transaction.
|
protected abstract void |
saveInLog(byte[] buf,
String dirName,
String name,
Hashtable log,
boolean copy,
boolean first)
Register the specified object in transaction log.
|
private byte[] |
serialize(Serializable obj,
AbstractTransaction.Context ctx) |
protected abstract void |
setPhase(int newPhase)
Changes the transaction state.
|
boolean |
useLoadAll()
Returns true if this Transaction implementation implements an optimized loadAll method.
|
freeze, getBoolean, getInteger, getInteger, getProperty, getProperty, loadProperties, saveProperties
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close, commit, delete, getCommitCount, getList, loadByteArray, stop
private static final byte JAVA_SERIALIZATION_TAG
private static final byte ENCODING_TAG
private boolean onlyUseJavaSerialization
protected long startTime
protected int phase
protected File dir
protected ThreadLocal<AbstractTransaction.Context> perThreadContext
commit
. On commit, its content is added to current
log (clog, memory + disk), then it is freed.protected static final byte[] OOS_STREAM_HEADER
public long getStartTime()
public final boolean isPersistent()
public final int getPhase()
Transaction.getPhase()
public final String getPhaseInfo()
Transaction.getPhaseInfo()
protected abstract void setPhase(int newPhase) throws IOException
newPhase
- the new transaction state.IOException
- an error occurs.public abstract void initRepository() throws IOException
IOException
public final void init(String path) throws IOException
Transaction
path
- the path of storage directory.IOException
- an error occurs.public final void begin() throws IOException
IOException
- an error occurs.Transaction.begin()
public final void create(Serializable obj, String name) throws IOException
obj
- the object to store.name
- the name of the object.IOException
- an error occurs.Transaction.create(java.io.Serializable, java.lang.String)
public final void create(Serializable obj, String dirName, String name) throws IOException
obj
- the object to store.dirName
- the directory name of the object.name
- the name of the object.IOException
- an error occurs.Transaction.create(java.io.Serializable, java.lang.String, java.lang.String)
public final void save(Serializable obj, String name) throws IOException
obj
- the object to store.name
- the name of the object.IOException
- an error occurs.Transaction.save(java.io.Serializable, java.lang.String)
public final void save(Serializable obj, String dirName, String name) throws IOException
obj
- the object to store.dirName
- the directory name of the object.name
- the name of the object.IOException
- an error occurs.Transaction.save(java.io.Serializable, java.lang.String, java.lang.String)
private byte[] serialize(Serializable obj, AbstractTransaction.Context ctx) throws IOException
IOException
public final void save(Serializable obj, String dirName, String name, boolean first) throws IOException
obj
- the object to store.dirName
- the directory name of the object.name
- the name of the object.first
- the object is a new one.IOException
- an error occurs.Transaction.save(java.io.Serializable, java.lang.String, java.lang.String, boolean)
public final void createByteArray(byte[] buf, String name) throws IOException
buf
- the byte array to store.name
- the name of the object.IOException
- an error occurs.Transaction.createByteArray(byte[], java.lang.String)
public final void createByteArray(byte[] buf, String dirName, String name) throws IOException
buf
- the byte array to store.dirName
- the directory name of the object.name
- the name of the object.IOException
- an error occurs.Transaction.createByteArray(byte[], java.lang.String, java.lang.String)
public final void saveByteArray(byte[] buf, String name) throws IOException
buf
- the byte array to store.name
- the name of the object.IOException
- an error occurs.Transaction.saveByteArray(byte[], java.lang.String)
public final void saveByteArray(byte[] buf, String dirName, String name) throws IOException
buf
- the byte array to store.dirName
- the directory name of the object.name
- the name of the object.IOException
- an error occurs.Transaction.saveByteArray(byte[], java.lang.String, java.lang.String)
public final void saveByteArray(byte[] buf, String dirName, String name, boolean copy, boolean first) throws IOException
buf
- the byte array to store.dirName
- the directory name of the object.name
- the name of the object.copy
- the byte array can be modified, copy it.first
- the object is a new one.IOException
- an error occurs.Transaction.saveByteArray(byte[], java.lang.String, java.lang.String, boolean, boolean)
protected abstract void saveInLog(byte[] buf, String dirName, String name, Hashtable log, boolean copy, boolean first) throws IOException
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.public final Object load(String name) throws IOException, ClassNotFoundException
name
- the name of the object.IOException
- an error occurs.ClassNotFoundException
- an error occurs.Transaction.load(java.lang.String)
public final Object load(String dirName, String name) throws IOException, ClassNotFoundException
dirName
- the directory name of the object.name
- the name of the object.IOException
- an error occurs.ClassNotFoundException
- an error occurs.Transaction.load(java.lang.String, java.lang.String)
public boolean useLoadAll()
public void loadAll(String prefix, Map map)
prefix
- The prefix of searched objects.map
- The map of corresponding objects.protected final Object loadFromByteArray(byte[] buf) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
private Object deserialize(byte[] buf, int offset) throws IOException, ClassNotFoundException
IOException
ClassNotFoundException
private Object decode(byte[] buf, int offset) throws IOException
IOException
public final byte[] loadByteArray(String name) throws IOException
name
- the name of the object.IOException
- an error occurs.Transaction.loadByteArray(java.lang.String)
public final void delete(String name)
name
- the name of the object.Transaction.delete(java.lang.String)
public void release() throws IOException
IOException
- an error occurs.Transaction.release()
public boolean containsOperations()
public int getOperationCount()
Copyright © 2020 ScalAgent D.T.. All rights reserved.