| java.lang.Object org.apache.commons.transaction.file.FileResourceManager
FileResourceManager | public class FileResourceManager implements ResourceManager,ResourceManagerErrorCodes(Code) | | A resource manager for streamable objects stored in a file system.
It is intended for developer and "out of the box" use.
It is not intended to be a real alternative for
a full blown DMBS (of course it can not be compared to a RDBMS at all).
Major features:
- Transactions performed with this class more or less comform to the widely accepted ACID properties
- Reading should be as fast as from the ordinary file system (at the cost of a bit slower commits)
Compared to a "real" DBMS major limitations are (in order of assumed severity):
- Number of simultaneously open resources is limited to the number of available file descriptors
- It does not scale a bit
- Pessimistic transaction and locking scheme
- Isolation level currently is restricted to read committed and repeated read (which is not that bad)
Important: If possible you should have the work and store directory located in the
same file system. If not, you might get additional problems, as there are:
- On commit it might be necessay to copy files instead of rename/relink them. This may lead to time consuming,
overly blocking commit phases and higher risk of corrupted files
- Prepare phase might be too permissive, no check for sufficient memory on store file system is possible
General limitations include:
- Due to lack of synchronization on the transaction context level, every transaction may only be
accessed by a single thread throughout its full life.
This means it is forbidden for a thread that has not started a transaction
to perform any operations inside this transaction. However, threads associated
with different transactions can safely access these methods concurrently.
Reasons for the lack of synchronization are improved performance and simplicity (of the code of this class).
- There is no dedicated class for a transaction. Having such a class would be better practice and
make certain actions more intuitive.
- Resource identifiers need a reasonsable string representation obtainable by
toString .
More specifically, they will have to resolve to a valid file path that does note denote a directory.
If it does, you might be able to create it, but not to read or write anything
from resp. to it. Valid string representations of a resource idenfier are
for example "file" "/root" or "hjfhdfhuhuhsdufhdsufhdsufhdfuhdfduhduhduhdu".
Invalid are for example "/" or "/root/". Invalid on some file systems are for example "c:" or "file://huhu".
- As there are no active processes inside this RM and it shares its threads with the application,
control over transactions is limited to points where the application calls the RM.
In particular, this disables active termination of transactions upon timeout.
- There is no notion of a connection to this file manager. This means you can not connect from hosts other than
local and you will get problems when plugging this store into a J2EE store using connectors.
- Methods should throw more specific exceptions
Caution:
The txId passed to many methods as an identifier for the
transaction concerned will function as a key in a HashMap .
Thus assure that equals and hashCode are both
properly implemented and match each other.
Caution:
You will have to guarantee that no other process will access neither
the store or the working dir concurrently to this FileResourceManager .
Special Caution:
Be very careful not to have two instances of FileResourceManager
working in the same store and/or working dir.
version: $Id: FileResourceManager.java 509474 2007-02-20 09:04:22Z antoine $ |
Inner Class :protected class TransactionContext | |
Constructor Summary | |
public | FileResourceManager(String storeDir, String workDir, boolean urlEncodePath, LoggerFacade logger) Creates a new resource manager operation on the specified directories. | public | FileResourceManager(String storeDir, String workDir, boolean urlEncodePath, LoggerFacade logger, boolean debug) Creates a new resource manager operation on the specified directories. | public | FileResourceManager(String storeDir, String workDir, ResourceIdToPathMapper idMapper, LoggerFacade logger, boolean debug) Creates a new resource manager operation on the specified directories. | public | FileResourceManager(String storeDir, String workDir, ResourceIdToPathMapper idMapper, TransactionIdToPathMapper txIdMapper, LoggerFacade logger, boolean debug) Creates a new resource manager operation on the specified directories. |
Method Summary | |
protected static void | applyDeletes(File removeDir, File targetDir, File rootDir) | protected String | assureLeadingSlash(Object pathObject) | protected void | assureNotMarkedForRollback(TransactionContext context) | protected void | assureRMReady() | protected void | assureStarted() | protected void | closeOpenResource(Object openResource) | public void | commitTransaction(Object txId) | public void | copyResource(Object txId, Object fromResourceId, Object toResourceId, boolean overwrite) | public void | createResource(Object txId, Object resourceId) | public void | createResource(Object txId, Object resourceId, boolean assureOnly) | public void | deleteResource(Object txId, Object resourceId) | public void | deleteResource(Object txId, Object resourceId, boolean assureOnly) | protected void | fileInitialSaneCheck(Object txId, Object path) | public String | generatedUniqueTxId() Generates a transaction identifier unique to this resource manager. | protected String | getChangePath(Object txId, Object path) | protected TransactionContext | getContext(Object txId) | public int | getDefaultIsolationLevel() | public long | getDefaultTransactionTimeout() Gets the default transaction timeout in milliseconds. | protected String | getDeletePath(Object txId, Object path) | public int | getIsolationLevel(Object txId) | public LoggerFacade | getLogger() Gets the logger used by this resource manager. | protected String | getMainPath(Object path) | protected String | getPathForRead(Object txId, Object resourceId) | protected String | getPathForWrite(Object txId, Object resourceId) | protected int | getSharedLockLevel(TransactionContext context) | public String | getStoreDir() Gets the store directory. | public int[] | getSupportedIsolationLevels() | protected String | getTransactionBaseDir(Object txId) | public int | getTransactionState(Object txId) | public long | getTransactionTimeout(Object txId) | public String | getWorkDir() Gets the working directory. | public boolean | isIsolationLevelSupported(int level) | public boolean | lockResource(Object resourceId, Object txId) | public boolean | lockResource(Object resourceId, Object txId, boolean shared) | public boolean | lockResource(Object resourceId, Object txId, boolean shared, boolean wait, long timeoutMSecs, boolean reentrant) | public void | markTransactionForRollback(Object txId) | public void | moveResource(Object txId, Object fromResourceId, Object toResourceId, boolean overwrite) | public int | prepareTransaction(Object txId) | public InputStream | readResource(Object resourceId) | public InputStream | readResource(Object txId, Object resourceId) | public synchronized boolean | recover() | protected void | recoverContexts() | protected void | registerOpenResource(Object openResource) | protected void | releaseGlobalOpenResources() | public synchronized void | reset() Resets the store by deleting work and store directory. | public boolean | resourceExists(Object resourceId) | public boolean | resourceExists(Object txId, Object resourceId) | protected boolean | rollBackOrForward() | public void | rollbackTransaction(Object txId) | public void | setDefaultTransactionTimeout(long timeout) Sets the default transaction timeout. | protected void | setDirty(Object txId, Throwable t) | public void | setIsolationLevel(Object txId, int level) | public void | setTransactionTimeout(Object txId, long mSecs) | protected boolean | shutdown(int mode, long timeoutMSecs) | public synchronized void | start() | public void | startTransaction(Object txId) | public synchronized boolean | stop(int mode) | public synchronized boolean | stop(int mode, long timeOut) | public synchronized void | sync() Synchronizes persistent data with caches. | protected TransactionContext | txInitialSaneCheck(Object txId) | protected TransactionContext | txInitialSaneCheckForWriting(Object txId) | protected boolean | undoScheduledChangeOrCreate(Object txId, Object resourceId) | protected boolean | undoScheduledDelete(Object txId, Object resourceId) | protected boolean | waitForAllTxToStop(long timeoutMSecs) | public OutputStream | writeResource(Object txId, Object resourceId) | public OutputStream | writeResource(Object txId, Object resourceId, boolean append) |
CONTEXT_FILE | final protected static String CONTEXT_FILE(Code) | | |
DEFAULT_COMMIT_TIMEOUT_FACTOR | final protected static int DEFAULT_COMMIT_TIMEOUT_FACTOR(Code) | | |
DEFAULT_ISOLATION_LEVEL | final protected static int DEFAULT_ISOLATION_LEVEL(Code) | | |
DEFAULT_PARAMETER_ENCODING | final protected static String DEFAULT_PARAMETER_ENCODING(Code) | | |
DEFAULT_TIMEOUT_MSECS | final protected static int DEFAULT_TIMEOUT_MSECS(Code) | | |
LOCK_ACCESS | final protected static int LOCK_ACCESS(Code) | | |
LOCK_COMMIT | final protected static int LOCK_COMMIT(Code) | | |
LOCK_EXCLUSIVE | final protected static int LOCK_EXCLUSIVE(Code) | | |
LOCK_SHARED | final protected static int LOCK_SHARED(Code) | | |
NATIVE_ISOLATION_LEVEL | final protected static int NATIVE_ISOLATION_LEVEL(Code) | | |
NO_LOCK | final protected static int NO_LOCK(Code) | | |
OPERATION_MODE_RECOVERING | final protected static int OPERATION_MODE_RECOVERING(Code) | | |
OPERATION_MODE_STARTED | final protected static int OPERATION_MODE_STARTED(Code) | | |
OPERATION_MODE_STARTING | final protected static int OPERATION_MODE_STARTING(Code) | | |
OPERATION_MODE_STOPPED | final protected static int OPERATION_MODE_STOPPED(Code) | | |
OPERATION_MODE_STOPPING | final protected static int OPERATION_MODE_STOPPING(Code) | | |
WORK_CHANGE_DIR | final protected static String WORK_CHANGE_DIR(Code) | | |
WORK_DELETE_DIR | final protected static String WORK_DELETE_DIR(Code) | | |
cleanUp | protected boolean cleanUp(Code) | | |
debug | protected boolean debug(Code) | | |
defaultTimeout | protected long defaultTimeout(Code) | | |
dirty | protected boolean dirty(Code) | | |
globalOpenResources | protected List globalOpenResources(Code) | | |
globalTransactions | protected Map globalTransactions(Code) | | |
idCnt | protected int idCnt(Code) | | |
operationMode | protected int operationMode(Code) | | |
FileResourceManager | public FileResourceManager(String storeDir, String workDir, boolean urlEncodePath, LoggerFacade logger)(Code) | | Creates a new resource manager operation on the specified directories.
Parameters: storeDir - directory where main data should go after commit Parameters: workDir - directory where transactions store temporary data Parameters: urlEncodePath - if set to true encodes all paths to allow for any kind of characters Parameters: logger - the logger to be used by this store |
FileResourceManager | public FileResourceManager(String storeDir, String workDir, boolean urlEncodePath, LoggerFacade logger, boolean debug)(Code) | | Creates a new resource manager operation on the specified directories.
Parameters: storeDir - directory where main data should go after commit Parameters: workDir - directory where transactions store temporary data Parameters: urlEncodePath - if set to true encodes all paths to allow for any kind of characters Parameters: logger - the logger to be used by this store Parameters: debug - if set to true logs all locking information to "transaction.log" for debugging inspection |
FileResourceManager | public FileResourceManager(String storeDir, String workDir, ResourceIdToPathMapper idMapper, LoggerFacade logger, boolean debug)(Code) | | Creates a new resource manager operation on the specified directories.
This constructor is reintroduced for backwards API compatibility and is used by jakarta-slide.
Parameters: storeDir - directory where main data should go after commit Parameters: workDir - directory where transactions store temporary data Parameters: idMapper - mapper for resourceId to path Parameters: logger - the logger to be used by this store Parameters: debug - if set to true logs all locking information to "transaction.log" for debugging inspection |
FileResourceManager | public FileResourceManager(String storeDir, String workDir, ResourceIdToPathMapper idMapper, TransactionIdToPathMapper txIdMapper, LoggerFacade logger, boolean debug)(Code) | | Creates a new resource manager operation on the specified directories.
Parameters: storeDir - directory where main data should go after commit Parameters: workDir - directory where transactions store temporary data Parameters: idMapper - mapper for resourceId to path Parameters: txIdMapper - mapper for transaction id to path Parameters: logger - the logger to be used by this store Parameters: debug - if set to true logs all locking information to "transaction.log" for debugging inspection |
closeOpenResource | protected void closeOpenResource(Object openResource)(Code) | | |
getContext | protected TransactionContext getContext(Object txId)(Code) | | |
getDefaultIsolationLevel | public int getDefaultIsolationLevel()(Code) | | |
getDefaultTransactionTimeout | public long getDefaultTransactionTimeout()(Code) | | Gets the default transaction timeout in milliseconds.
|
getLogger | public LoggerFacade getLogger()(Code) | | Gets the logger used by this resource manager.
used logger |
recoverContexts | protected void recoverContexts()(Code) | | |
registerOpenResource | protected void registerOpenResource(Object openResource)(Code) | | |
releaseGlobalOpenResources | protected void releaseGlobalOpenResources()(Code) | | |
reset | public synchronized void reset()(Code) | | Resets the store by deleting work and store directory.
|
rollBackOrForward | protected boolean rollBackOrForward()(Code) | | |
setDefaultTransactionTimeout | public void setDefaultTransactionTimeout(long timeout)(Code) | | Sets the default transaction timeout.
Parameters: timeout - timeout in milliseconds |
shutdown | protected boolean shutdown(int mode, long timeoutMSecs)(Code) | | |
sync | public synchronized void sync() throws ResourceManagerSystemException(Code) | | Synchronizes persistent data with caches. Is implemented with an empty
body, but called by other methods relying on synchronization. Subclasses
that utilize caching must implement this method reasonably.
throws: ResourceManagerSystemException - if anything fatal hapened during synchonization |
waitForAllTxToStop | protected boolean waitForAllTxToStop(long timeoutMSecs)(Code) | | |
|
|