Class FileSystemStore

java.lang.Object
com.arjuna.ats.arjuna.objectstore.ObjectStore
com.arjuna.ats.internal.arjuna.objectstore.FileSystemStore
All Implemented Interfaces:
BaseStore, ObjectStoreAPI, ParticipantStore, RecoveryStore, TxLog
Direct Known Subclasses:
FileLockingStore, LogStore, ShadowingStore

public abstract class FileSystemStore extends ObjectStore
The basic class for file system object stores. This is not actually an object store implementation, since other classes must provide implementations of the abstract methods. It does provide implementations of common methods though.
Since:
JTS 1.0.
Version:
$Id: FileSystemStore.java 2342 2006-03-30 13:06:17Z $
Author:
Mark Little (mark@arjuna.com)
  • Field Details

    • syncWrites

      protected boolean syncWrites
    • doSync

      protected volatile boolean doSync
    • scanZeroLengthFiles

      protected boolean scanZeroLengthFiles
  • Constructor Details

  • Method Details

    • getStoreName

      public String getStoreName()
      Returns:
      the "name" of the object store. Where in the hierarchy it appears, e.g., /ObjectStore/MyName/...
    • read_committed

      public InputObjectState read_committed(Uid storeUid, String tName) throws ObjectStoreException
      Description copied from interface: ParticipantStore
      Read the object's committed state.
      Parameters:
      storeUid - The object to work on.
      tName - The type of the object to work on.
      Returns:
      the state of the object.
      Throws:
      ObjectStoreException
    • read_uncommitted

      public InputObjectState read_uncommitted(Uid storeUid, String tName) throws ObjectStoreException
      Description copied from interface: ParticipantStore
      Read the object's shadowed state.
      Parameters:
      storeUid - The object to work on.
      tName - The type of the object to work on.
      Returns:
      the state of the object.
      Throws:
      ObjectStoreException
    • remove_committed

      public boolean remove_committed(Uid storeUid, String tName) throws ObjectStoreException
      Description copied from interface: TxLog
      Remove the object's committed state.
      Parameters:
      storeUid - The object to work on.
      tName - The type of the object to work on.
      Returns:
      true if no errors occurred, false otherwise.
      Throws:
      ObjectStoreException
    • remove_uncommitted

      public boolean remove_uncommitted(Uid storeUid, String tName) throws ObjectStoreException
      Description copied from interface: ParticipantStore
      Remove the object's uncommitted state.
      Parameters:
      storeUid - The object to work on.
      tName - The type of the object to work on.
      Returns:
      true if no errors occurred, false otherwise.
      Throws:
      ObjectStoreException
    • write_committed

      public boolean write_committed(Uid storeUid, String tName, OutputObjectState state) throws ObjectStoreException
      Description copied from interface: TxLog
      Write a new copy of the object's committed state.
      Parameters:
      storeUid - The object to work on.
      tName - The type of the object to work on.
      state - The state to write.
      Returns:
      true if no errors occurred, false otherwise.
      Throws:
      ObjectStoreException
    • write_uncommitted

      public boolean write_uncommitted(Uid storeUid, String tName, OutputObjectState state) throws ObjectStoreException
      Description copied from interface: ParticipantStore
      Write a copy of the object's uncommitted state.
      Parameters:
      storeUid - The object to work on.
      tName - The type of the object to work on.
      state - The state to write.
      Returns:
      true if no errors occurred, false otherwise.
      Throws:
      ObjectStoreException
    • allObjUids

      public boolean allObjUids(String tName, InputObjectState state, int match) throws ObjectStoreException
      Given a type name initialise the state to contains all of the Uids of objects of that type
      Parameters:
      tName - The type to scan for.
      state - The object state in which to store the Uids
      match - The file type to look for (e.g., committed, shadowed). [StateStatus] Note: m=OS_UNKNOWN matches any state.
      Returns:
      true if no errors occurred, false otherwise.
      Throws:
      ObjectStoreException
    • allTypes

      public boolean allTypes(InputObjectState foundTypes) throws ObjectStoreException
      Description copied from interface: RecoveryStore
      Obtain all types of objects stored in the object store.
      Parameters:
      foundTypes - The state in which to store the types.
      Returns:
      true if no errors occurred, false otherwise.
      Throws:
      ObjectStoreException
    • read_state

      protected abstract InputObjectState read_state(Uid u, String tn, int s) throws ObjectStoreException
      Throws:
      ObjectStoreException
    • remove_state

      protected abstract boolean remove_state(Uid u, String tn, int s) throws ObjectStoreException
      Throws:
      ObjectStoreException
    • write_state

      protected abstract boolean write_state(Uid u, String tn, OutputObjectState buff, int s) throws ObjectStoreException
      Throws:
      ObjectStoreException
    • synchronousWrites

      protected final boolean synchronousWrites()
      Are synchronous write enabled?
    • lock

      protected boolean lock(File fd, int lmode, boolean create)
      Lock the file in the object store.
    • unlock

      protected boolean unlock(File fd)
      Unlock the file in the object store.
    • closeAndUnlock

      protected boolean closeAndUnlock(File fd, FileInputStream ifile, FileOutputStream ofile)
      Unlock and close the file. Note that if the unlock fails we set the return value to false to indicate an error but rely on the close to really do the unlock.
    • openAndLock

      protected File openAndLock(String fname, int lmode, boolean create) throws ObjectStoreException
      Throws:
      ObjectStoreException
    • renameFromTo

      protected final boolean renameFromTo(File from, File to)
    • renameFromToInternal

      protected final boolean renameFromToInternal(File from, File to)
    • allTypes

      protected boolean allTypes(OutputObjectState foundTypes, String root) throws ObjectStoreException
      Throws:
      ObjectStoreException
    • genPathName

      protected String genPathName(Uid objUid, String tName, int ostype) throws ObjectStoreException
      Returns:
      the file name for the state of the object identified by the Uid and TypeName. If the StateType argument is OS_SHADOW then the Uid part of the name includes # characters. The magic number SLOP below is the number of extra characters needed to make up the entire path.
      Throws:
      ObjectStoreException
    • supressEntry

      protected boolean supressEntry(String name)
      Description copied from class: ObjectStore
      Suppress directories of the specified type from allTypes etc?
      Specified by:
      supressEntry in class ObjectStore
    • truncate

      protected String truncate(String value)
    • createHierarchy

      protected final boolean createHierarchy(String path) throws ObjectStoreException
      Attempt to build up the object store in the file system dynamically. This creates directories as required as new types are added to the store. Note that we made sure the root object store was created and writable at construction time. WARNING: on a multi-processor box it is possible that multiple threads may try to create the same hierarchy at the same time. What will tend to happen is that one thread will succeed and the other(s) will fail. However, if a failed thread just assumes that the directory is being created by another thread, then we're in trouble, because although this may be the case, the directory structure may not have actually been created - it may still be in the process of being created. So, we have to err on the side of caution and try to create the directory a few times. (This can happen across processes too.)
      Throws:
      ObjectStoreException
    • exists

      protected final boolean exists(String path)
      If this object store implementation is exclusively working on a set of object states, then this method will check a file cache first. Otherwise, we must go back to the file system each time to check the status of the file. If we add a FileDescriptor cache a la the C++ version then we would be able to get rid of the state cache and simply check to see if we had a fd for it.
    • addToCache

      protected final void addToCache(String fname)
    • removeFromCache

      protected final void removeFromCache(String fname)
    • removeFromCache

      protected final void removeFromCache(String fname, boolean warn)
      Print a warning if the file to be removed is not in the cache.
      Since:
      2.1.1.