org.space4j.implementation
Class SimpleLogger

java.lang.Object
  extended by org.space4j.implementation.SimpleLogger
All Implemented Interfaces:
Logger

public class SimpleLogger
extends java.lang.Object
implements Logger


Constructor Summary
SimpleLogger(java.lang.String dirname)
          Initializes this SimpleLogger.
 
Method Summary
 long getLogNumber()
          Get the current log number.
 void logCommand(Command cmd)
          Log a command to a log file on disk.
 Space readSnapshot()
          Recover the last snapshot from disk and recreate a Space from it.
 void reapplyCommandsFromLog(Space4J space4j)
          Read the last commands from the log and re-apply them to this Space4J.
 void takeSnapshot(Space space)
          Take a snapshot of the Space to disk.
 void takeSnapshot(Space space, long snapnumber)
          Take a snapshot of the Space to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleLogger

public SimpleLogger(java.lang.String dirname)
Initializes this SimpleLogger. SimpleLogger uses a special directory named space4j_db to store all other directories. Each application (client) has its own subdirectory below this one. You pass the name of this subdirectory through the dirname parameter.

Parameters:
dirname - The dir where to store the files.
Method Detail

getLogNumber

public long getLogNumber()
Description copied from interface: Logger
Get the current log number.

Specified by:
getLogNumber in interface Logger
Returns:
The current log number.

logCommand

public void logCommand(Command cmd)
                throws LoggerException
Description copied from interface: Logger
Log a command to a log file on disk.

Specified by:
logCommand in interface Logger
Parameters:
cmd - The command to log
Throws:
LoggerException

takeSnapshot

public void takeSnapshot(Space space)
                  throws LoggerException
Description copied from interface: Logger
Take a snapshot of the Space to disk. The Space will be serialized and written to disk.

Specified by:
takeSnapshot in interface Logger
Parameters:
space - The space to be saved.
Throws:
LoggerException

takeSnapshot

public void takeSnapshot(Space space,
                         long snapnumber)
                  throws LoggerException
Description copied from interface: Logger
Take a snapshot of the Space to disk. The Space will be serialized and written to disk.

Specified by:
takeSnapshot in interface Logger
Parameters:
space - The space to be saved.
snapnumber - The number of the snapshot to be saved.
Throws:
LoggerException

readSnapshot

public Space readSnapshot()
                   throws LoggerException
Description copied from interface: Logger
Recover the last snapshot from disk and recreate a Space from it.

Specified by:
readSnapshot in interface Logger
Returns:
A space recovered from the snapshot or null if there were no space to recover in disk.
Throws:
LoggerException

reapplyCommandsFromLog

public void reapplyCommandsFromLog(Space4J space4j)
                            throws LoggerException,
                                   CommandException
Description copied from interface: Logger
Read the last commands from the log and re-apply them to this Space4J. The last commands are the commands after the last snapshot, in other words, those that were not reflected by the last snaphot. OBS: Let's say there is a crash before the system can take a snapshot. The log will be used to reconstruct the space. Actually the rule to initialization is: "Recover the last snapshot and recover the commands after the last snapshot.

Specified by:
reapplyCommandsFromLog in interface Logger
Parameters:
space4j - The Space4J that will redo the commands.
Throws:
LoggerException
CommandException


Copyright © 2005 Space4J Team. All Rights Reserved.