org.geotoolkit.coverage
Class CoverageReferences

Object
  extended by CoverageReferences

@ThreadSafe
public class CoverageReferences
extends Object

Holds weak references to coverage instances. Every call to the reference(org.opengis.coverage.Coverage) method with the same Coverage instance will return the same WeakReference instance. If all weak references to a coverage have been created by the same instance of CoverageReferences (typically the DEFAULT one), then it is guaranteed that given:

Coverage coverageA = ...;
Coverage coverageB = ...;

WeakReference<Coverage> refA = reference(coverageA);
WeakReference<Coverage> refB = reference(coverageB);
then testing (refA == refB) is equivalent to testing (coverageA == coverageB) Comparing the references instead than the coverages can keep comparisons mainfull even after the coverages have been garbage collected. This is sometime useful for checking if two results of a calculation were done using the same coverage inputs, without preventing garbage-collection of those coverages.

Because a weak references created by this class may be shared by many, invoking Reference.clear() on them has no effect. Only the garbage-collector can clear the references.

Note: This class may be extended in a future version with coverage-specific enhancements. For example we could prevent the garbage-collection of a coverage as long as the JAI TileCache has not disposed the image tiles. This class is defined in this package instead than in the more generic org.geotoolkit.util.collection package for that reason.

Since:
2.1
Version:
3.13
Author:
Martin Desruisseaux (IRD, Geomatys)
Module:
coverage/geotk-coverage (download)    View source code for this class

Field Summary
static CoverageReferences DEFAULT
          The default, system-wide weak references for coverages.
 
Constructor Summary
protected CoverageReferences()
          Creates a new coverage cache.
 
Method Summary
 Reference<Coverage> reference(Coverage coverage)
          Returns a weak reference to the specified coverage.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final CoverageReferences DEFAULT
The default, system-wide weak references for coverages.

Constructor Detail

CoverageReferences

protected CoverageReferences()
Creates a new coverage cache. This method is given protected access for subclassing only. For typical usage, the DEFAULT instance should be used instead.

Method Detail

reference

public Reference<Coverage> reference(Coverage coverage)
Returns a weak reference to the specified coverage. If such reference already exists for the specified coverage, then that reference is returned. Otherwise, a new WeakReference is created and returned.

Parameters:
coverage - The coverage to reference.
Returns:
A unique weak reference to the specified coverage.


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.