com.sag.osami.context.recorder.storage
Class SortedRecordingData

java.lang.Object
  extended by com.sag.osami.context.recorder.storage.SortedRecordingData
All Implemented Interfaces:
IContextHandler, ISerializedContextHandler

public class SortedRecordingData
extends java.lang.Object
implements ISerializedContextHandler

This class is used as an intermediate target for recorded context events. This is necessary due to the fact that context events may be "handled" (and therefore recorded) in non-chronological order (depending on the thread scheduling of the context handler worker threads), while chronological order is preferable when replaying a recording. Therefore, this class maintains some additional sorting information and is able to rewrite the recording into a RecordingContainer in the correct order efficiently.

Objects of this class are intended to be used once and then thrown away (upon rewriting to a container). In particular, (re)starting a recording after rewriting will fail.

This class does all of the necessary context handler (de)registering.


Constructor Summary
SortedRecordingData(IContextStore ctxStore)
           
 
Method Summary
 java.lang.String[] getDefaultContextTypes()
          This method is necessary for the ContextStore service tracking mechanism which tracks all registered IContextHandlers: the returned string array should contain the types of the context events which this handler should receive after (OSGi service) registering.
 int getEventsCount()
           
 void handleContextEvent(ContextEvent context)
          This method processes received context events.
 void setContextStore(IContextStore contextStore)
          This method is necessary for the ContextStore service tracking mechanism which tracks all registered IContextHandlers: by passing the reference to the context store as a parameter, the handler obtains access to the context store (and should store the reference as a local member variable for further use)
 void startRecording()
           
 void stopRecording()
           
 void writeToContainer(java.io.OutputStream target)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedRecordingData

public SortedRecordingData(IContextStore ctxStore)
                    throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getDefaultContextTypes

public java.lang.String[] getDefaultContextTypes()
Description copied from interface: IContextHandler
This method is necessary for the ContextStore service tracking mechanism which tracks all registered IContextHandlers: the returned string array should contain the types of the context events which this handler should receive after (OSGi service) registering.

However, the types handled by a context handler may be modified during runtime, e.g. by using IContextStore.registerHandlerForContextType(IContextHandler, String).

If the handler acts as a producer only, a null-returning dummy implementation suffices.

Specified by:
getDefaultContextTypes in interface IContextHandler

setContextStore

public void setContextStore(IContextStore contextStore)
Description copied from interface: IContextHandler
This method is necessary for the ContextStore service tracking mechanism which tracks all registered IContextHandlers: by passing the reference to the context store as a parameter, the handler obtains access to the context store (and should store the reference as a local member variable for further use)

Specified by:
setContextStore in interface IContextHandler
Parameters:
contextStore - the context store

handleContextEvent

public void handleContextEvent(ContextEvent context)
Description copied from interface: IContextHandler
This method processes received context events. If the handler acts as a producer only, an empty dummy implementation suffices.

Since version 1.1.0, the handling logic of context handlers (i.e. this method) is executed in separate context handling worker threads, thereby decoupling the handling execution time from the rest of the system. Hence, it is not necessary (and not advisable) to implement own threading in this method.

Specified by:
handleContextEvent in interface IContextHandler
Parameters:
context - the context event to be handled

startRecording

public void startRecording()

stopRecording

public void stopRecording()

getEventsCount

public int getEventsCount()

writeToContainer

public void writeToContainer(java.io.OutputStream target)
                      throws java.io.IOException
Throws:
java.io.IOException