org.imemex.componentmappings.impl
Class AbstractComponentReplica<T>

java.lang.Object
  extended by org.imemex.componentmappings.impl.AbstractComponentReplica<T>
All Implemented Interfaces:
ComponentMapping<T>, ComponentReplica<T>, Persistable
Direct Known Subclasses:
DefaultGroupComponentReplica, DefaultNameComponentReplica, InMemoryTupleComponentReplica

public abstract class AbstractComponentReplica<T>
extends java.lang.Object
implements ComponentReplica<T>, Persistable

Sample default implementation of ComponentReplica based on a HashMap. The HashMap is used to provide efficient access for methods requiring the internalRVID. The query simply returns all elements contained in the HashMap. This class uses the Template Method pattern to make replication and persistence behaviour definable by its subclasses.

Author:
jens

Constructor Summary
AbstractComponentReplica(java.io.File storageDir)
          Instantiates a new AbstractComponentReplica.
 
Method Summary
 void clear()
          Clears (drops) this ComponentMap.
 void close()
          Closes this ComponentMap.
 PullOperator<Mapping<T>> entries()
          Returns all entries stored by this replica.
 void flushMapping()
          Flushes memory-resident index structures to disk in order to allow querying to take place after indexing.
 int getBufferSize()
          since all elements are buffered in the hashmap before calling close() we set the buffer size to Integer.MAX_VALUE
 T getEntry(long oid)
          Returns the component entry for the given resource view specified by oid.
 boolean insert(long internalRVID, T newEntry)
          Inserts the given mapping into this ComponentMap.
 boolean insertAll(PullOperator<Mapping<T>> entries)
          Inserts all entries of the given PullOperator into this ComponentMap.
 boolean isEmpty()
          Returns true if this instance does not contain any entries.
 boolean isLoadingReplica()
           
 void read(java.io.DataInput dataInput)
          Reads the state of this instance from the given .
 void rebuildMapping(boolean online)
          Rebuilds and optimzes the mapping (for instance an index).
 void remove(long internalRVID)
          Removes the given entries for resource view internalRVID.
 void removeAll(PullOperator<java.lang.Long> oids)
          Removes the given entries for resource view internalRVID.
 long size()
          Returns the number of entries.
 void write(java.io.DataOutput dataOutput)
          Writes the state of this instance to the gieven
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractComponentReplica

public AbstractComponentReplica(java.io.File storageDir)
Instantiates a new AbstractComponentReplica.

Method Detail

insert

public boolean insert(long internalRVID,
                      T newEntry)
Description copied from interface: ComponentMapping
Inserts the given mapping into this ComponentMap. If the entry already exists, it will be updated. Note, that all implementations of this method are responsible themselves to copy the newEntry instances. This is very important for ComponentReplicas.

Specified by:
insert in interface ComponentMapping<T>
Parameters:
internalRVID - - globally unique key used to identify a resource view in iMeMex
newEntry - - the instance to index
Returns:
true if this RV component was added to the index, false otherwise (i.e., the entry already existed in the index but was updated)

remove

public void remove(long internalRVID)
Description copied from interface: ComponentMapping
Removes the given entries for resource view internalRVID.

Specified by:
remove in interface ComponentMapping<T>
Parameters:
internalRVID - - globally unique key used to identify a resource view in iMeMex

insertAll

public boolean insertAll(PullOperator<Mapping<T>> entries)
Description copied from interface: ComponentMapping
Inserts all entries of the given PullOperator into this ComponentMap. Every entry that already exists will be updated. Note, that all implementations of this method are responsible themselves to copy the newEntry instances. This is very important for ComponentReplicas.

Specified by:
insertAll in interface ComponentMapping<T>
Parameters:
entries - - is a PullOperator with Map.Entry instances.
Returns:
true if all RV components were added to the index, false otherwise (i.e., at least one of the entries already existed in the index which was then updated)
See Also:
Map.Entry

isEmpty

public boolean isEmpty()
Description copied from interface: ComponentMapping
Returns true if this instance does not contain any entries.

Specified by:
isEmpty in interface ComponentMapping<T>
Returns:

size

public long size()
Description copied from interface: ComponentMapping
Returns the number of entries.

Specified by:
size in interface ComponentMapping<T>
Returns:

clear

public void clear()
Description copied from interface: ComponentMapping
Clears (drops) this ComponentMap.

Specified by:
clear in interface ComponentMapping<T>

rebuildMapping

public void rebuildMapping(boolean online)
                    throws OnlineRebuildNotSupportedException
Description copied from interface: ComponentMapping
Rebuilds and optimzes the mapping (for instance an index).

Specified by:
rebuildMapping in interface ComponentMapping<T>
Parameters:
online - - if true allows concurrent modifications to this ComponentMapping while rebuilding. If false this ComponentMapping is locked and no modifications are allowed during the rebuild.
Throws:
OnlineRebuildNotSupportedException

close

public void close()
Description copied from interface: ComponentMapping
Closes this ComponentMap.

Specified by:
close in interface ComponentMapping<T>

getEntry

public T getEntry(long oid)
Description copied from interface: ComponentReplica
Returns the component entry for the given resource view specified by oid. Implementations of this interface represent replicated components (caches, copies, materialized views, etc.) that may be used to speed up query processing.

Specified by:
getEntry in interface ComponentReplica<T>
Parameters:
oid - - globally unique key used to identify a resource view in iMeMex.
Returns:
the component instance stored by this replica for the given oid.

entries

public PullOperator<Mapping<T>> entries()
Description copied from interface: ComponentReplica
Returns all entries stored by this replica. Entries returned are instances of Mapping.

Specified by:
entries in interface ComponentReplica<T>
Returns:
a pull operator of Mapping instances that contain all mappings from OID to the appropriate resource view component stored in this replica.
See Also:
org.imemex.resourceviewmanager.componentmappings.Mapping

read

public void read(java.io.DataInput dataInput)
          throws java.io.IOException
Description copied from interface: Persistable
Reads the state of this instance from the given .

Specified by:
read in interface Persistable
Throws:
java.io.IOException

write

public void write(java.io.DataOutput dataOutput)
           throws java.io.IOException
Description copied from interface: Persistable
Writes the state of this instance to the gieven

Specified by:
write in interface Persistable
Throws:
java.io.IOException

removeAll

public void removeAll(PullOperator<java.lang.Long> oids)
Description copied from interface: ComponentMapping
Removes the given entries for resource view internalRVID.

Specified by:
removeAll in interface ComponentMapping<T>
Parameters:
oids - - a PullOperator of Long instances representing internalRVIDs

flushMapping

public void flushMapping()
Description copied from interface: ComponentMapping
Flushes memory-resident index structures to disk in order to allow querying to take place after indexing.

Specified by:
flushMapping in interface ComponentMapping<T>

getBufferSize

public int getBufferSize()
since all elements are buffered in the hashmap before calling close() we set the buffer size to Integer.MAX_VALUE

Specified by:
getBufferSize in interface ComponentMapping<T>
Returns:
the number of elements which are buffered before being stored persistently by the index

isLoadingReplica

public boolean isLoadingReplica()