org.geotools.caching.grid.featurecache
Class GridFeatureCache

java.lang.Object
  extended by org.geotools.caching.featurecache.AbstractFeatureCache
      extended by org.geotools.caching.grid.featurecache.GridFeatureCache
All Implemented Interfaces:
java.util.EventListener, FeatureCache, FeatureListener, FeatureSource
Direct Known Subclasses:
StreamingGridFeatureCache

public class GridFeatureCache
extends AbstractFeatureCache

An implementation of a feature cache.

This implementation holds a write lock on the cache while it access features from the feature source. As a result during this time no other features can read or write to the cache.


Field Summary
protected  int capacity
           
protected  int max_tiles
           
protected  GridSpatialIndex tracker
           
 
Fields inherited from class org.geotools.caching.featurecache.AbstractFeatureCache
ff, fs, lock, logger, source_feature_reads, source_hits
 
Constructor Summary
GridFeatureCache(FeatureSource fs, int indexcapacity, int capacity, Storage store)
           
GridFeatureCache(FeatureSource fs, ReferencedEnvelope env, int gridsize, int capacity, Storage store)
          Creates a new grid feature cache.
 
Method Summary
 void clear()
          Clears the cache.
 void dispose()
          Disposes of the cache.
 ReferencedEnvelope getBounds()
          Gets the bounds of the cache.
 ReferencedEnvelope getBounds(Query query)
          Gets the bounds of the data that match a given query.
 int getCount(Query query)
          Gets the count of the data that match a given query.
protected static ReferencedEnvelope getFeatureBounds(FeatureSource fs)
          Private function used to get the bounds of a feature collection and convert the IOException to a FeatureCacheException
 SpatialIndex getIndex()
          returns the spatial index that is used to implement the cache
 org.opengis.feature.simple.SimpleFeatureType getSchema()
          Returns the feature schema of the underlying feature source; checks the feature store first to see if it's in there
 java.lang.String getStats()
          Gets the feature cache statistics
 java.util.Set getSupportedHints()
          Returns the set of hints this FeatureSource is able to support.
protected  void isOversized(FeatureCollection fc)
          Determines if the given feature collection is too big to put into the cache.
 java.util.List<com.vividsolutions.jts.geom.Envelope> match(com.vividsolutions.jts.geom.Envelope e)
          This function looks in the cache for missing tiles.
 java.util.List<NodeIdentifier>[] matchNodeIds(com.vividsolutions.jts.geom.Envelope e)
          Converts and envelope into a list of nodes that the envelope covers.
 FeatureCollection peek(com.vividsolutions.jts.geom.Envelope e)
          Looks in the cache for any elements within the given envelope.
 void put(FeatureCollection fc)
          Adds a feature collection to the cache.
 void put(FeatureCollection fc, com.vividsolutions.jts.geom.Envelope e)
          Adds a feature collection to the cache.
 void register(java.util.Collection<NodeIdentifier> nodes)
          Registers a collection of nodes as valid.
protected  void register(com.vividsolutions.jts.geom.Envelope e)
          Registers a given envelope in the cache.
 void remove(com.vividsolutions.jts.geom.Envelope e)
          Removes an area from the cache.
 java.lang.String toString()
           
 void unregister(java.util.Collection<NodeIdentifier> nodes)
          Un-registers a collection of nodes.
protected  void unregister(com.vividsolutions.jts.geom.Envelope e)
          Unregisters all nodes in a given envelope.
 
Methods inherited from class org.geotools.caching.featurecache.AbstractFeatureCache
_getFeatures, addFeatureListener, changed, get, getDataStore, getFeatures, getFeatures, getFeatures, getInfo, getName, getQueryCapabilities, readLock, readUnLock, register, register, removeFeatureListener, sourceAccessStats, unregister, unregister, writeLock, writeUnLock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

max_tiles

protected int max_tiles

tracker

protected GridSpatialIndex tracker

capacity

protected int capacity
Constructor Detail

GridFeatureCache

public GridFeatureCache(FeatureSource fs,
                        int indexcapacity,
                        int capacity,
                        Storage store)
                 throws FeatureCacheException
Parameters:
FeatureStore - from which to cache features
indexcapacity - = number of tiles in index
capacity - = max number of features to cache; Integer.MAX_VALUE will cache all features
Throws:
FeatureCacheException
java.io.IOException

GridFeatureCache

public GridFeatureCache(FeatureSource fs,
                        ReferencedEnvelope env,
                        int gridsize,
                        int capacity,
                        Storage store)
Creates a new grid feature cache.

Parameters:
fs - FeatureStore from which to cache features
env - The size of the feature cache; once defined features outside this bounds cannot be added to the featurestore/cache
gridsize - number of tiles in the index
capacity - maximum number of features to cache
store - the cache storage
Method Detail

getIndex

public SpatialIndex getIndex()
returns the spatial index that is used to implement the cache

Returns:

getFeatureBounds

protected static ReferencedEnvelope getFeatureBounds(FeatureSource fs)
                                              throws FeatureCacheException
Private function used to get the bounds of a feature collection and convert the IOException to a FeatureCacheException

Parameters:
fs -
Returns:
Throws:
FeatureCacheException

getSchema

public org.opengis.feature.simple.SimpleFeatureType getSchema()
Returns the feature schema of the underlying feature source; checks the feature store first to see if it's in there

Specified by:
getSchema in interface FeatureSource
Overrides:
getSchema in class AbstractFeatureCache
Returns:
the schema of features created by this datasource.

match

public java.util.List<com.vividsolutions.jts.geom.Envelope> match(com.vividsolutions.jts.geom.Envelope e)
This function looks in the cache for missing tiles.

Specified by:
match in class AbstractFeatureCache
Parameters:
e -
Returns:
if there are more than 10 missing tiles than a single envelope is returned that encompasses all missing tiles; otherwise only the envelopes for the tiles that are missing are returned.

matchNodeIds

public java.util.List<NodeIdentifier>[] matchNodeIds(com.vividsolutions.jts.geom.Envelope e)
Converts and envelope into a list of nodes that the envelope covers. This returns array that contains two lists; the first is all the nodes that intersect the envelope and are missing from the cache; the second contains all the nodes that intersect the envelope and are present in the cache.

Parameters:
e - envelope to search
Returns:
list of two arrays {missing nodes, present nodes}

clear

public void clear()
Clears the cache.


dispose

public void dispose()
Disposes of the cache.


peek

public FeatureCollection peek(com.vividsolutions.jts.geom.Envelope e)
Looks in the cache for any elements within the given envelope.

Returns a in-memory feature collection.

Returns:
Collection of features found in the cache.

put

public void put(FeatureCollection fc,
                com.vividsolutions.jts.geom.Envelope e)
         throws CacheOversizedException
Adds a feature collection to the cache.

Parameters:
fc - the feature collection to add to the cache
e - the envelope that encompasses the feature collection added
Throws:
CacheOversizedException

isOversized

protected void isOversized(FeatureCollection fc)
                    throws CacheOversizedException
Description copied from class: AbstractFeatureCache
Determines if the given feature collection is too big to put into the cache.

Specified by:
isOversized in class AbstractFeatureCache
Throws:
CacheOversizedException - if feature collection is to big for cache

remove

public void remove(com.vividsolutions.jts.geom.Envelope e)
Removes an area from the cache.


getBounds

public ReferencedEnvelope getBounds()
                             throws java.io.IOException
Gets the bounds of the cache.

This maybe be larger than the data bounds.

Returns:
The bounding box of the datasource or null if unknown and too expensive for the method to calculate.
Throws:
java.io.IOException - if there are errors getting the bounding box.

getBounds

public ReferencedEnvelope getBounds(Query query)
                             throws java.io.IOException
Gets the bounds of the data that match a given query.

This function is passed along to the feature source.

Parameters:
query - Contains the Filter, and optionally MaxFeatures and StartIndex to find the bounds for.
Returns:
The bounding box of the datasource or null if unknown and too expensive for the method to calculate or any errors occur.
Throws:
java.io.IOException - DOCUMENT ME!

getCount

public int getCount(Query query)
             throws java.io.IOException
Gets the count of the data that match a given query.

This function is passed along to the feature source.

Parameters:
query - Contains the Filter, and optionally MaxFeatures and StartIndex to find the count for.
Returns:
The number of Features provided by the Query or -1 if count is too expensive to calculate or any errors or occur.
Throws:
java.io.IOException - if there are errors getting the count

put

public void put(FeatureCollection fc)
         throws CacheOversizedException
Adds a feature collection to the cache.

Parameters:
fc - the feature collection to add to the cache
Throws:
CacheOversizedException - if the feature collection has too many features for the cache.

register

protected void register(com.vividsolutions.jts.geom.Envelope e)
Registers a given envelope in the cache. All nodes within this envelope are flagged as valid.

Specified by:
register in class AbstractFeatureCache

register

public void register(java.util.Collection<NodeIdentifier> nodes)
Registers a collection of nodes as valid.

Parameters:
nodes -

unregister

public void unregister(java.util.Collection<NodeIdentifier> nodes)
Un-registers a collection of nodes.

Parameters:
nodes -

unregister

protected void unregister(com.vividsolutions.jts.geom.Envelope e)
Unregisters all nodes in a given envelope.

Specified by:
unregister in class AbstractFeatureCache

toString

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

getSupportedHints

public java.util.Set getSupportedHints()
Description copied from interface: FeatureSource
Returns the set of hints this FeatureSource is able to support.

Hints are to be specified in the Query, for each data access where they may be required.
Depending on the actual value provide by the user, the FeatureSource may decide not to honor the hint.

Returns:
a set of RenderingHints#Key objects (eventually empty, never null).

getStats

public java.lang.String getStats()
Description copied from class: AbstractFeatureCache
Gets the feature cache statistics

Specified by:
getStats in class AbstractFeatureCache
Returns:


Copyright © 1996-2010 Geotools. All Rights Reserved.