webfunds.store
Class AppendFileStore

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

public class AppendFileStore
extends Store
implements Diagnostics

A hashtable object that provides access to files stored in a directory. Every piece of data is appended to a single file, hence 'AppendFile'. This is oriented to network storage, where there is a need to encrypt and hide the structure of the static data that is stored Network security concerns: There will remain a fairly clear signature in the append events, but that is mirrored by the actual activity anyway, so may not be so efficacious to protect. Probably, a wholistic protection approach would be preferable, as in an anonymiser ring.


Field Summary
protected  java.io.FileOutputStream append
           
protected  java.lang.String badFiles
           
protected  java.io.PrintWriter bug
          implements Diagnostics
static java.lang.String DELETE
           
protected  java.io.File dir
           
static java.lang.String DUMMY
           
protected  boolean error
           
protected  java.io.File file
           
protected  java.lang.String fix
           
protected  long high_watermark
           
static long HIGH_WATERMARK
           
protected  long post_watermark
           
static long POST_WATERMARK
           
protected  java.util.Hashtable stores
           
static java.lang.String suffix
           
protected static java.lang.String test
           
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
AppendFileStore()
          An uninitialised object, for ClassLoader.
AppendFileStore(java.io.File dir, java.io.PrintWriter pw, java.lang.String logfix)
          Open an empty, new AppendFileStore.
 
Method Summary
 boolean checkErrors()
           
protected  void cleanup(int lastfile)
          Clean up the old files we don't want, those a few numbers back.
 void clear()
          Removes all files in this directory, and any empty directories (intentional?).
protected  void dumpAll(java.io.DataOutputStream dos)
          Dump all objects to the output.
protected  void dumpObject(java.io.DataOutputStream dos, byte[] b1, byte[] b2, byte[] b3)
          Dump an object in Encodable format to the output.
protected  void dumpObject(java.io.DataOutputStream dos, java.lang.String key, java.lang.Object obj)
          Dump an object in Encodable format to the output.
 boolean equals(java.lang.Object obj)
           
protected  boolean equalsKeys(AppendFileStore one, AppendFileStore two)
           
 java.io.PrintWriter err()
          Do stack trace prints to err(), should always return something.
static AppendFileStore example(java.io.File fname)
           
static void exampleFill(AppendFileStore ex)
          Provide a dirname that is empty / not present.
protected static void exampleRemove(AppendFileStore a)
           
 java.lang.String getBadFiles()
           
protected  long getChecksum(byte[] b1, byte[] b2, byte[] b3)
           
 java.io.PrintWriter getDebug()
          Returns a debug writer, if any is set.
static Store getInstance(java.io.File dir)
           
static AppendFileStore getInstance(java.io.File dir, java.io.PrintWriter pw, java.lang.String logfix)
          Returns an existing AppendFileStore, with files in dir read in as objects in the hashtable.
protected static int getNumber(java.lang.String name)
           
 Store getStore(java.lang.String s, int i)
           
 Store[] getStores()
           
 void init(java.io.File dir, java.io.PrintWriter pw, java.lang.String logfix)
          Has to be a non-existant file.
protected  void initFiles()
           
protected  void initialiseFromFile(java.io.File file)
          Reads in the current hashtable from the file, which was saved by the previous incantation as an Append file.
 void logmsg(java.lang.String s)
           
static void main(java.lang.String[] args)
           
protected  void newFile(java.lang.String s)
          Has to be a non-existant file.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          (Re)sets a (file) object into the hashtable.
 java.lang.Object remove(java.lang.Object key)
          Drop the object from both hashtable and disk.
protected static void removeIt(java.io.File dir)
           
protected  void removeObject(java.io.DataOutputStream dos, java.lang.String key)
          Remove an object from the stream by adding a remove signal.
 void rollover()
          Cause a new file to be set up if old one is too big.
protected  void rollover(java.lang.String name)
           
protected  void sync()
          Store interface requires this, but it is a no-op.
 java.lang.String toString()
          Convert this object to a human readable string
protected static void tryit()
           
 
Methods inherited from class webfunds.store.Store
contains, containsKey, elements, get, getClassLoader, getName, getStore, getType, isChanged, isEmpty, keys, setChanged, setClassLoader, size
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

VERSION

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

HIGH_WATERMARK

public static final long HIGH_WATERMARK

POST_WATERMARK

public static final long POST_WATERMARK

high_watermark

protected long high_watermark

post_watermark

protected long post_watermark

suffix

public static final java.lang.String suffix

DUMMY

public static final java.lang.String DUMMY

DELETE

public static final java.lang.String DELETE

dir

protected java.io.File dir

file

protected java.io.File file

append

protected java.io.FileOutputStream append

error

protected boolean error

badFiles

protected java.lang.String badFiles

stores

protected java.util.Hashtable stores

bug

protected java.io.PrintWriter bug
implements Diagnostics

fix

protected java.lang.String fix

test

protected static final java.lang.String test
Constructor Detail

AppendFileStore

public AppendFileStore(java.io.File dir,
                       java.io.PrintWriter pw,
                       java.lang.String logfix)
                throws StoreException
Open an empty, new AppendFileStore. Note this is for internal use only as there is no easy way to have a new empty object. Use getInstance instead. But, why would you want one? Opened up due to ClassLoader inheriting problems.

AppendFileStore

public AppendFileStore()
                throws StoreException
An uninitialised object, for ClassLoader.
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)
          throws StoreException
Has to be a non-existant file.

newFile

protected void newFile(java.lang.String s)
                throws StoreException
Has to be a non-existant file.

getInstance

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

getInstance

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

getNumber

protected static int getNumber(java.lang.String name)

initFiles

protected void initFiles()
                  throws StoreException

getChecksum

protected long getChecksum(byte[] b1,
                           byte[] b2,
                           byte[] b3)

initialiseFromFile

protected void initialiseFromFile(java.io.File file)
                           throws StoreException
Reads in the current hashtable from the file, which was saved by the previous incantation as an Append file.

cleanup

protected void cleanup(int lastfile)
Clean up the old files we don't want, those a few numbers back. Cannot do until we have had at least one successful rollover(). Crude, we really need to account for gaps.

rollover

public void rollover()
              throws StoreException
Cause a new file to be set up if old one is too big. Does nothing if still below watermark. This is not called internally except on intialisation. Explicitly, a change to an object is not a convenient moment, as there may be a need to send it. Also, when we get past the watermark, automatic rollover would happen everytime something was added with the curren algorithm.

rollover

protected void rollover(java.lang.String name)
                 throws StoreException

dumpAll

protected void dumpAll(java.io.DataOutputStream dos)
                throws StoreException
Dump all objects to the output.

dumpObject

protected void dumpObject(java.io.DataOutputStream dos,
                          java.lang.String key,
                          java.lang.Object obj)
                   throws StoreException
Dump an object in Encodable format to the output.

dumpObject

protected void dumpObject(java.io.DataOutputStream dos,
                          byte[] b1,
                          byte[] b2,
                          byte[] b3)
                   throws StoreException
Dump an object in Encodable format to the output.

removeObject

protected void removeObject(java.io.DataOutputStream dos,
                            java.lang.String key)
                     throws StoreException
Remove an object from the stream by adding a remove signal.

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

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
(Re)sets a (file) object into the hashtable. and syncs the file to disk if it has changed. As we mostly deal in copied refs of the Object rather than copies of the Object, it is the caller's responsibility to ensure that it needs put'ing.
Overrides:
put in class Store
Parameters:
value - is an Encodable object
key - is the String name of the object

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()
Store interface requires this, but it is a no-op.
Overrides:
sync in class Store

getStore

public Store getStore(java.lang.String s,
                      int i)
Overrides:
getStore in class Store

getStores

public Store[] getStores()
Overrides:
getStores in class Store

toString

public java.lang.String toString()
Convert this object to a human readable string
Overrides:
toString in class java.lang.Object

equalsKeys

protected boolean equalsKeys(AppendFileStore one,
                             AppendFileStore two)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

exampleFill

public static void exampleFill(AppendFileStore ex)
                        throws StoreException
Provide a dirname that is empty / not present.

example

public static AppendFileStore example(java.io.File fname)
                               throws StoreException

main

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

exampleRemove

protected static void exampleRemove(AppendFileStore a)
                             throws java.lang.Exception

tryit

protected static void tryit()
                     throws java.lang.Exception

removeIt

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