Java Reference
In-Depth Information
Section 18.2.3. Accordingly, the definition of stable states is under the user's
control and the initial state corresponds to the initial configuration of the
application when no user stimuli have yet been generated. This makes the
application recovery quite easy. After the application restart, any logged
state change is applied starting from the initial state or the last saved stable
The main framework component is represented by class Tracker . It acts as an
intermediate layer between the recoverable application and the persistent
storage. Complex applications are made up of a large number of classes that
might need to be recoverable. For this kind of application it is not feasible
to pass the reference to an instance of class Tracker throughout the entire
application hierarchy of nested classes.
For this reason it is convenient to implement class Tracker as a container
of global functions. This approach is similar to the implementation of class
System of package java.lang .
Decision point
How does the tracker save the state of an application?
The package offers interface Serializable . Every class implementing
this interface can have its state serialized automatically, i.e. converted to a
form suitable for external storage. Persistent storage of objects of serializable
classes can be accomplished by passing the objects to an output stream, e.g.
using a file (named trackerState.log ) for the stream. Thus, every recoverable
class must implement the Serializable interface.
Since an application may be made up of several recoverable classes,
saving the state of the entire application means serializing all of the objects
that are instances of recoverable classes. For this purpose, we need to find a
way of keeping track of all the recoverable objects being created during the
application's life span.
We adopt a solution that is similar to the naming mechanism of Java RMI.
The Tracker class provides methods for storing and obtaining references to
objects in an object registry and methods to save the state of the entire set
of registered objects in persistent storage. See, for example, the following
code fragment, where Target is a recoverable class.
public Application() {
try {
target # new Target();
Tracker.bind(target, "target");
catch (Exception e) { e.printStackTrace(); }
Search WWH ::

Custom Search