Package org.deckfour.xes.model.buffered
Class XSequentialEventBuffer
- java.lang.Object
-
- org.deckfour.xes.model.buffered.XSequentialEventBuffer
-
- All Implemented Interfaces:
java.lang.Cloneable
public class XSequentialEventBuffer extends java.lang.Object implements java.lang.CloneableThis class provides a random-access interface to a sequential set of events. These events are buffered not in heap space, but in a binary buffer file, whose encoding is implemented in this class as well.The structure of a buffer file is a sequence of binary records, one for each events, where records are encoded as follows:
- Offset in bytes to next record / size of record (4-byte integer)
- Offset in bytes to previous record (4-byte integer)
- ID of the event (serialization provided by XID class)
- Number of attributes (as 4-byte integer)
- A corresponding number of attribute serializations
- Attribute key (UTF-8 encoded String)
- Attribute value (UTF-8 encoded String)
- Attribute type (UTF-8 encoded String)
- Attribute extension URI (UTF-8 encoded String)
- Serialization of the attribute's attribute map (meta-attributes)
- Author:
- Christian W. Guenther (christian@deckfour.org)
-
-
Field Summary
Fields Modifier and Type Field Description protected static intEXTENSION_GENERICEncoding for non-existent extension (generic attributes)
-
Constructor Summary
Constructors Modifier Constructor Description protectedXSequentialEventBuffer()XSequentialEventBuffer(NikeFS2StorageProvider aProvider, XAttributeMapSerializer attributeMapSerializer)Creates and initializes a new instance of this class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(XEvent event)Appends a new event to the end of this collection.voidcleanup()Cleans up any non-volatile resources (e.g.java.lang.Objectclone()Creates an identical clone of this buffer.protected byte[]encode(XEvent event)Encodes the given event into a sequence of bytes.protected voidfinalize()Remove buffer file when this instance is garbage collected.XEventget(int eventIndex)Retrieves the event recorded at the specified positionNikeFS2StorageProvidergetProvider()Returns the storage provider used by this instanceNikeFS2RandomAccessStoragegetStorage()Returns the random access storage this instance is based onintindex()Retrieves the current internal, logical position of this collection.longlastInsert()Returns the last insert position of this instanceprotected voidnavigateToIndex(int reqIndex)Repositions the low-level layer to read from the specified index.longposition()Returns the current position of this instanceprotected XEventread()Reads an event from the current position of the data access layer.booleanreplace(XEvent event, int index)Replaces an event at the given position.protected voidresetPosition()Resets the position of the data access layer to read the next event from the first position.intsize()Retrieves the number of events recorded in this instance.protected voidskipBackward(int eventsToSkip)Repositions the position of the data access layer to skip the specified number of records towards the beginning of the file.protected voidskipForward(int eventsToSkip)Repositions the position of the data access layer to skip the specified number of records towards the end of the file.
-
-
-
Field Detail
-
EXTENSION_GENERIC
protected static final int EXTENSION_GENERIC
Encoding for non-existent extension (generic attributes)- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XSequentialEventBuffer
public XSequentialEventBuffer(NikeFS2StorageProvider aProvider, XAttributeMapSerializer attributeMapSerializer) throws java.io.IOException
Creates and initializes a new instance of this class.- Parameters:
aProvider- Storage provider used for backing this buffer.attributeMapSerializer- Attribute map serializer to be used.- Throws:
java.io.IOException
-
XSequentialEventBuffer
protected XSequentialEventBuffer()
-
-
Method Detail
-
getProvider
public NikeFS2StorageProvider getProvider()
Returns the storage provider used by this instance
-
position
public long position()
Returns the current position of this instance
-
lastInsert
public long lastInsert()
Returns the last insert position of this instance
-
getStorage
public NikeFS2RandomAccessStorage getStorage()
Returns the random access storage this instance is based on
-
size
public int size()
Retrieves the number of events recorded in this instance.- Returns:
- number of audit trail entries recorded in this instance
-
index
public int index()
Retrieves the current internal, logical position of this collection.
-
append
public void append(XEvent event) throws java.io.IOException
Appends a new event to the end of this collection.Notice that a call to this method does not affect the current position events are read from.
- Parameters:
ate- The event to append- Throws:
java.io.IOException
-
replace
public boolean replace(XEvent event, int index) throws java.io.IOException
Replaces an event at the given position.- Parameters:
event- The new event to be inserted.index- Index to replace at.- Returns:
- The former event, having been replaced.
- Throws:
java.io.IOException
-
get
public XEvent get(int eventIndex) throws java.io.IOException, java.lang.IndexOutOfBoundsException
Retrieves the event recorded at the specified position- Parameters:
eventIndex- Position of the requested event, defined to be within[0, size()-1].- Returns:
- The requested event.
- Throws:
java.io.IOExceptionjava.lang.IndexOutOfBoundsException
-
cleanup
public void cleanup() throws java.io.IOExceptionCleans up any non-volatile resources (e.g. temporary files) associated with this instance and resets the instance to an initial state.- Throws:
java.io.IOException
-
navigateToIndex
protected void navigateToIndex(int reqIndex) throws java.io.IOExceptionRepositions the low-level layer to read from the specified index.- Parameters:
reqIndex- Index to position the file pointer to.- Throws:
java.io.IOException
-
resetPosition
protected void resetPosition()
Resets the position of the data access layer to read the next event from the first position.
-
skipForward
protected void skipForward(int eventsToSkip) throws java.io.IOExceptionRepositions the position of the data access layer to skip the specified number of records towards the end of the file.- Parameters:
eventsToSkip- Number of records to be skipped.- Throws:
java.io.IOException
-
skipBackward
protected void skipBackward(int eventsToSkip) throws java.io.IOExceptionRepositions the position of the data access layer to skip the specified number of records towards the beginning of the file.- Parameters:
eventsToSkip- Number of records to be skipped.- Throws:
java.io.IOException
-
read
protected XEvent read() throws java.io.IOException
Reads an event from the current position of the data access layer. Calling this method implies the advancement of the data access layer, so that the next call will yield the subsequent event.- Throws:
java.io.IOException
-
encode
protected byte[] encode(XEvent event) throws java.io.IOException
Encodes the given event into a sequence of bytes. This byte array corresponds to the structure of an event record, as specified in the beginning of this document, excluding the back-/forward offsets used for navigation.- Parameters:
ate- The event to be encoded.- Returns:
- byte Array representing the event without navigation offsets.
- Throws:
java.io.IOException
-
clone
public java.lang.Object clone()
Creates an identical clone of this buffer.- Overrides:
clonein classjava.lang.Object
-
finalize
protected void finalize() throws java.lang.ThrowableRemove buffer file when this instance is garbage collected.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
-