org.prevayler.implementation
Class PrevaylerDirectory

java.lang.Object
  extended by org.prevayler.implementation.PrevaylerDirectory

public class PrevaylerDirectory
extends Object


Constructor Summary
PrevaylerDirectory(File directory)
           
PrevaylerDirectory(String directory)
           
 
Method Summary
static void checkValidJournalSuffix(String suffix)
          Ensure that the given suffix (which should not include a dot) is valid for journals.
static void checkValidSnapshotSuffix(String suffix)
          Ensure that the given suffix (which should not include a dot) is valid for snapshots.
 File createTempFile(String prefix, String suffix)
          Create a temporary file in the directory.
 File findInitialJournalFile(long initialTransactionWanted)
          Find the journal file containing the desired transaction.
 File journalFile(long transaction, String suffix)
          Generate a valid journal filename.
static long journalVersion(File file)
          Extract the version number from a journal filename.
 File latestSnapshot()
          Find the latest snapshot file.
 Set necessaryFiles()
          Determine which snapshot and journal files are still necessary for recovery.
 void produceDirectory()
          Ensure that the directory exists, creating it and parent directories if necessary.
static void renameUnusedFile(File journalFile)
          Rename a journal file to indicate it was found empty and is being ignored.
 File snapshotFile(long version, String suffix)
          Generate a valid snapshot filename.
static long snapshotVersion(File file)
          Extract the version number from a snapshot filename.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrevaylerDirectory

public PrevaylerDirectory(String directory)

PrevaylerDirectory

public PrevaylerDirectory(File directory)
Method Detail

produceDirectory

public void produceDirectory()
                      throws IOException
Ensure that the directory exists, creating it and parent directories if necessary.

Throws:
IOException - if the directory can't be created or isn't a directory.

checkValidSnapshotSuffix

public static void checkValidSnapshotSuffix(String suffix)
Ensure that the given suffix (which should not include a dot) is valid for snapshots. Snapshot suffixes must match the pattern /[a-zA-Z0-9]*[Ss]napshot/.

Throws:
IllegalArgumentException - otherwise.

checkValidJournalSuffix

public static void checkValidJournalSuffix(String suffix)
Ensure that the given suffix (which should not include a dot) is valid for journals. Journal suffixes must match the pattern /[a-zA-Z0-9]*[Jj]ournal/.

Throws:
IllegalArgumentException - otherwise.

snapshotFile

public File snapshotFile(long version,
                         String suffix)
Generate a valid snapshot filename.

Throws:
IllegalArgumentException - if the version is negative or the suffix is invalid.

journalFile

public File journalFile(long transaction,
                        String suffix)
Generate a valid journal filename.

Throws:
IllegalArgumentException - if the version is negative or the suffix is invalid.

snapshotVersion

public static long snapshotVersion(File file)
Extract the version number from a snapshot filename. Returns -1 if file does not have a valid snapshot filename.


journalVersion

public static long journalVersion(File file)
Extract the version number from a journal filename. Returns -1 if file does not have a valid journal filename.


latestSnapshot

public File latestSnapshot()
                    throws IOException
Find the latest snapshot file. Returns null if no snapshot file was found.

Throws:
IOException

findInitialJournalFile

public File findInitialJournalFile(long initialTransactionWanted)
Find the journal file containing the desired transaction. Returns null if no appropriate journal file was found.


createTempFile

public File createTempFile(String prefix,
                           String suffix)
                    throws IOException
Create a temporary file in the directory.

Throws:
IOException

renameUnusedFile

public static void renameUnusedFile(File journalFile)
Rename a journal file to indicate it was found empty and is being ignored.


necessaryFiles

public Set necessaryFiles()
                   throws IOException
Determine which snapshot and journal files are still necessary for recovery. Necessary files include the latest snapshot file and any journal files potentially containing transactions after that snapshot version.

Throws:
IOException


Copyright © 2001-2013. All Rights Reserved.