ptolemy.backtrack.ui
Class BacktrackController

java.lang.Object
  extended by ptolemy.backtrack.ui.BacktrackController

public class BacktrackController
extends java.lang.Object

Backtracking controller for composite actors. This controller is built on top of the backtracking sub-system. It helps to create checkpoints for Ptolemy II composite actors. Each of those checkpoints may correspond to multiple checkpoints in the backtracking sub-system, due to the fact that entities in a composite actor may be monitored by different checkpoint objects. This controller also allows to roll back the composite actor to its previous state.

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

Field Summary
private  java.util.HashMap<java.lang.Long,java.util.HashMap<Checkpoint,java.lang.Long>> _checkpoints
          The map from checkpoint handles used in this class to checkpoint handles used in the checkpointing sub-system.
private  long _currentHandle
          The current checkpoint handle.
 
Constructor Summary
BacktrackController()
           
 
Method Summary
 void commit(long handle)
          Commit a checkpoint handle.
 long createCheckpoint(CompositeActor container)
          Create a checkpoint for the given composite actor, and return the checkpoint handle.
 boolean rollback(long handle, boolean trim)
          Roll back the system state with the records in the checkpoint with the given handle.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_checkpoints

private java.util.HashMap<java.lang.Long,java.util.HashMap<Checkpoint,java.lang.Long>> _checkpoints
The map from checkpoint handles used in this class to checkpoint handles used in the checkpointing sub-system. The keys of this map are handles (of Long type); the values are HashMaps. In each of those HashMaps, the keys are checkpoint objects, and the values are the checkpoint handles returned by those checkpoint objects.


_currentHandle

private long _currentHandle
The current checkpoint handle.

Constructor Detail

BacktrackController

public BacktrackController()
Method Detail

commit

public void commit(long handle)
Commit a checkpoint handle. After it is committed, the system can no longer roll back to that checkpoint, or any other checkpoint taken before that one. Memory allocated for the committed checkpoints will be released.

Parameters:
handle - The handle of the checkpoint to be committed.

createCheckpoint

public long createCheckpoint(CompositeActor container)
Create a checkpoint for the given composite actor, and return the checkpoint handle. This checkpoint handle is different from the checkpoint handles returned by Checkpoint.createCheckpoint(), which are the internal representations of checkpoint timestamps. This checkpoint handle, however, refers to a collection of checkpoint timestamps for different checkpoint objects that manage different entities in the container. The returned checkpoint handle can only be used with commit(long) and rollback(long, boolean) in this class.

Parameters:
container - The composite actor for which a checkpoint will be created.
Returns:
The checkpoint handle.

rollback

public boolean rollback(long handle,
                        boolean trim)
Roll back the system state with the records in the checkpoint with the given handle. If the checkpoint objects that monitor the entities in the composite actor are not changed since the time when the checkpoint was created, this rollback only affects that composite actor and its children. This is true in most of the cases, but it is not guaranteed.

Parameters:
handle - The checkpoint handle previous returned by createCheckpoint(CompositeActor).
trim - Whether the records in the checkpoint should be deleted. If the records are deleted, memory is freed, but lazy computation is impossible.
Returns:
Whether the given handle is valid.