org.space4j.implementation
Class SimpleSpace4J

java.lang.Object
  extended by org.space4j.implementation.SimpleSpace4J
All Implemented Interfaces:
java.lang.Runnable, Space4J
Direct Known Subclasses:
MasterSpace4J, SlaveSpace4J

public class SimpleSpace4J
extends java.lang.Object
implements Space4J, java.lang.Runnable

The simplest possible implementation of a Space4J.


Field Summary
protected  java.lang.String dirname
           
protected  IndexManager im
           
protected  Logger logger
           
protected  long snapTime
           
protected  Space space
           
protected  java.lang.Thread thread
           
 
Constructor Summary
SimpleSpace4J(java.lang.String dirname)
           
SimpleSpace4J(java.lang.String dirname, long snapTime)
          Initializes the SimpleSpace4J, initializes the Logger, recover the Space from disk if there is a snapshot saved and reapply the commands to the Space.
 
Method Summary
 int exec(Command cmd)
          Execute a command and log it.
protected  int exec(Command cmd, boolean log)
           
 void executeSnapshot()
          Take a snapshot of the Space to disk.
 java.lang.String getDirName()
           
 Space getSpace()
          Returns the Space where the Objects are stored, so the client can direct access them.
 Space readSnapshot()
           
 int reapply(Command cmd)
          Re-apply a command on the underlying Space.
 void reapplyCommandsFromLog()
           
 void run()
           
 void start()
          Starts the Space4J.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

space

protected Space space

logger

protected Logger logger

dirname

protected java.lang.String dirname

im

protected IndexManager im

thread

protected java.lang.Thread thread

snapTime

protected long snapTime
Constructor Detail

SimpleSpace4J

public SimpleSpace4J(java.lang.String dirname,
                     long snapTime)
              throws LoggerException,
                     CommandException
Initializes the SimpleSpace4J, initializes the Logger, recover the Space from disk if there is a snapshot saved and reapply the commands to the Space.

Throws:
LoggerException
CommandException

SimpleSpace4J

public SimpleSpace4J(java.lang.String dirname)
              throws LoggerException,
                     CommandException
Throws:
LoggerException
CommandException
Method Detail

getDirName

public java.lang.String getDirName()

getSpace

public Space getSpace()
Description copied from interface: Space4J
Returns the Space where the Objects are stored, so the client can direct access them.

Specified by:
getSpace in interface Space4J
Returns:
a Space if Space4J is running locally or null otherwise

run

public void run()
Specified by:
run in interface java.lang.Runnable

start

public void start()
           throws java.net.UnknownHostException,
                  java.io.IOException,
                  java.lang.ClassNotFoundException
Description copied from interface: Space4J
Starts the Space4J. This is only necessary for a replicated Space4J.

Specified by:
start in interface Space4J
Throws:
java.net.UnknownHostException
java.io.IOException
java.lang.ClassNotFoundException

exec

public int exec(Command cmd)
         throws CommandException,
                LoggerException
Execute a command and log it.

Specified by:
exec in interface Space4J
Parameters:
cmd - The command to be executed and logged.
Returns:
The number of objects modified by this operation.
Throws:
CommandException - if there is a problem executing this command
LoggerException - if there is a problem logging thie command

reapply

public int reapply(Command cmd)
            throws CommandException,
                   LoggerException
Description copied from interface: Space4J
Re-apply a command on the underlying Space. This method will be used to re-apply the commands from the logs. OBS: Logging is done AFTER the command is executed. If, for some reason, a CommandException is thrown, the command will not be logged.

Specified by:
reapply in interface Space4J
Parameters:
cmd - The command to execute.
Returns:
An int containing the number of objects modified by this operation.
Throws:
CommandException - if there is a problem executing this command
LoggerException - if there is a problem logging thie command

exec

protected int exec(Command cmd,
                   boolean log)
            throws CommandException,
                   LoggerException
Throws:
CommandException
LoggerException

executeSnapshot

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

Specified by:
executeSnapshot in interface Space4J
Throws:
LoggerException

readSnapshot

public Space readSnapshot()
                   throws LoggerException
Throws:
LoggerException

reapplyCommandsFromLog

public void reapplyCommandsFromLog()
                            throws CommandException,
                                   LoggerException
Throws:
CommandException
LoggerException


Copyright © 2005 Space4J Team. All Rights Reserved.