org.gillius.realdb.model
Class IndexBlock

java.lang.Object
  extended by org.gillius.realdb.model.IndexBlock
All Implemented Interfaces:
Range

public class IndexBlock
extends java.lang.Object
implements Range

IndexBlock represents a single index data block within a stream's DataIndex. A large sequence number (32 bit) is used so we can recognize that the active block written longest ago is still recognized as being older than the newest block.

Author:
Jason Winnebeck

Field Summary
static org.gillius.realdb.model.SequencedBlockLoader<IndexBlock> loader
          A global static final thread-safe instance of a SequencedBlockLoader to load IndexBlocks.
 
Constructor Summary
IndexBlock(byte[] data)
          Constructs a new IndexBlock by reading it from the given byte array.
IndexBlock(int seqNum)
          Creates an "empty" IndexBlock with no data blocks, and start and end times are 0.
IndexBlock(int seqNum, long startTime, long endTime, int[] dataBlocks)
          Creates an IndexBlock with the given data blocks.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 int[] getDataBlocks()
           
 long getEndTime()
           
static int getMaxDataBlocks(int blockSize)
          Given a block size in bytes, returns the number of data block indicies that this IndexBlock can hold.
static int getMinSize()
          Returns the size, in bytes, of the smallest possible IndexBlock, the empty block.
 int getSeqNum()
           
static int getSize(int numBlocks)
          Returns the size, in bytes, of the IndexBlock that holds 'numBlocks' data block indexes.
 long getStartTime()
          Returns the timestamp of the first data point in the first data block
 int hashCode()
           
 java.lang.String toString()
           
 void write(java.io.DataOutput output)
          Writes this object to the given DataOutput.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

loader

public static org.gillius.realdb.model.SequencedBlockLoader<IndexBlock> loader
A global static final thread-safe instance of a SequencedBlockLoader to load IndexBlocks.

Constructor Detail

IndexBlock

public IndexBlock(int seqNum)
Creates an "empty" IndexBlock with no data blocks, and start and end times are 0.

Parameters:
seqNum - sequence number for the IndexBlock

IndexBlock

public IndexBlock(int seqNum,
                  long startTime,
                  long endTime,
                  int[] dataBlocks)
Creates an IndexBlock with the given data blocks.

Parameters:
seqNum - block's sequence number
startTime - time of the first data point in the first data block
endTime - time of the last data point in the last data block
dataBlocks - array of 1 or more data blocks.

IndexBlock

public IndexBlock(byte[] data)
           throws BadFileException
Constructs a new IndexBlock by reading it from the given byte array.

Parameters:
data - non-null byte[]
Throws:
BadFileException - if the data integrity of the block is not correct
Method Detail

getMinSize

public static int getMinSize()
Returns the size, in bytes, of the smallest possible IndexBlock, the empty block.


getSize

public static int getSize(int numBlocks)
Returns the size, in bytes, of the IndexBlock that holds 'numBlocks' data block indexes.


getMaxDataBlocks

public static int getMaxDataBlocks(int blockSize)
Given a block size in bytes, returns the number of data block indicies that this IndexBlock can hold.

Parameters:
blockSize - a block size in bytes, greater than or equal to getMinSize().
Returns:
maximum size of the dataBlocks array to fit within 'blockSize' bytes

getSeqNum

public int getSeqNum()

getStartTime

public long getStartTime()
Returns the timestamp of the first data point in the first data block

Specified by:
getStartTime in interface Range

getEndTime

public long getEndTime()
Specified by:
getEndTime in interface Range

getDataBlocks

public int[] getDataBlocks()

write

public void write(java.io.DataOutput output)
           throws java.io.IOException
Description copied from interface: DataOutputWritable
Writes this object to the given DataOutput. This method should not have any side-effects on this object as it may be used to discover sizes before writing.

Parameters:
output - non-null DataOutput
Throws:
java.io.IOException

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2008-2010 Jason Winnebeck. All Rights Reserved.