org.autoplot.datasource.ReferenceCache

Provide a cache of datasets that are in memory, so that the same data is not loaded twice. This first implementation uses WeakReferences, so that this cache need not be emptied, but we will avoid the situation where the same data is loaded twice.


PROP_ENABLE_REFERENCE_CACHE

System property the enables the reference cache. Clients should check this before using the cache with code like: boolean useReferenceCache= "true".equals( System.getProperty( ReferenceCache.PROP_ENABLE_REFERENCE_CACHE, "false" ) );


NULL

marker dataset used to indicate null was loaded for the URI. This dataset should not be used.


getDataSet

getDataSet( String uri ) → QDataSet

Query to see if the dataset exists in the cache. Null is returned if it is not, or a QDataSet is returned if it is. NOTE: the entry might be ReferenceCache.NULL, meaning the load resulted in no data.

Parameters

uri - the URI that can be resolved into a dataset.

Returns:

the dataset or null

[search for examples] [view on GitHub] [view on old javadoc] [view source]


getDataSetOrLock

getDataSetOrLock( String uri, ProgressMonitor monitor ) → ReferenceCacheEntry

Get a ReferenceCacheEntry for the URI, which will indicate the thread which has been designated as the load thread.


rcent= ReferenceCache.getInstance().getDataSetOrLock( this.tsb.getURI(), mon);
if ( !rcent.shouldILoad( Thread.currentThread() ) ) { 
   QDataSet result= rcent.park( mon );

Be sure to use try/finally when using this cache!

Parameters

uri - the URI to load.
monitor - to monitor the load.

Returns:

the ReferenceCacheEntry

[search for examples] [view on GitHub] [view on old javadoc] [view source]


getInstance

getInstance( ) → ReferenceCache

get the single instance of the ReferenceCache

Returns:

an org.autoplot.datasource.ReferenceCache

[search for examples] [view on GitHub] [view on old javadoc] [view source]


getReferenceCacheEntry

getReferenceCacheEntry( String uri ) → ReferenceCacheEntry

return the ReferenceCacheEntry, if any, for the URI. This is to resolve the ambiguity of the getDataSet call. Typically the status of the entry is called.

Parameters

uri - the URI that can be resolved into a dataset.

Returns:

null or the ReferenceCacheEntry.

[search for examples] [view on GitHub] [view on old javadoc] [view source]


offerDataSet

offerDataSet( String uri, QDataSet ds ) → void

like putDataSet, but if no one has requested this dataset, then simply add it to the cache of datasets in case someone else wants it. Be sure to call this before the call to putDataSet that will release the lock.

Parameters

uri - the URI
ds - the dataset

Returns:

void (returns nothing)

[search for examples] [view on GitHub] [view on old javadoc] [view source]


park

park( org.autoplot.datasource.ReferenceCache.ReferenceCacheEntry ent, ProgressMonitor monitor ) → void

park this thread until the other guy has finished loading.

Parameters

ent - a ReferenceCache.ReferenceCacheEntry
monitor - the monitor of the load.

Returns:

void (returns nothing)

[search for examples] [view on GitHub] [view on old javadoc] [view source]


printStatus

printStatus( ) → void

display the status of all the entries.

Returns:

void (returns nothing)

[search for examples] [view on GitHub] [view on old javadoc] [view source]


reset

reset( ) → void

explicitly remove entries from the cache.

Returns:

void (returns nothing)

[search for examples] [view on GitHub] [view on old javadoc] [view source]


tidy

tidy( ) → void

remove all the entries that have been garbage collected.

Returns:

void (returns nothing)

[search for examples] [view on GitHub] [view on old javadoc] [view source]