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

java.lang.Object
  extended by com.sag.osami.context.recorder.storage.RecordingContainer

public class RecordingContainer
extends java.lang.Object

This class represents a recording container file which stores the serializer used by the ContextStore at the time of the recording, and several recordings.

A recording container is basically a ZIP file which contains a file SERIALIZER which denotes the serializer, and folders recording-<recording number> for each recording: therein INFO and DATA files are stored, the first containing some metadata (see RecordingContainer.RecordingInfo), the latter containing the actual recorded/serialized context event data (see ContextEventData).


Nested Class Summary
static class RecordingContainer.RecordingInfo
          A RecordingInfo contains some metadata (number, start date, end date, events count) about a recording within a container.
 
Method Summary
 void close()
          Closes the recording container/ZIP file.
static RecordingContainer create(java.io.File location, java.lang.String initSerializer, ISerializedContextReceiver ctxStore)
          Creates a new recording container.
 java.io.File getLocation()
          Gets the location of the recording container.
 RecordingContainer.RecordingInfo[] getRecordings()
          Gets the metadata for the recordings contained in the container.
static RecordingContainer open(java.io.File location, java.lang.String actualSerializer, ISerializedContextReceiver ctxStore)
          Opens an existing recording container.
 java.io.DataInputStream readRecording(int recNum)
          Obtains an input stream within the recording container for a specific recording.
 void startRecording()
          Starts a new recording, i.e. initializes a SortedRecordingData and adds according metadata to the container object.
 void stopRecording()
          Stops the current recording, writes the current container data into a working container file, adds the (correctly reordered) temporary recording into the working container and replaces the current/old container with the working container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static RecordingContainer create(java.io.File location,
                                        java.lang.String initSerializer,
                                        ISerializedContextReceiver ctxStore)
                                 throws java.io.IOException
Creates a new recording container. The currently deployed ContextStore serializer class name is written to the container.

Parameters:
location - location of the recording container to be created
initSerializer - currently deployed ContextStore serializer
Returns:
the recording container
Throws:
java.io.IOException

open

public static RecordingContainer open(java.io.File location,
                                      java.lang.String actualSerializer,
                                      ISerializedContextReceiver ctxStore)
                               throws java.io.IOException,
                                      InvalidSerializerException
Opens an existing recording container.

Parameters:
location - location of the existing recording container
actualSerializer - fully qualified class name of the currently deployed ContextStore serializer
Returns:
the recording container
Throws:
java.io.IOException - on I/O errors
InvalidSerializerException - when currently deployed serializer and the serializer of the recording container don't match

startRecording

public void startRecording()
                    throws java.io.IOException
Starts a new recording, i.e. initializes a SortedRecordingData and adds according metadata to the container object. No information is written to the actual container file at this time.

Throws:
java.io.IOException - on I/O errors

stopRecording

public void stopRecording()
                   throws java.io.IOException
Stops the current recording, writes the current container data into a working container file, adds the (correctly reordered) temporary recording into the working container and replaces the current/old container with the working container. After this, no writing Zip-streams are open and zipf is pointing at the correct/new container.

Throws:
java.io.IOException - on I/O errors

getRecordings

public RecordingContainer.RecordingInfo[] getRecordings()
Gets the metadata for the recordings contained in the container.

Returns:
array of RecordingContainer.RecordingInfo

readRecording

public java.io.DataInputStream readRecording(int recNum)
                                      throws java.io.IOException
Obtains an input stream within the recording container for a specific recording.

Parameters:
recNum - number of the recording
Returns:
input stream which contains the recorded context event data (to be read by ContextEventData)
Throws:
java.io.IOException - on I/O errors

getLocation

public java.io.File getLocation()
Gets the location of the recording container.

Returns:
location of container

close

public void close()
           throws java.io.IOException
Closes the recording container/ZIP file.

Throws:
java.io.IOException