01: // Space4J(TM) - Object Persistence in RAM
02: // Copyright (C) 2003 Sergio Oliveira Junior
03: // This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
04:
05: package org.space4j;
06:
07: import java.io.*;
08: import org.space4j.*;
09:
10: /**
11: * An interface defining how a Logger Object should work.<Br>
12: * A Logger is responsible for logging the commands to disk, taking snapshots of the Space to disk,
13: * recovering snapshots of the Space from disk, and reapplying the logged Commands.<br>
14: */
15: public interface Logger {
16:
17: /**
18: * Log a command to a log file on disk.<br>
19: * @param cmd The command to log
20: */
21: public void logCommand(Command cmd) throws LoggerException;
22:
23: /**
24: * Take a snapshot of the Space to disk. The Space will be serialized and written to disk.<br>
25: * @param space The space to be saved.
26: */
27: public void takeSnapshot(Space space) throws LoggerException;
28:
29: /**
30: * Take a snapshot of the Space to disk. The Space will be serialized and written to disk.<br>
31: * @param space The space to be saved.
32: * @param snapnumber The number of the snapshot to be saved.
33: */
34: public void takeSnapshot(Space space, long snapnumber)
35: throws LoggerException;
36:
37: /**
38: * Recover the last snapshot from disk and recreate a Space from it.
39: * @return A space recovered from the snapshot or null if there were no space to recover in disk.
40: */
41: public Space readSnapshot() throws LoggerException;
42:
43: /**
44: * Read the last commands from the log and re-apply them to this Space4J.<br>
45: * The last commands are the commands after the last snapshot, in other words, those that were not reflected by the last snaphot.<br>
46: * OBS: Let's say there is a crash before the system can take a snapshot. The log will be used to reconstruct the space.<br>
47: * Actually the rule to initialization is: "Recover the last snapshot and recover the commands after the last snapshot.<br>
48: * @param space4j The Space4J that will redo the commands.
49: */
50: public void reapplyCommandsFromLog(Space4J space4j)
51: throws LoggerException, CommandException;
52:
53: /**
54: * Get the current log number.
55: * @return The current log number.
56: */
57: public long getLogNumber();
58:
59: }
|