org.apache.commons.transaction.file
Class FileSequence

java.lang.Object
  extended by org.apache.commons.transaction.file.FileSequence

public class FileSequence
extends Object

Fail-Safe sequence store implementation using the file system. Works by versioning values of sequences and throwing away all versions, but the current and the previous one.

Version:
$Revision$

Field Summary
protected  LoggerFacade logger
           
protected  String storeDir
           
 
Constructor Summary
FileSequence(String storeDir, LoggerFacade logger)
          Creates a new resouce manager operation on the specified directories.
 
Method Summary
 boolean create(String sequenceName, long initialValue)
          Creates a sequence if it does not already exist.
 boolean delete(String sequenceName)
          Deletes a sequence if it exists.
 boolean exists(String sequenceName)
          Checks if the sequence already exists.
protected  String getPathI(String sequenceName)
           
protected  String getPathII(String sequenceName)
           
 long nextSequenceValueBottom(String sequenceName, long increment)
          Gets the next value of the sequence.
protected  long read(String sequenceName)
           
protected  long readFromPath(String path)
           
protected  void write(String sequenceName, long value)
           
protected  void writeToPath(String path, long value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storeDir

protected final String storeDir

logger

protected final LoggerFacade logger
Constructor Detail

FileSequence

public FileSequence(String storeDir,
                    LoggerFacade logger)
             throws ResourceManagerException
Creates a new resouce manager operation on the specified directories.

Parameters:
storeDir - directory where sequence information is stored
logger - logger used for warnings only
Throws:
ResourceManagerException
Method Detail

exists

public boolean exists(String sequenceName)
Checks if the sequence already exists.

Parameters:
sequenceName - the name of the sequence you want to check
Returns:
true if the sequence already exists, false otherwise

create

public boolean create(String sequenceName,
                      long initialValue)
               throws ResourceManagerException
Creates a sequence if it does not already exist.

Parameters:
sequenceName - the name of the sequence you want to create
Returns:
true if the sequence has been created, false if it already existed
Throws:
ResourceManagerException - if anything goes wrong while accessing the sequence

delete

public boolean delete(String sequenceName)
Deletes a sequence if it exists.

Parameters:
sequenceName - the name of the sequence you want to delete
Returns:
true if the sequence has been deleted, false if not

nextSequenceValueBottom

public long nextSequenceValueBottom(String sequenceName,
                                    long increment)
                             throws ResourceManagerException
Gets the next value of the sequence.

Parameters:
sequenceName - the name of the sequence you want the next value for
increment - the increment for the sequence, i.e. how much to add to the sequence with this call
Returns:
the next value of the sequence not yet incremented, i.e. the increment is recorded internally, but not returned with the next call to this method
Throws:
ResourceManagerException - if anything goes wrong while accessing the sequence

read

protected long read(String sequenceName)
             throws ResourceManagerException
Throws:
ResourceManagerException

write

protected void write(String sequenceName,
                     long value)
              throws ResourceManagerException
Throws:
ResourceManagerException

getPathI

protected String getPathI(String sequenceName)

getPathII

protected String getPathII(String sequenceName)

readFromPath

protected long readFromPath(String path)
                     throws ResourceManagerException,
                            NumberFormatException,
                            FileNotFoundException,
                            IOException
Throws:
ResourceManagerException
NumberFormatException
FileNotFoundException
IOException

writeToPath

protected void writeToPath(String path,
                           long value)
                    throws ResourceManagerException
Throws:
ResourceManagerException


Copyright ? 2004 The Apache Software Foundation. All Rights Reserved.