com.timeindexing.index
Class FileIndex

java.lang.Object
  extended by com.timeindexing.index.AbstractIndex
      extended by com.timeindexing.index.FileIndex
All Implemented Interfaces:
IndexEventGenerator, ExtendedIndex, ExtendedIndexHeader, Index, IndexHeader, ManagedIndex, ManagedIndexHeader, StoredIndex
Direct Known Subclasses:
ExternalIndex, InlineIndex

public abstract class FileIndex
extends AbstractIndex
implements StoredIndex

A place holder abstract class for stored Index objects that are stored in files.


Constructor Summary
FileIndex()
           
 
Method Summary
 Index activate()
          Make the Index activated.
 boolean addIndexURI(ID indexID, java.net.URI URIName)
          Add a new indexID/indexURI
 IndexItem addItem(DataItem dataitem)
          Add a Data Item to the Index.
 IndexItem addItem(DataItem dataitem, Timestamp dataTS)
          Add a Data Item to the Index plus a Timestamp from the Data.
 IndexItem addItem(DataItem dataitem, Timestamp dataTS, long annotation)
          Add a Data Item to the Index plus a Timestamp from the Data.
 IndexItem addReference(IndexItem item, Index other)
          Add a Referemnce to an IndexItem in a Index.
 IndexItem addReference(IndexItem otherItem, Index otherIndex, Timestamp dataTS)
          Add a Referemnce to an IndexItem in a Index.
 IndexItem addReference(IndexItem otherItem, Index otherIndex, Timestamp dataTS, long annotation)
          Add a Referemnce to an IndexItem in a Index.
 IndexItem addReference(IndexReference reference, Timestamp dataTS)
          Add a Referemnce to an IndexItem in a Index.
 IndexItem addReference(IndexReference reference, Timestamp dataTS, long annotation)
          Add a Referemnce to an IndexItem in a Index.
 IndexView addView()
          Add a view to this index.
 IndexView asView()
          Get a view onto the Index.
 boolean close()
          Close this index.
 boolean closeView(IndexView view)
          Close this index.
 boolean commit()
          Commit this index.
 java.net.URI generateURI(java.lang.String pathname)
          Construct a URI from a pathname.
 IndexProperties getAllOptions()
          Get all the option from the header.
 Offset getFirstOffset()
          Get the Offset of the fisrt item.
 ManagedIndexHeader getHeader()
          Get the headerfor the index.
 java.lang.String getHeaderPathName()
          Get the path of the index header.
 java.net.URI getIndexURI(ID indexID)
          Get the index URI of a nominated index.
 IndexItem getItem(long n)
          Get an Index Item from the Index.
 Position getLastFlushPosition()
          Get the IndexItem Position when the index was last flushed.
 Timestamp getLastFlushTime()
          Get the last time the index was flushed.
 Offset getLastOffset()
          Get the Offset of the last item.
 java.lang.Object getOption(HeaderOption option)
          Get an option from the header.
 Index getTrackedIndex(ID indexID)
          Get an Index being tracked
 boolean hasIndexURI(java.net.URI URIName)
          Does this index have the URI of some other index
 boolean hasOption(HeaderOption option)
          Does an option exist in the header.
protected  boolean isOpen(java.lang.String name)
          Try and determine if this index is alreay open
 boolean isTrackingIndex(ID indexID)
          Is an Index being tracked
 boolean isWriteLocked()
          Has the Index been write-locked.
 java.util.Set listOptions()
          Get the set of optional header values.
 java.util.Collection listTrackedIndexes()
          List all the Referenced Indexes.
 ManagedIndexHeader notInTimeOrder()
          State that the index is not in time order any more.
 DataHolderObject readData(long pos, DataReference dataReference)
          Read data for an index item given a DataReference.
 boolean reallyClose()
          Close this index.
 long removeView(IndexView view)
          Remove a view from this index.
 long retrieveItem(IndexItem item, long position)
          Retrieve an Index Item into the Index.
 ManagedIndexHeader setDataPathName(java.lang.String path)
          Set the path of the data if the index data style is external or shadow.
 ManagedIndexHeader setDataSize(long size)
          Set the size of the data items, if there is fixed size data.
 ManagedIndexHeader setDescription(Description d)
          Set the description.
 ManagedIndexHeader setEndTime(Timestamp end)
          Set the end time
 ManagedIndexHeader setFirstDataTime(Timestamp first)
          Set the first data time
 ManagedIndexHeader setFirstOffset(Offset offset)
          Set the Offset of the fisrt item.
 ManagedIndexHeader setFirstTime(Timestamp first)
          Set the first time
 ManagedIndexHeader setID(ID id)
          Set the ID of the index.
 ManagedIndexHeader setIndexDataType(DataType type)
          Set the data type of the index.
 ManagedIndexHeader setIndexPathName(java.lang.String path)
          Set the path of the index file
 ManagedIndexHeader setIndexType(IndexType type)
          Set the type of the index.
 ManagedIndexHeader setItemSize(int size)
          Set the size of the index items.
 ManagedIndexHeader setLastDataTime(Timestamp last)
          Set the last data time
 ManagedIndexHeader setLastOffset(Offset offset)
          Set the Offset of the last item.
 ManagedIndexHeader setLastTime(Timestamp last)
          Set the last time
 ManagedIndexHeader setLength(long length)
          Set the no of items in the index.
 ManagedIndexHeader setName(java.lang.String name)
          Set the name of the index.
 ManagedIndexHeader setOption(HeaderOption option, java.lang.Object object)
          Set an option in the header.
 ManagedIndexHeader setOptions(IndexProperties someProperties)
          Set options in the header based on the passed IndexProperties.
 ManagedIndexHeader setReadOnly(boolean readonly)
          Set the read only status.
 ManagedIndexHeader setStartTime(Timestamp start)
          Set the start time
 ManagedIndexHeader setTerminated(boolean t)
          Set the index to be terminated.
 ManagedIndexHeader setURI(java.net.URI uri)
          Set the URI of the index.
 boolean syncHeader(ManagedIndexHeader indexHeader)
          Syncrhronize the values in this index header from values in a specified IndexHeader object.
 int trackReferencedIndex(Index index)
          Track a Referenced Index.
protected  long writeItem(FileIndexItem item)
          Write an IndexItem to the Index.
 
Methods inherited from class com.timeindexing.index.AbstractIndex
addAccessEventListener, addAddEventListener, addDataType, addItem, addPrimaryEventListener, apply, binarySearch, contains, contains, eventMulticaster, filter, getAnnotationStyle, getCache, getCachePolicy, getDataPathName, getDataSize, getDataType, getDescription, getEndTime, getFirstDataTime, getFirstTime, getID, getIndexDataType, getIndexPathName, getIndexType, getItem, getItem, getItem, getItemSize, getLastAccessTime, getLastDataTime, getLastTime, getLength, getLoadDataAutomatically, getName, getStartTime, getURI, hasAnnotations, hasDataType, isActivated, isChanged, isClosed, isFixedSizeData, isInTimeOrder, isReadOnly, isTerminated, iterator, locate, locate, locate, locate, map, removeAccessEventListener, removeAddEventListener, removePrimaryEventListener, select, select, select, select, setAutoCommit, setCachePolicy, setLastAccessTime, setLoadDataAutomatically, terminate, updateDescription
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.timeindexing.index.ManagedIndex
addView, closeView, create, getHeader, getTrackedIndex, isTrackingIndex, listTrackedIndexes, open, removeView, trackReferencedIndex
 
Methods inherited from interface com.timeindexing.index.ExtendedIndex
getIndexType
 
Methods inherited from interface com.timeindexing.index.Index
addDataType, apply, asView, close, contains, contains, filter, getAnnotationStyle, getCachePolicy, getDataType, getItem, getItem, getItem, getItemSize, getLastAccessTime, getLoadDataAutomatically, hasAnnotations, hasDataType, isActivated, isChanged, isClosed, iterator, locate, locate, locate, locate, map, select, select, select, select, setAutoCommit, setCachePolicy, setLoadDataAutomatically, terminate, updateDescription
 
Methods inherited from interface com.timeindexing.index.ManagedIndexHeader
addIndexURI, getAllOptions, getIndexURI, getOption, hasIndexURI, hasOption, listOptions, notInTimeOrder, setDataPathName, setDataSize, setDescription, setEndTime, setFirstDataTime, setFirstOffset, setFirstTime, setID, setIndexDataType, setIndexPathName, setIndexType, setItemSize, setLastDataTime, setLastOffset, setLastTime, setLength, setName, setOption, setOptions, setReadOnly, setStartTime, setTerminated, setURI, syncHeader
 
Methods inherited from interface com.timeindexing.index.ExtendedIndexHeader
addDataType, getAnnotationStyle, getDataSize, getDataType, getItemSize, hasAnnotations, hasDataType
 
Methods inherited from interface com.timeindexing.index.IndexHeader
getDataPathName, getDescription, getEndTime, getFirstDataTime, getFirstTime, getID, getIndexDataType, getIndexPathName, getLastDataTime, getLastTime, getLength, getName, getStartTime, getURI, isFixedSizeData, isInTimeOrder, isReadOnly, isTerminated
 
Methods inherited from interface com.timeindexing.event.IndexEventGenerator
addAccessEventListener, addAddEventListener, addPrimaryEventListener, removeAccessEventListener, removeAddEventListener, removePrimaryEventListener
 

Constructor Detail

FileIndex

public FileIndex()
Method Detail

commit

public boolean commit()
               throws IndexCommitException
Commit this index.

Specified by:
commit in interface Index
Overrides:
commit in class AbstractIndex
Returns:
true if the index isActivated and isChanged, otherwise return false
Throws:
IndexCommitException

reallyClose

public boolean reallyClose()
                    throws IndexCloseException
Close this index.

Specified by:
reallyClose in interface ManagedIndex
Throws:
IndexCloseException

addItem

public IndexItem addItem(DataItem dataitem)
                  throws IndexTerminatedException,
                         IndexClosedException,
                         IndexActivationException,
                         AddItemException
Add a Data Item to the Index. The data timestamp will be the same as the record timestamp. The ID will be generated. There are no annotations.

Specified by:
addItem in interface Index
Specified by:
addItem in class AbstractIndex
Parameters:
dataitem - the DataItem to add
Returns:
the no of items in the index.
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addItem

public IndexItem addItem(DataItem dataitem,
                         Timestamp dataTS)
                  throws IndexTerminatedException,
                         IndexClosedException,
                         IndexActivationException,
                         AddItemException
Add a Data Item to the Index plus a Timestamp from the Data. The ID will be generated. There are no annotations.

Specified by:
addItem in interface Index
Specified by:
addItem in class AbstractIndex
Parameters:
dataitem - the IndexItem to add
dataTS - the Timestamp for the data, null implies that the data Timestamp is the same as the record Timestamp
Returns:
the no of items in the index.
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addItem

public IndexItem addItem(DataItem dataitem,
                         Timestamp dataTS,
                         long annotation)
                  throws IndexTerminatedException,
                         IndexClosedException,
                         IndexActivationException,
                         AddItemException
Add a Data Item to the Index plus a Timestamp from the Data. The ID will be generated. There are no annotations.

Specified by:
addItem in interface Index
Specified by:
addItem in class AbstractIndex
Parameters:
dataitem - the IndexItem to add
dataTS - the Timestamp for the data, null implies that the data Timestamp is the same as the record Timestamp
annotation - the annotation meta data
Returns:
the no of items in the index.
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addReference

public IndexItem addReference(IndexItem item,
                              Index other)
                       throws IndexTerminatedException,
                              IndexClosedException,
                              IndexActivationException,
                              AddItemException
Add a Referemnce to an IndexItem in a Index.

Specified by:
addReference in interface Index
Specified by:
addReference in class AbstractIndex
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addReference

public IndexItem addReference(IndexItem otherItem,
                              Index otherIndex,
                              Timestamp dataTS)
                       throws IndexTerminatedException,
                              IndexClosedException,
                              IndexActivationException,
                              AddItemException
Add a Referemnce to an IndexItem in a Index.

Specified by:
addReference in interface Index
Specified by:
addReference in class AbstractIndex
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addReference

public IndexItem addReference(IndexItem otherItem,
                              Index otherIndex,
                              Timestamp dataTS,
                              long annotation)
                       throws IndexTerminatedException,
                              IndexClosedException,
                              IndexActivationException,
                              AddItemException
Add a Referemnce to an IndexItem in a Index.

Specified by:
addReference in interface Index
Specified by:
addReference in class AbstractIndex
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addReference

public IndexItem addReference(IndexReference reference,
                              Timestamp dataTS)
                       throws IndexTerminatedException,
                              IndexClosedException,
                              IndexActivationException,
                              AddItemException
Add a Referemnce to an IndexItem in a Index. This version takes the Index URI, the Index ID, the IndexItem's Position, and the IndexItem's data Timestamp. It is used internally when doing a TimeIndexFactory.save().

Specified by:
addReference in interface ManagedIndex
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addReference

public IndexItem addReference(IndexReference reference,
                              Timestamp dataTS,
                              long annotation)
                       throws IndexTerminatedException,
                              IndexClosedException,
                              IndexActivationException,
                              AddItemException
Add a Referemnce to an IndexItem in a Index. This version takes the Index URI, the Index ID, the IndexItem's Position, and the IndexItem's data Timestamp. It is used internally when doing a TimeIndexFactory.save().

Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

getItem

public IndexItem getItem(long n)
                  throws GetItemException,
                         IndexClosedException
Get an Index Item from the Index.

Specified by:
getItem in interface Index
Specified by:
getItem in class AbstractIndex
Throws:
GetItemException
IndexClosedException

writeItem

protected long writeItem(FileIndexItem item)
                  throws IndexTerminatedException,
                         IndexClosedException,
                         IndexActivationException,
                         AddItemException
Write an IndexItem to the Index.

Returns:
the size of the resulting index.
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

retrieveItem

public long retrieveItem(IndexItem item,
                         long position)
Retrieve an Index Item into the Index.

Specified by:
retrieveItem in interface StoredIndex
Parameters:
item - the IndexItem to add
position - the position to load the IndexItem at
Returns:
the no of items in the cache

readData

public DataHolderObject readData(long pos,
                                 DataReference dataReference)
Read data for an index item given a DataReference.

Specified by:
readData in interface StoredIndex

getHeaderPathName

public java.lang.String getHeaderPathName()
Get the path of the index header.


getLastFlushTime

public Timestamp getLastFlushTime()
Get the last time the index was flushed.

Specified by:
getLastFlushTime in interface ExtendedIndex

getLastFlushPosition

public Position getLastFlushPosition()
Get the IndexItem Position when the index was last flushed.

Specified by:
getLastFlushPosition in interface ExtendedIndex

getFirstOffset

public Offset getFirstOffset()
Get the Offset of the fisrt item.

Specified by:
getFirstOffset in interface ExtendedIndex
Specified by:
getFirstOffset in interface ExtendedIndexHeader

getLastOffset

public Offset getLastOffset()
Get the Offset of the last item.

Specified by:
getLastOffset in interface ExtendedIndex
Specified by:
getLastOffset in interface ExtendedIndexHeader

activate

public Index activate()
               throws IndexReadOnlyException,
                      IndexWriteLockedException
Make the Index activated.

Specified by:
activate in interface Index
Throws:
IndexReadOnlyException
IndexWriteLockedException

isWriteLocked

public boolean isWriteLocked()
Has the Index been write-locked.

Specified by:
isWriteLocked in interface Index

generateURI

public java.net.URI generateURI(java.lang.String pathname)
                         throws java.net.URISyntaxException
Construct a URI from a pathname.

Throws:
java.net.URISyntaxException

setName

public ManagedIndexHeader setName(java.lang.String name)
Set the name of the index.

Specified by:
setName in interface ManagedIndexHeader

setID

public ManagedIndexHeader setID(ID id)
Set the ID of the index.

Specified by:
setID in interface ManagedIndexHeader

setURI

public ManagedIndexHeader setURI(java.net.URI uri)
Set the URI of the index.

Specified by:
setURI in interface ManagedIndexHeader

setStartTime

public ManagedIndexHeader setStartTime(Timestamp start)
Set the start time

Specified by:
setStartTime in interface ManagedIndexHeader

setEndTime

public ManagedIndexHeader setEndTime(Timestamp end)
Set the end time

Specified by:
setEndTime in interface ManagedIndexHeader

setFirstTime

public ManagedIndexHeader setFirstTime(Timestamp first)
Set the first time

Specified by:
setFirstTime in interface ManagedIndexHeader

setLastTime

public ManagedIndexHeader setLastTime(Timestamp last)
Set the last time

Specified by:
setLastTime in interface ManagedIndexHeader

setFirstDataTime

public ManagedIndexHeader setFirstDataTime(Timestamp first)
Set the first data time

Specified by:
setFirstDataTime in interface ManagedIndexHeader

setLastDataTime

public ManagedIndexHeader setLastDataTime(Timestamp last)
Set the last data time

Specified by:
setLastDataTime in interface ManagedIndexHeader

setLength

public ManagedIndexHeader setLength(long length)
Set the no of items in the index.

Specified by:
setLength in interface ManagedIndexHeader

setTerminated

public ManagedIndexHeader setTerminated(boolean t)
Set the index to be terminated.

Specified by:
setTerminated in interface ManagedIndexHeader

setItemSize

public ManagedIndexHeader setItemSize(int size)
Set the size of the index items.

Specified by:
setItemSize in interface ManagedIndexHeader

setDataSize

public ManagedIndexHeader setDataSize(long size)
Set the size of the data items, if there is fixed size data.

Specified by:
setDataSize in interface ManagedIndexHeader

setFirstOffset

public ManagedIndexHeader setFirstOffset(Offset offset)
Set the Offset of the fisrt item.

Specified by:
setFirstOffset in interface ManagedIndexHeader

setLastOffset

public ManagedIndexHeader setLastOffset(Offset offset)
Set the Offset of the last item.

Specified by:
setLastOffset in interface ManagedIndexHeader

setIndexType

public ManagedIndexHeader setIndexType(IndexType type)
Set the type of the index. Either inline or external or shadow.

Specified by:
setIndexType in interface ManagedIndexHeader

setIndexDataType

public ManagedIndexHeader setIndexDataType(DataType type)
Set the data type of the index. Some indexes have the same type throughout, other have mixed type data.

Specified by:
setIndexDataType in interface ManagedIndexHeader

setIndexPathName

public ManagedIndexHeader setIndexPathName(java.lang.String path)
Set the path of the index file

Specified by:
setIndexPathName in interface ManagedIndexHeader

setDataPathName

public ManagedIndexHeader setDataPathName(java.lang.String path)
Set the path of the data if the index data style is external or shadow.

Specified by:
setDataPathName in interface ManagedIndexHeader

setDescription

public ManagedIndexHeader setDescription(Description d)
Set the description. This is one of the few attributes of an index that can be set directly.

Specified by:
setDescription in interface ManagedIndexHeader

setReadOnly

public ManagedIndexHeader setReadOnly(boolean readonly)
Set the read only status.

Specified by:
setReadOnly in interface ManagedIndexHeader

notInTimeOrder

public ManagedIndexHeader notInTimeOrder()
State that the index is not in time order any more.

Specified by:
notInTimeOrder in interface ManagedIndexHeader

getIndexURI

public java.net.URI getIndexURI(ID indexID)
Get the index URI of a nominated index.

Specified by:
getIndexURI in interface ExtendedIndexHeader
Specified by:
getIndexURI in interface ManagedIndexHeader

hasIndexURI

public boolean hasIndexURI(java.net.URI URIName)
Does this index have the URI of some other index

Specified by:
hasIndexURI in interface ExtendedIndexHeader
Specified by:
hasIndexURI in interface ManagedIndexHeader

addIndexURI

public boolean addIndexURI(ID indexID,
                           java.net.URI URIName)
Add a new indexID/indexURI

Specified by:
addIndexURI in interface ExtendedIndexHeader
Specified by:
addIndexURI in interface ManagedIndexHeader
Returns:
true, if a new index URI was added; false, if the index had this ID/URI pair already

getOption

public java.lang.Object getOption(HeaderOption option)
Get an option from the header.

Specified by:
getOption in interface ManagedIndexHeader

setOption

public ManagedIndexHeader setOption(HeaderOption option,
                                    java.lang.Object object)
Set an option in the header.

Specified by:
setOption in interface ManagedIndexHeader

hasOption

public boolean hasOption(HeaderOption option)
Does an option exist in the header.

Specified by:
hasOption in interface ManagedIndexHeader

listOptions

public java.util.Set listOptions()
Get the set of optional header values.

Specified by:
listOptions in interface ManagedIndexHeader

getAllOptions

public IndexProperties getAllOptions()
Get all the option from the header.

Specified by:
getAllOptions in interface ManagedIndexHeader

setOptions

public ManagedIndexHeader setOptions(IndexProperties someProperties)
Set options in the header based on the passed IndexProperties.

Specified by:
setOptions in interface ManagedIndexHeader

trackReferencedIndex

public int trackReferencedIndex(Index index)
Track a Referenced Index.

Specified by:
trackReferencedIndex in interface ManagedIndex
Returns:
the number of tracked indexes

isTrackingIndex

public boolean isTrackingIndex(ID indexID)
Is an Index being tracked

Specified by:
isTrackingIndex in interface ManagedIndex

getTrackedIndex

public Index getTrackedIndex(ID indexID)
Get an Index being tracked

Specified by:
getTrackedIndex in interface ManagedIndex

listTrackedIndexes

public java.util.Collection listTrackedIndexes()
List all the Referenced Indexes.

Specified by:
listTrackedIndexes in interface ManagedIndex

getHeader

public ManagedIndexHeader getHeader()
Get the headerfor the index.

Specified by:
getHeader in interface ManagedIndex

syncHeader

public boolean syncHeader(ManagedIndexHeader indexHeader)
Syncrhronize the values in this index header from values in a specified IndexHeader object.

Specified by:
syncHeader in interface ManagedIndexHeader

close

public boolean close()
              throws IndexCloseException
Close this index.

Specified by:
close in interface Index
Returns:
true if the index is really closed by calling this
Throws:
IndexCloseException

closeView

public boolean closeView(IndexView view)
                  throws IndexCloseException
Close this index.

Specified by:
closeView in interface ManagedIndex
Returns:
true if the index is really closed by calling this
Throws:
IndexCloseException

isOpen

protected boolean isOpen(java.lang.String name)
Try and determine if this index is alreay open


asView

public IndexView asView()
Get a view onto the Index.

Specified by:
asView in interface Index

addView

public IndexView addView()
Add a view to this index.

Specified by:
addView in interface ManagedIndex
Returns:
the IndexView itself

removeView

public long removeView(IndexView view)
Remove a view from this index.

Specified by:
removeView in interface ManagedIndex
Returns:
How many views are still left on the Index


Timeindexing 2008