com.timeindexing.index
Class AbstractIndex

java.lang.Object
  extended bycom.timeindexing.index.AbstractIndex
All Implemented Interfaces:
ExtendedIndex, ExtendedIndexHeader, Index, IndexEventGenerator, IndexHeader
Direct Known Subclasses:
AbstractManagedIndex, SQLIndex

public abstract class AbstractIndex
extends java.lang.Object
implements ExtendedIndex, ExtendedIndexHeader, IndexEventGenerator

An abstract implementation of an Index object. It represents the index header, the index stream and the data stream.


Constructor Summary
protected AbstractIndex()
           
 
Method Summary
 void addAccessEventListener(IndexAccessEventListener l)
          Add a IndexAccessEventListener.
 void addAddEventListener(IndexAddEventListener l)
          Add a IndexAddEventListener.
 boolean addDataType(ID typeID, java.lang.String typeName)
          Add a new data type
abstract  long addItem(DataItem item)
          Add a Data Item to the Index.
abstract  long addItem(DataItem item, Timestamp dataTime)
          Add a Data Item to the Index with a speicifed Data Timestamp
 long addItem(IndexItem item)
          Add an Index Item to the Index.
 void addPrimaryEventListener(IndexPrimaryEventListener l)
          Add a IndexPrimaryEventListener.
protected  TimestampMapping binarySearch(Timestamp t, long start, long end, IndexTimestampSelector selector, Lifetime lifetime, int depth)
          Do a binary search of the list.
 boolean contains(Timestamp t, IndexTimestampSelector selector)
          Does a timestamp fall within the bounds of the Index.
 IndexEventMulticaster eventMulticaster()
          Get the event listener.
 int getAnnotationStyle()
          Get the annotation style.
 java.lang.String getDataPathName()
          Get the path of the data if the index data style is external or shadow.
 long getDataSize()
          Get the size of the data items, if there is fixed size data.
 java.lang.String getDataType(ID typeID)
          Get the type name of the things in the data stream.
 Description getDescription()
          Get the description for an index.
 Timestamp getEndTime()
          Get the end time of the index.
 Timestamp getFirstDataTime()
          Get the data time for the first IndexItem in the Index.
 Timestamp getFirstTime()
          Get the time the first IndexItem was put into the Index.
 ID getID()
          Get an ID of an index.
 DataType getIndexDataType()
          Get the index data type.
 java.lang.String getIndexPathName()
          Get the indexPath of the index.
 IndexType getIndexType()
          Get the index type.
 IndexItem getItem(long n)
          Get an Index Item from the Index.
 IndexItem getItem(Position p)
          Get an Index Item from the Index.
 IndexItem getItem(Timestamp t, IndexTimestampSelector sel, Lifetime lifetime)
          Get an Index Item from the Index.
 int getItemSize()
          Get the size of the items.
 Timestamp getLastAccessTime()
          Get the last time an IndexItem was accessed from the index.
 Timestamp getLastDataTime()
          Get the data time for the last IndexItem in the Index.
 Timestamp getLastTime()
          Get the time the last IndexItem was put into the Index.
 long getLength()
          Get the no of items in the index.
 java.lang.String getName()
          Get the name of the index.
 Timestamp getStartTime()
          Get the start time of the index.
 java.net.URI getURI()
          Get the Index specification in the form of a URI.
 boolean hasAnnotations()
          Does this index have annotations.
 boolean hasDataType(java.lang.String typeName)
          Does this index have a typed name.
 boolean isActivated()
          Is the Index activated.
 boolean isChanged()
          Has the index changed in any way.
 boolean isClosed()
          Is the Index closed.
 boolean isFixedSizeData()
          Does the index have fixed size data.
 boolean isInTimeOrder()
          Is the index still in time order.
 boolean isReadOnly()
          Is the Index only available for read-only operations.
 boolean isTerminated()
          Is the Index terminated.
 java.util.Iterator iterator()
          Get an iterator over the IndexItems in the Index.
 TimestampMapping locate(Timestamp t, IndexTimestampSelector selector, Lifetime lifetime)
          Try and determine the position associated with the speicifed Timestamp.
 void removeAccessEventListener(IndexAccessEventListener l)
          Remove a IndexAccessEventListener.
 void removeAddEventListener(IndexAddEventListener l)
          Remove a IndexAddEventListener.
 void removePrimaryEventListener(IndexPrimaryEventListener l)
          Remove a IndexPrimaryEventListener.
protected  Index setLastAccessTime()
          Set the last time an IndexItem was accessed from the index.
 Index terminate()
          Make the Index finalized.
 Index updateDescription(Description description)
          Set the description.
 
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.ExtendedIndex
getFirstOffset, getLastFlushPosition, getLastFlushTime, getLastOffset
 
Methods inherited from interface com.timeindexing.index.Index
activate, addReference, addReference, asView, close, flush, isWriteLocked
 
Methods inherited from interface com.timeindexing.index.ExtendedIndexHeader
addIndexURI, getIndexURI, hasIndexURI
 

Constructor Detail

AbstractIndex

protected AbstractIndex()
Method Detail

getName

public java.lang.String getName()
Get the name of the index.

Specified by:
getName in interface IndexHeader

getID

public ID getID()
Get an ID of an index.

Specified by:
getID in interface IndexHeader

getURI

public java.net.URI getURI()
Get the Index specification in the form of a URI.

Specified by:
getURI in interface IndexHeader

getStartTime

public Timestamp getStartTime()
Get the start time of the index. This is when the index was created not necessarliy when the first item was added to the index.

Specified by:
getStartTime in interface IndexHeader

getEndTime

public Timestamp getEndTime()
Get the end time of the index. This is the time the last item was closed, not necessarliy when the last item was added to the index.

Specified by:
getEndTime in interface IndexHeader

getFirstTime

public Timestamp getFirstTime()
Get the time the first IndexItem was put into the Index.

Specified by:
getFirstTime in interface IndexHeader
Returns:
ZeroTimestamp if there is no first item, usually when there are no items in the index

getLastTime

public Timestamp getLastTime()
Get the time the last IndexItem was put into the Index.

Specified by:
getLastTime in interface IndexHeader
Returns:
ZeroTimestamp if there is no last item, usually when there are no items in the index

getFirstDataTime

public Timestamp getFirstDataTime()
Get the data time for the first IndexItem in the Index.

Specified by:
getFirstDataTime in interface IndexHeader
Returns:
ZeroTimestamp if there is no first item, usually when there are no items in the index

getLastDataTime

public Timestamp getLastDataTime()
Get the data time for the last IndexItem in the Index.

Specified by:
getLastDataTime in interface IndexHeader
Returns:
ZeroTimestamp if there is no last item, usually when there are no items in the index

getItemSize

public int getItemSize()
Get the size of the items.

Specified by:
getItemSize in interface Index

isFixedSizeData

public boolean isFixedSizeData()
Does the index have fixed size data.

Specified by:
isFixedSizeData in interface IndexHeader

getDataSize

public long getDataSize()
Get the size of the data items, if there is fixed size data.

Specified by:
getDataSize in interface IndexHeader

getDataType

public java.lang.String getDataType(ID typeID)
Get the type name of the things in the data stream.

Specified by:
getDataType in interface Index

hasDataType

public boolean hasDataType(java.lang.String typeName)
Does this index have a typed name.

Specified by:
hasDataType in interface Index

addDataType

public boolean addDataType(ID typeID,
                           java.lang.String typeName)
Add a new data type

Specified by:
addDataType in interface Index
Returns:
true, if a new type was added; false, if the index had this ID/typeName pair already

getIndexType

public IndexType getIndexType()
Get the index type. Either inline or external.

Specified by:
getIndexType in interface ExtendedIndex

getIndexDataType

public DataType getIndexDataType()
Get the index data type. Some indexes have the same type throughout, other have mixed type data.

Specified by:
getIndexDataType in interface IndexHeader

isInTimeOrder

public boolean isInTimeOrder()
Is the index still in time order.

Specified by:
isInTimeOrder in interface IndexHeader

hasAnnotations

public boolean hasAnnotations()
Does this index have annotations.

Specified by:
hasAnnotations in interface Index

getAnnotationStyle

public int getAnnotationStyle()
Get the annotation style. Either inline or external.

Specified by:
getAnnotationStyle in interface Index

getLength

public long getLength()
Get the no of items in the index.

Specified by:
getLength in interface IndexHeader

addItem

public abstract long addItem(DataItem item)
                      throws IndexTerminatedException,
                             IndexClosedException,
                             IndexActivationException,
                             AddItemException
Add a Data Item to the Index.

Specified by:
addItem in interface Index
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addItem

public abstract long addItem(DataItem item,
                             Timestamp dataTime)
                      throws IndexTerminatedException,
                             IndexClosedException,
                             IndexActivationException,
                             AddItemException
Add a Data Item to the Index with a speicifed Data Timestamp

Specified by:
addItem in interface Index
Throws:
IndexTerminatedException
IndexClosedException
IndexActivationException
AddItemException

addItem

public long addItem(IndexItem item)
             throws IndexTerminatedException,
                    IndexClosedException,
                    IndexActivationException,
                    AddItemException
Add an Index Item to the Index.

Parameters:
item - the IndexItem to add
Returns:
the no of items in the index.
Throws:
IndexTerminatedException - if the index has been terminated and an attempt is made to add an Item
IndexActivationException - if the index has NOT been activated and an attempt is made to add an Item
IndexClosedException
AddItemException

getItem

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

Specified by:
getItem in interface Index
Throws:
GetItemException

getItem

public IndexItem getItem(Position p)
                  throws GetItemException
Get an Index Item from the Index.

Specified by:
getItem in interface Index
Throws:
GetItemException

getItem

public IndexItem getItem(Timestamp t,
                         IndexTimestampSelector sel,
                         Lifetime lifetime)
                  throws GetItemException
Get an Index Item from the Index.

Specified by:
getItem in interface Index
Throws:
GetItemException

getLastAccessTime

public Timestamp getLastAccessTime()
Get the last time an IndexItem was accessed from the index.

Specified by:
getLastAccessTime in interface Index

setLastAccessTime

protected Index setLastAccessTime()
Set the last time an IndexItem was accessed from the index.


getIndexPathName

public java.lang.String getIndexPathName()
Get the indexPath of the index.

Specified by:
getIndexPathName in interface IndexHeader
Returns:
null if there is no index path

getDataPathName

public java.lang.String getDataPathName()
Get the path of the data if the index data style is external or shadow.

Specified by:
getDataPathName in interface IndexHeader
Returns:
null if there is no data path

getDescription

public Description getDescription()
Get the description for an index.

Specified by:
getDescription in interface IndexHeader
Returns:
null if there is no description

updateDescription

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

Specified by:
updateDescription in interface Index

contains

public boolean contains(Timestamp t,
                        IndexTimestampSelector selector)
Does a timestamp fall within the bounds of the Index. The bounds are the first time data is put in and the last time data is put in the Index.

Specified by:
contains in interface Index

locate

public TimestampMapping locate(Timestamp t,
                               IndexTimestampSelector selector,
                               Lifetime lifetime)
Try and determine the position associated with the speicifed Timestamp.

Specified by:
locate in interface Index
Returns:
null if no position is found

binarySearch

protected TimestampMapping binarySearch(Timestamp t,
                                        long start,
                                        long end,
                                        IndexTimestampSelector selector,
                                        Lifetime lifetime,
                                        int depth)
                                 throws GetItemException
Do a binary search of the list.

Throws:
GetItemException

isActivated

public boolean isActivated()
Is the Index activated.

Specified by:
isActivated in interface Index

isTerminated

public boolean isTerminated()
Is the Index terminated.

Specified by:
isTerminated in interface IndexHeader

terminate

public Index terminate()
Make the Index finalized. It is not possible to add items ever again to an Index that has been terminated.

Specified by:
terminate in interface Index

isClosed

public boolean isClosed()
Is the Index closed.

Specified by:
isClosed in interface Index

isChanged

public boolean isChanged()
Has the index changed in any way.

Specified by:
isChanged in interface Index

isReadOnly

public boolean isReadOnly()
Is the Index only available for read-only operations.

Specified by:
isReadOnly in interface IndexHeader

iterator

public java.util.Iterator iterator()
Get an iterator over the IndexItems in the Index.

Specified by:
iterator in interface Index

eventMulticaster

public IndexEventMulticaster eventMulticaster()
Get the event listener.


addPrimaryEventListener

public void addPrimaryEventListener(IndexPrimaryEventListener l)
Add a IndexPrimaryEventListener.

Specified by:
addPrimaryEventListener in interface IndexEventGenerator

removePrimaryEventListener

public void removePrimaryEventListener(IndexPrimaryEventListener l)
Remove a IndexPrimaryEventListener.

Specified by:
removePrimaryEventListener in interface IndexEventGenerator

addAddEventListener

public void addAddEventListener(IndexAddEventListener l)
Add a IndexAddEventListener.

Specified by:
addAddEventListener in interface IndexEventGenerator

removeAddEventListener

public void removeAddEventListener(IndexAddEventListener l)
Remove a IndexAddEventListener.

Specified by:
removeAddEventListener in interface IndexEventGenerator

addAccessEventListener

public void addAccessEventListener(IndexAccessEventListener l)
Add a IndexAccessEventListener.

Specified by:
addAccessEventListener in interface IndexEventGenerator

removeAccessEventListener

public void removeAccessEventListener(IndexAccessEventListener l)
Remove a IndexAccessEventListener.

Specified by:
removeAccessEventListener in interface IndexEventGenerator