org.oddjob.persist
Class FilePersister

java.lang.Object
  extended by org.oddjob.persist.PersisterBase
      extended by org.oddjob.persist.FilePersister
All Implemented Interfaces:
OddjobPersister

public class FilePersister
extends PersisterBase

Description

Persist and load jobs from and to a file. The file the job is persisted to is the jobs id with a .ser extension.

A new sub directory is created for each nested Oddjob with an id. The job of the nested Oddjob are persisted to the sub directory. Thus the directory structure mirrors the structure of the Oddjobs.

Example

Using a file persister with Oddjob. The persist directory is passed in as an argument from the command line. The state of child jobs will be saved in a child directory relative to the given directory of the name 'important-jobs'.
<oddjob id="this">
    <job>
        <oddjob id="important-jobs" file="${this.dir}/FilePersisterExampleInner.xml">
            <persister>
                <file-persister dir="${this.args[0]}"/>
            </persister>
        </oddjob>
    </job>
</oddjob>
Author:
Rob Gordon.

Constructor Summary
FilePersister()
           
 
Method Summary
protected  void clear(Path path)
          Remove a possibly previously persisted object.
 File getDir()
          Get the directory, files are being persisted in.
protected  String[] list(Path path)
           
protected  void persist(Path path, String id, Object o)
          Provided by subclasses to do the persisting.
protected  void remove(Path path, String id)
          Remove a possibly previously persisted object.
protected  Object restore(Path path, String id, ClassLoader classLoader)
          Restore a previously persisted Component or it's Proxy.
 void setDir(File dir)
          Set the directory to save files in.
 String toString()
           
 
Methods inherited from class org.oddjob.persist.PersisterBase
persisterFor, setPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FilePersister

public FilePersister()
Method Detail

setDir

public void setDir(File dir)
Set the directory to save files in.

Parameters:
dir - The directory.

getDir

public File getDir()
Get the directory, files are being persisted in.

Returns:
The directory.

persist

protected void persist(Path path,
                       String id,
                       Object o)
                throws ComponentPersistException
Description copied from class: PersisterBase
Provided by subclasses to do the persisting.

Specified by:
persist in class PersisterBase
Parameters:
path - The path as a string. Never null.
id - The id. Never Null.
o - The component or it's proxy.
Throws:
ComponentPersistException

remove

protected void remove(Path path,
                      String id)
               throws ComponentPersistException
Description copied from class: PersisterBase
Remove a possibly previously persisted object.

Specified by:
remove in class PersisterBase
Parameters:
path - The path.
id - The id.
Throws:
ComponentPersistException

restore

protected Object restore(Path path,
                         String id,
                         ClassLoader classLoader)
                  throws ComponentPersistException
Description copied from class: PersisterBase
Restore a previously persisted Component or it's Proxy.

Specified by:
restore in class PersisterBase
Parameters:
path - The path. Never Null.
id - The id. Never Null.
classLoader - The classLoader.
Returns:
The component or it's proxy. Null if nothing had previously been persisted for this path and id.
Throws:
ComponentPersistException

list

protected String[] list(Path path)
                 throws ComponentPersistException
Specified by:
list in class PersisterBase
Throws:
ComponentPersistException

clear

protected void clear(Path path)
Description copied from class: PersisterBase
Remove a possibly previously persisted object.

Specified by:
clear in class PersisterBase
Parameters:
path - The path.

toString

public String toString()
Overrides:
toString in class Object