com.timeindexing.io
Class ExternalIndexIO

java.lang.Object
  extended bycom.timeindexing.io.AbstractIndexIO
      extended bycom.timeindexing.io.AbstractFileIO
          extended bycom.timeindexing.io.ExternalIndexIO
All Implemented Interfaces:
IndexFileInteractor, IndexFileReader, IndexFileWriter, IndexInteractor, java.lang.Runnable
Direct Known Subclasses:
ShadowIndexIO

public class ExternalIndexIO
extends AbstractFileIO
implements IndexFileInteractor

This does I/O for an Index with external data. There are major / primary events on:


Constructor Summary
ExternalIndexIO(StoredIndex managedIndex)
          Construct an External Index.
 
Method Summary
protected  long alignForData()
          Align the index for an append of the Data
protected  long bufferedDataWrite(java.nio.ByteBuffer buffer)
          Write a buffer of data.
protected  long bufferedIndexWrite(java.nio.ByteBuffer buffer)
          Write a buffer of index items.
 long calculateAppendPosition()
          Calculate the append position from the last item of the index.
 long close()
          Operation on close
 DataHolderObject convertDataReference(DataReference dataReference)
          Read some data, given a DataReference and return it as a DataHolderObject.
 long create(IndexProperties indexProperties)
          Operation on creation.
 long flush()
          Operation on flush.
 ManagedIndexItem getItem(long position, boolean doLoadData)
          Get the item at index position Position.
 boolean gotoAppendPosition()
          Goto the append position
 boolean gotoFirstPosition()
          Goto the first position
protected  java.nio.ByteBuffer memoryMapData(long offset, long size)
          Memory map some data from a channel.
protected  long open()
          Open an index to read it.
 long open(IndexProperties indexProperties)
          Open an index file to read it.
protected  long processData(java.nio.ByteBuffer buffer)
          Processing of the data.
protected  long processIndexItem(java.nio.ByteBuffer buffer)
          Processing of the idnex item.
 long readDataHeader(byte headerType)
          Read an index header from the header stream.
protected  long readDataIntoBuffer(java.nio.ByteBuffer buffer, long size)
          Actually read in the data.
 long readMetaData()
          Read all the meta data.
protected  boolean seekToData(long position)
          Seek to a certain position in the data file.
protected  boolean seekToIndex(long position)
          Seek to a certain position.
 boolean setAppendPosition()
          Set the append position from the indexChannelPosition.
 long writeDataHeader(byte headerType)
          Write the data file header.
 
Methods inherited from class com.timeindexing.io.AbstractFileIO
addItem, alignForIndexItem, awaitWork, bufferedWrite, drainWriteQueue, flushBuffer, getAppendPosition, getItem, getWriteLock, isWriteLocked, loadIndex, readData, readData, readData, readHeader, readIndexItem, readIndexItem, readItem, readItem, readNormalData, readReferenceData, releaseWriteLock, requestReadWork, requestWriteWork, run, seekToData, seekToIndex, setItemSize, skipData, timeOut, writeFromWorkQueue, writeHeader, writeItem, writeNormal, writeReference
 
Methods inherited from class com.timeindexing.io.AbstractIndexIO
getIndex, getThread, initThread, startThread, stopThread
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.timeindexing.io.IndexInteractor
addItem, getIndex, getItem
 
Methods inherited from interface com.timeindexing.io.IndexFileReader
loadIndex, readData, readData, readData, readHeader, readItem, readItem
 
Methods inherited from interface com.timeindexing.io.IndexFileWriter
getAppendPosition, getWriteLock, isWriteLocked, releaseWriteLock, writeHeader, writeItem
 

Constructor Detail

ExternalIndexIO

public ExternalIndexIO(StoredIndex managedIndex)
Construct an External Index.

Method Detail

create

public long create(IndexProperties indexProperties)
            throws java.io.IOException,
                   IndexCreateException
Operation on creation.

Specified by:
create in interface IndexFileWriter
Throws:
java.io.IOException
IndexCreateException

open

public long open(IndexProperties indexProperties)
          throws java.io.IOException,
                 IndexOpenException
Open an index file to read it.

Specified by:
open in interface IndexFileReader
Throws:
java.io.IOException
IndexOpenException

open

protected long open()
             throws java.io.IOException,
                    IndexOpenException
Open an index to read it. It normaises indexFileName and dataFileName.

Throws:
java.io.IOException
IndexOpenException

readMetaData

public long readMetaData()
                  throws java.io.IOException,
                         IndexOpenException
Read all the meta data.

Specified by:
readMetaData in interface IndexFileReader
Throws:
java.io.IOException
IndexOpenException

getItem

public ManagedIndexItem getItem(long position,
                                boolean doLoadData)
                         throws java.io.IOException
Get the item at index position Position.

Specified by:
getItem in interface IndexFileReader
Specified by:
getItem in class AbstractFileIO
Throws:
java.io.IOException

alignForData

protected long alignForData()
                     throws java.io.IOException
Align the index for an append of the Data

Specified by:
alignForData in class AbstractFileIO
Throws:
java.io.IOException

processIndexItem

protected long processIndexItem(java.nio.ByteBuffer buffer)
                         throws java.io.IOException
Processing of the idnex item.

Specified by:
processIndexItem in class AbstractFileIO
Throws:
java.io.IOException

processData

protected long processData(java.nio.ByteBuffer buffer)
                    throws java.io.IOException
Processing of the data.

Specified by:
processData in class AbstractFileIO
Throws:
java.io.IOException

bufferedIndexWrite

protected long bufferedIndexWrite(java.nio.ByteBuffer buffer)
                           throws java.io.IOException
Write a buffer of index items.

Specified by:
bufferedIndexWrite in class AbstractFileIO
Throws:
java.io.IOException

bufferedDataWrite

protected long bufferedDataWrite(java.nio.ByteBuffer buffer)
                          throws java.io.IOException
Write a buffer of data.

Specified by:
bufferedDataWrite in class AbstractFileIO
Throws:
java.io.IOException

readDataIntoBuffer

protected long readDataIntoBuffer(java.nio.ByteBuffer buffer,
                                  long size)
                           throws java.io.IOException
Actually read in the data.

Specified by:
readDataIntoBuffer in class AbstractFileIO
Throws:
java.io.IOException

memoryMapData

protected java.nio.ByteBuffer memoryMapData(long offset,
                                            long size)
                                     throws java.io.IOException
Memory map some data from a channel.

Specified by:
memoryMapData in class AbstractFileIO
Throws:
java.io.IOException

convertDataReference

public DataHolderObject convertDataReference(DataReference dataReference)
Read some data, given a DataReference and return it as a DataHolderObject.

Specified by:
convertDataReference in interface IndexFileReader
Overrides:
convertDataReference in class AbstractFileIO

seekToIndex

protected boolean seekToIndex(long position)
                       throws java.io.IOException
Seek to a certain position.

Specified by:
seekToIndex in class AbstractFileIO
Returns:
true if actually had to move the position, returns false if in correct place
Throws:
java.io.IOException

seekToData

protected boolean seekToData(long position)
                      throws java.io.IOException
Seek to a certain position in the data file.

Specified by:
seekToData in class AbstractFileIO
Returns:
true if actually had to move the position, returns false if in correct place
Throws:
java.io.IOException

flush

public long flush()
           throws java.io.IOException
Operation on flush. Returns how many bytes were written.

Specified by:
flush in interface IndexFileWriter
Throws:
java.io.IOException

close

public long close()
           throws java.io.IOException
Operation on close

Specified by:
close in interface IndexFileReader
Returns:
the size of the index
Throws:
java.io.IOException

readDataHeader

public long readDataHeader(byte headerType)
                    throws java.io.IOException,
                           IndexOpenException
Read an index header from the header stream.

Throws:
java.io.IOException
IndexOpenException

writeDataHeader

public long writeDataHeader(byte headerType)
                     throws java.io.IOException
Write the data file header. Write the contents of the header out It assumes the data file is alreayd open for writing.

Throws:
java.io.IOException

gotoAppendPosition

public boolean gotoAppendPosition()
                           throws java.io.IOException
Goto the append position

Specified by:
gotoAppendPosition in interface IndexFileReader
Overrides:
gotoAppendPosition in class AbstractFileIO
Throws:
java.io.IOException

gotoFirstPosition

public boolean gotoFirstPosition()
                          throws java.io.IOException
Goto the first position

Specified by:
gotoFirstPosition in interface IndexFileReader
Overrides:
gotoFirstPosition in class AbstractFileIO
Throws:
java.io.IOException

setAppendPosition

public boolean setAppendPosition()
                          throws java.io.IOException
Set the append position from the indexChannelPosition.

Specified by:
setAppendPosition in interface IndexFileReader
Overrides:
setAppendPosition in class AbstractFileIO
Throws:
java.io.IOException

calculateAppendPosition

public long calculateAppendPosition()
                             throws java.io.IOException
Calculate the append position from the last item of the index.

Specified by:
calculateAppendPosition in class AbstractFileIO
Throws:
java.io.IOException