com.sag.osami.context.recorder
Class ContextStoreReplay

java.lang.Object
  extended by com.sag.osami.context.recorder.ContextStoreReplay

public class ContextStoreReplay
extends java.lang.Object

This class handles the replaying of recorded context events.

It utilizes two threads for this: a Replay- and a Reader-thread. The task of the Reader-thread is to read the context event data from the recording input stream and to put ready-to-use context events into a buffer. The task of the Replay-thread is to fetch these context events from the buffer and to pass them to the ContextStore in the correct order and with correct time intervals between the context events.

The buffer is a bounded LinkedBlockingQueue, resulting in the following (desired) behavior of the threads:

When the buffer is full, the Reader-thread blocks until a free slot becomes available.
When the buffer is empty, the Replay-thread blocks until a context event becomes available (should rarely happen).

In effect, the memory consumption should remain low and on the other hand, the replaying thread should never wait unnecessarily as a result of context event reading/parsing.


Constructor Summary
ContextStoreReplay(ISerializedContextReceiver ctxStore)
          Default constructor.
 
Method Summary
 void runOnFinish(java.lang.Runnable callback)
          Defines a callback which is to be run after a replay was stopped or finished.
 void start(java.io.DataInputStream recordingData)
          Starts the replay of a recording, i.e. starts the Reader- and Replay-thread.
 void stop()
          Stops the replay of a recording, i.e. stops the Reader- and Replay-thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextStoreReplay

public ContextStoreReplay(ISerializedContextReceiver ctxStore)
Default constructor.

Parameters:
ctxStore - ContextStore which receives the replayed (serialized) context events
Method Detail

start

public void start(java.io.DataInputStream recordingData)
Starts the replay of a recording, i.e. starts the Reader- and Replay-thread.


stop

public void stop()
Stops the replay of a recording, i.e. stops the Reader- and Replay-thread.


runOnFinish

public void runOnFinish(java.lang.Runnable callback)
Defines a callback which is to be run after a replay was stopped or finished.