Java Reference
In-Depth Information
Read from the persistent storage (file trackerState.log ) the last stable state
of the application.
Read forward the state changes log (file trackerPhysical.log ) and redo all
operations from the last stable point to the end of the log (i.e. the point
where the crash occurred). At the end of this step, the correct state before
the system crash is rebuilt.
Redoing an operation requires getting reference to the object that has
performed the operation using its associated label and copying the state
saved after the operation's execution.
The log file can be read forwards and backwards in order to perform undo
and redo of single operations. For this purpose, the framework offers class
TrackingConsole implementing a simple graphical interface that allows the
user to move forwards and backwards the application's current state.
Decision point
How does the tracker record complex operations (physical recording)?
A recoverable class might aggregate objects of other recoverable classes.
Thus, operations on the composite class (called “complex operations”)
might cause the execution of operations on the component objects. Tracking
state changes caused by complex operations is performed in the same way as
for simple operations. From a performance point of view, saving the state of
a composite class is partially redundant because it includes the state of each
component object.
18.4.3
Implementation
Interface Trackable defines two methods that every concrete subclass must
implement. Method cloneTarget() instantiates a new object of the same class
and initializes its state. It is used to create a copy of a trackable object when
a state transition is saved. Method restore() is used to undo or redo an oper-
ation: it restores an object's before or after state.
package recap;
import java.io.*;
import java.util.*;
public interface Trackable extends Serializable {
public Trackable cloneTarget();
public void restore(Trackable obj);
}
Class Entry represents the data structure used to record an object's before
or after state when an operation is performed.
public class Entry implements Serializable {
 
Search WWH ::




Custom Search