Java Reference
In-Depth Information
Decision point
How does the tracker restore the state of an object after a crash?
A new object is registered in the tracker registry by invoking method
bind()
of class
Tracker
. This method accepts two parameters: a reference to a
trackable object and a label that identifies the object univocally. This label is
always the same every time the application is restarted. When the appli-
cation state is saved in a persistent storage, the state of every registered
object is saved along with its associated label.
Restoring the last saved state of a recovered application is as simple as
copying in every registered object the state loaded from the persistent
storage associated to the same object label. For this purpose, every trackable
object must implement interface
Trackable
which defines method
restore()
.
Decision point
How does the tracker log state changes (physical recording)?
Every method that causes a state transition in a recoverable object must
invoke method
record()
of class
Tracker
before and after the state change.
Method
record()
saves the object's current state in a log file named
trackerPhysical.log
. The method accepts three parameters: a reference to the
recoverable object, a string that corresponds to the name of the method
causing the state transition, and a label that indicates whether the state
has been saved before or after the state transition. See, for example, the
following code fragment, where
increment()
is a method of a recoverable class
that modifies the value of state variable
sum
.
public void
increment(
int
num) {
Tracker.record(
this
, "increment", Tracker.BEFORE);
sum
!#
num;
Tracker.record(
this
, "increment", Tracker.AFTER);
}
Decision point
How does the tracker restore the application's state corresponding to the last
state transition (physical recording)?
When a system crash occurs, the application needs to be restarted appro-
priately, by recovering the state previously reached during its execution.
This is achieved by performing the following steps:
Build the application.
■