webfunds.store
Class SepFileStore

java.lang.Object
  |
  +--webfunds.store.Store
        |
        +--webfunds.store.SepFileStore

public class SepFileStore
extends Store
implements Diagnostics

A hashtable object that provides access to files stored in a directory. Every piece of data is stored in a separate file, hence, 'SepFile.'


Field Summary
static int APPEND
           
protected  java.lang.String badFiles
           
protected  java.io.PrintWriter bug
           
protected  java.io.File dir
           
protected  boolean error
           
protected  java.lang.String fix
           
static int NET
           
static int SOMETHING
           
protected  java.util.Hashtable stores
           
protected  boolean syncbool
           
static int VERSION
          The version of the stored format for objects.
 
Fields inherited from class webfunds.store.Store
APPEND, changed, error, hash, name, NET, SOMETHING
 
Constructor Summary
SepFileStore()
          Open an empty, new SepFileStore with nothing set.
SepFileStore(java.io.File dir)
          Open an empty, new SepFileStore.
SepFileStore(java.io.File dir, java.io.PrintWriter pw, java.lang.String logfix)
          Open an empty, new SepFileStore with diags
 
Method Summary
protected static void checkDir(java.io.File dir)
           
 boolean checkErrors()
           
 void clear()
          Removes all files in this directory, and any empty directories (intentional?).
 java.io.PrintWriter err()
          Do stack trace prints to err(), should always return something.
 java.lang.Object get(java.lang.Object key)
          Return a (file) object located in the hashtable.
protected  Store getAppendStore(java.lang.String name)
           
 java.lang.String getBadFiles()
           
 java.io.PrintWriter getDebug()
          Returns a debug writer, if any is set.
static Store getInstance(java.io.File dir)
           
static SepFileStore getInstance(java.io.File dir, java.io.PrintWriter pw, java.lang.String logfix)
          Returns an existing SepFileStore, with files in dir read in as objects in the hashtable.
protected  Store getOldStore(java.lang.String name)
           
 Store getStore(java.lang.String name, java.lang.ClassLoader cl)
          Open up a new subStore, with ClassLoader set.
 Store getStore(java.lang.String name, int flags)
          Open up a new subStore, with variations.
 Store[] getStores()
          Within this current store, all directories are ignored by the creating getInstance() method.
 boolean getSync()
           
 void init(java.io.File dir, java.io.PrintWriter pw, java.lang.String logfix)
          Open an empty, new SepFileStore with diags
protected  void initFiles()
           
 void logmsg(java.lang.String s)
           
static void main(java.lang.String[] args)
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          (Re)sets a (file) object into the hashtable.
protected  boolean readEncodedFile(java.io.File file)
           
protected  void readFile(java.io.File file)
           
 java.lang.Object remove(java.lang.Object key)
          Drop the object from both hashtable and disk.
 void setSync(boolean syncbool)
          Call with true if sync-to-disk is required for all puts.
protected  void sync()
          Don't know.
protected  void sync(java.lang.String key)
          Write and sync a file to disk.
 java.lang.String toString()
           
 
Methods inherited from class webfunds.store.Store
contains, containsKey, elements, getClassLoader, getName, getStore, getType, isChanged, isEmpty, keys, setChanged, setClassLoader, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

public static final int VERSION
The version of the stored format for objects.

dir

protected java.io.File dir

syncbool

protected boolean syncbool

error

protected boolean error

badFiles

protected java.lang.String badFiles

stores

protected java.util.Hashtable stores

bug

protected java.io.PrintWriter bug

fix

protected java.lang.String fix

APPEND

public static final int APPEND

NET

public static final int NET

SOMETHING

public static final int SOMETHING
Constructor Detail

SepFileStore

public SepFileStore()
Open an empty, new SepFileStore with nothing set. Note this is probably incorrect, for ClassLoader use only.

SepFileStore

public SepFileStore(java.io.File dir)
Open an empty, new SepFileStore. Note this is probably incorrect, getInstance should be used instead.

SepFileStore

public SepFileStore(java.io.File dir,
                    java.io.PrintWriter pw,
                    java.lang.String logfix)
Open an empty, new SepFileStore with diags
Method Detail

getBadFiles

public java.lang.String getBadFiles()

logmsg

public void logmsg(java.lang.String s)
Specified by:
logmsg in interface Diagnostics

getDebug

public java.io.PrintWriter getDebug()
Description copied from interface: Diagnostics
Returns a debug writer, if any is set.
Specified by:
getDebug in interface Diagnostics

err

public java.io.PrintWriter err()
Description copied from interface: Diagnostics
Do stack trace prints to err(), should always return something.
Specified by:
err in interface Diagnostics

init

public void init(java.io.File dir,
                 java.io.PrintWriter pw,
                 java.lang.String logfix)
Open an empty, new SepFileStore with diags

getInstance

public static Store getInstance(java.io.File dir)

getInstance

public static SepFileStore getInstance(java.io.File dir,
                                       java.io.PrintWriter pw,
                                       java.lang.String logfix)
Returns an existing SepFileStore, with files in dir read in as objects in the hashtable. (Directories are ignored, see getStores()).

checkDir

protected static void checkDir(java.io.File dir)

initFiles

protected void initFiles()

readFile

protected void readFile(java.io.File file)

readEncodedFile

protected boolean readEncodedFile(java.io.File file)

setSync

public void setSync(boolean syncbool)
Call with true if sync-to-disk is required for all puts.

getSync

public boolean getSync()
Returns:
true if sync-to-disk is enabled, else false.

getOldStore

protected Store getOldStore(java.lang.String name)

getStore

public Store getStore(java.lang.String name,
                      int flags)
               throws StoreException
Open up a new subStore, with variations. But, note that we ignore stores in the invocing getInstance() we have to read it explicitly with getStores() or this call.
Overrides:
getStore in class Store

getAppendStore

protected Store getAppendStore(java.lang.String name)
                        throws StoreException

getStore

public Store getStore(java.lang.String name,
                      java.lang.ClassLoader cl)
               throws StoreException
Open up a new subStore, with ClassLoader set. Experimental. Not compatible with getStores (which is not used).

getStores

public Store[] getStores()
                  throws StoreException
Within this current store, all directories are ignored by the creating getInstance() method. This call getStores() finds all those missing directories and returns them as stores.
Overrides:
getStores in class Store

checkErrors

public boolean checkErrors()
Overrides:
checkErrors in class Store

clear

public void clear()
Removes all files in this directory, and any empty directories (intentional?). Does not change hashtable.
Overrides:
clear in class Store

get

public java.lang.Object get(java.lang.Object key)
Return a (file) object located in the hashtable.
Overrides:
get in class Store

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
(Re)sets a (file) object into the hashtable. Conducts some checking to see if it changed first, and syncs the file to disk if it has changed.
Overrides:
put in class Store

remove

public java.lang.Object remove(java.lang.Object key)
Drop the object from both hashtable and disk. Undefined what happens if delete fails, will recover?
Overrides:
remove in class Store

sync

protected void sync()
Don't know.
Overrides:
sync in class Store

sync

protected void sync(java.lang.String key)
Write and sync a file to disk. Grabs the hashtable copy just changed by put(), writes it to the filename, and calls the special sync operation.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception