Java Reference
In-Depth Information
18.5
Prototype 2: Logical recording
The focus of this prototype is on the framework's mechanisms for logical
recording of application state changes.
18.5.1
Analysis
For logical recording, only the characteristics of the invocation of the operation
are recorded. This mechanism is extremely efficient because does not require
storing the object state before and after the operation execution, but it prevents
a straightforward cancellation or repetition of the last operation.
Undo
redo will then require the reconstruction of a stable state of the
application from which to proceed forward, reconstructing operations by
re-executing them. In this case, provided that the recoverable domain
represents in a complete way the execution environment of the application,
idempotence is guaranteed, since we always undo
redo starting from the same
stable state. If instead the recoverable domain only represents a portion of the
execution environment of the application, the idempotence property is lost.
Periodically defining stable states is particularly important for logical
recording, since it allows the definition of reference points from which
logical operations can be re-executed.
18.5.2
Design
We simply need to add more functionalities to class Tracker in the form of
new methods that handle state changes, transitions and recovey.
Decision point
How does the tracker log state changes (logical recording)?
Every operation that causes a state transition in a recoverable object must
invoke, only once during its execution, method record() of class Tracker .
Method record() saves the operation's signature in a log file named
trackerLogical.log , i.e. the label of the recoverable object, the name of the
method that causes the state transition, the list of parameter types and
the list of argument values. For this purpose, we need to assume that all of
the argument values are instances of serializable classes.
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(Integer num) {
Tracker.record( this , "increment", Class[]
{Integer.class},
new Object[] {num});
sum !# num.intValue();
}
Decision point
How does the tracker restore the application's state corresponding to the last
state transition (logical recording)?
 
Search WWH ::




Custom Search