ptolemy.backtrack.util
Class CheckpointRecord

java.lang.Object
  extended by ptolemy.backtrack.util.CheckpointRecord

public class CheckpointRecord
extends java.lang.Object

Record for checkpoint objects. Each Rollbackable is monitored by a checkpoint object at a time. The Rollbackable object maintains a record for its checkpoint objects. When a new checkpoint object is assigned, the old one is pushed to the checkpoint record. When a rollback is issued beyond the time when the last checkpoint object was assigned, the previous checkpoint object is then assigned back to the Rollbackable.

This record for checkpoint objects is basically a stack, with the top element as the last assigned checkpoint object (the checkpoint object that currently monitors a Rollbackable).

Since:
Ptolemy II 5.1
Version:
$Id: CheckpointRecord.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Red (tfeng)

Nested Class Summary
private  class CheckpointRecord.Record
          The record of a checkpoint object associated with a timestamp to be stored in the stack.
 
Field Summary
private  java.util.Stack<CheckpointRecord.Record> _records
          The stack of records.
 
Constructor Summary
CheckpointRecord()
           
 
Method Summary
 void add(Checkpoint checkpoint, long timestamp)
          Add a checkpoint object to the top of this record, associating with it a timestamp.
 void commit(long timestamp)
          Commit the changes of checkpoint objects up to (but not including) the time given by the timestamp.
 long getTopTimestamp()
          Get the timestamp associated with the checkpoint object on top of the stack.
 Checkpoint restore(Checkpoint checkpoint, Rollbackable object, long timestamp, boolean trim)
          Restore the old checkpoint object to the given Rollbackable object, if the given timestamp is less than or equal to the timestamp associated with the current checkpoint object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_records

private java.util.Stack<CheckpointRecord.Record> _records
The stack of records. Each record is an instance of CheckpointRecord.Record.

Constructor Detail

CheckpointRecord

public CheckpointRecord()
Method Detail

add

public void add(Checkpoint checkpoint,
                long timestamp)
Add a checkpoint object to the top of this record, associating with it a timestamp. The timestamp is usually the current timestamp of the new checkpoint object.

When a rollback beyond this timestamp is issued later, the previous checkpoint object is restored.

Parameters:
checkpoint - The checkpoint object to be push to the top of this record.
timestamp - The current timestamp of the new checkpoint object.

commit

public void commit(long timestamp)
Commit the changes of checkpoint objects up to (but not including) the time given by the timestamp. Older records of checkpoint object assignments are deleted. After that, it is not possible to roll back to any time before the given timestamp.

Parameters:
timestamp - The timestamp specifying the time up to when the changes of checkpoint objects are committed.

getTopTimestamp

public long getTopTimestamp()
Get the timestamp associated with the checkpoint object on top of the stack.

Returns:
The timestamp associated with the top checkpoint object.

restore

public Checkpoint restore(Checkpoint checkpoint,
                          Rollbackable object,
                          long timestamp,
                          boolean trim)
Restore the old checkpoint object to the given Rollbackable object, if the given timestamp is less than or equal to the timestamp associated with the current checkpoint object.

This method is not meant to be called by user applications.

Parameters:
checkpoint - The checkpoint object of the Rollbackable object.
object - The Rollbackable object.
timestamp - The timestamp.
trim - Whether to delete the used checkpoint object record.
Returns:
The checkpoint object of the Rollbackable object after it is restored.