org.biomoby.client.taverna.plugin
Class CacheImpl

java.lang.Object
  extended by org.biomoby.client.taverna.plugin.CacheImpl

public class CacheImpl
extends java.lang.Object

An implementation of CentralAll, allowing to cache locally results of the cumulative methods so it does not need to access Moby registry all the time. The other methods of the Central interface do not use the results of the cached cumulative results (their implementation is just passed to the parent class).

The caching is done in the file system, not in memory, so the results are permanent (until someone removes the caching directory, or calls removeFromCache(java.lang.String)).

This class can be used also without caching - just instantiate it with 'cacheDir' set to null in the constructor.

Version:
$Id: CacheImpl.java,v 1.2 2007/12/03 14:19:15 edwardkawas Exp $
Author:
Martin Senger

Field Summary
static java.lang.String CACHE_PART_DATATYPES
          An ID used in removeFromCache(java.lang.String) indicating data types part.
static java.lang.String CACHE_PART_SERVICES
          An ID used in removeFromCache(java.lang.String) indicating services part.
static java.lang.String CACHE_PROP_COUNT
           
static java.lang.String CACHE_PROP_LOCATION
           
static java.lang.String CACHE_PROP_NAME
           
static java.lang.String CACHE_PROP_OLDEST
           
static java.lang.String CACHE_PROP_SIZE
           
static java.lang.String CACHE_PROP_YOUNGEST
           
static java.lang.String DATATYPE_FILENAME
           
static java.lang.String SERVICE_INSTANCE_FILENAME
           
 
Constructor Summary
CacheImpl(java.lang.String cacheDir)
          Create an instance that will access a default Moby registry and will cache results in the 'cacheDir' directory.
CacheImpl(java.lang.String endpoint, java.lang.String namespace, java.lang.String cacheDir)
          Create an instance that will access a Moby registry defined by its 'endpoint' and 'namespace', and will cache results in the 'cacheDir' directory.
 
Method Summary
 long getCacheAge()
          Return age of the current (whole) cache in millis from the beginning of the Epoch; or -1 if cache is empty, or the age is unknown.
 java.lang.String getCacheDir()
          Return a directory name representing the current cache.
 java.lang.String getDatatypeRDFLocation()
           
 java.lang.String getMOBYCENTRAL_REGISTRY_URI()
           
 java.lang.String getMOBYCENTRAL_REGISTRY_URL()
           
 java.lang.String getServiceInstanceRDFLocation()
           
 void removeFromCache(java.lang.String id)
          Removes object groups from the cache.
 void setDatatypeRDFLocation(java.lang.String datatypeRDFLocation)
           
 void setMOBYCENTRAL_REGISTRY_URI(java.lang.String mobycentral_registry_uri)
           
 void setMOBYCENTRAL_REGISTRY_URL(java.lang.String mobycentral_registry_url)
           
 void setServiceInstanceRDFLocation(java.lang.String serviceInstanceRDFLocation)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_PART_DATATYPES

public static final java.lang.String CACHE_PART_DATATYPES
An ID used in removeFromCache(java.lang.String) indicating data types part.

See Also:
Constant Field Values

CACHE_PART_SERVICES

public static final java.lang.String CACHE_PART_SERVICES
An ID used in removeFromCache(java.lang.String) indicating services part.

See Also:
Constant Field Values

CACHE_PROP_NAME

public static final java.lang.String CACHE_PROP_NAME
See Also:
Constant Field Values

CACHE_PROP_COUNT

public static final java.lang.String CACHE_PROP_COUNT
See Also:
Constant Field Values

CACHE_PROP_OLDEST

public static final java.lang.String CACHE_PROP_OLDEST
See Also:
Constant Field Values

CACHE_PROP_YOUNGEST

public static final java.lang.String CACHE_PROP_YOUNGEST
See Also:
Constant Field Values

CACHE_PROP_SIZE

public static final java.lang.String CACHE_PROP_SIZE
See Also:
Constant Field Values

CACHE_PROP_LOCATION

public static final java.lang.String CACHE_PROP_LOCATION
See Also:
Constant Field Values

SERVICE_INSTANCE_FILENAME

public static final java.lang.String SERVICE_INSTANCE_FILENAME
See Also:
Constant Field Values

DATATYPE_FILENAME

public static final java.lang.String DATATYPE_FILENAME
See Also:
Constant Field Values
Constructor Detail

CacheImpl

public CacheImpl(java.lang.String cacheDir)
          throws org.biomoby.shared.MobyException
Create an instance that will access a default Moby registry and will cache results in the 'cacheDir' directory.

Throws:
org.biomoby.shared.MobyException

CacheImpl

public CacheImpl(java.lang.String endpoint,
                 java.lang.String namespace,
                 java.lang.String cacheDir)
          throws org.biomoby.shared.MobyException
Create an instance that will access a Moby registry defined by its 'endpoint' and 'namespace', and will cache results in the 'cacheDir' directory. Note that the same 'cacheDir' can be safely used for more Moby registries.

Throws:
org.biomoby.shared.MobyException
Method Detail

getCacheDir

public java.lang.String getCacheDir()
Return a directory name representing the current cache. This is the same name as given in constructors.

Returns:
current cache directory name

removeFromCache

public void removeFromCache(java.lang.String id)
Removes object groups from the cache. If 'id' is null it removes the whole cache (for that Moby registry this instance was initiated for). Otherwise 'id' indicates which part of the cache that will be removed.

Parameters:
id - should be either null, or one of the following: CACHE_PART_DATATYPES, CACHE_PART_SERVICES, #CACHE_PART_SERVICETYPES, and #CACHE_PART_NAMESPACES.

getCacheAge

public long getCacheAge()
Return age of the current (whole) cache in millis from the beginning of the Epoch; or -1 if cache is empty, or the age is unknown.

Returns:
the cache age which is taken as the oldest (but filled) cache part (part is considered e.g. 'services', or 'data types', not their individual entities)

getServiceInstanceRDFLocation

public java.lang.String getServiceInstanceRDFLocation()
Returns:
the serviceInstanceRDFLocation

setServiceInstanceRDFLocation

public void setServiceInstanceRDFLocation(java.lang.String serviceInstanceRDFLocation)
Parameters:
serviceInstanceRDFLocation - the serviceInstanceRDFLocation to set

getMOBYCENTRAL_REGISTRY_URI

public java.lang.String getMOBYCENTRAL_REGISTRY_URI()
Returns:
the mOBYCENTRAL_REGISTRY_URI

setMOBYCENTRAL_REGISTRY_URI

public void setMOBYCENTRAL_REGISTRY_URI(java.lang.String mobycentral_registry_uri)
Parameters:
mobycentral_registry_uri - the mOBYCENTRAL_REGISTRY_URI to set

getMOBYCENTRAL_REGISTRY_URL

public java.lang.String getMOBYCENTRAL_REGISTRY_URL()
Returns:
the MOBYCENTRAL_REGISTRY_URL

setMOBYCENTRAL_REGISTRY_URL

public void setMOBYCENTRAL_REGISTRY_URL(java.lang.String mobycentral_registry_url)
Parameters:
mobycentral_registry_url - the MOBYCENTRAL_REGISTRY_URL to set

getDatatypeRDFLocation

public java.lang.String getDatatypeRDFLocation()
Returns:
the datatypeRDFLocation

setDatatypeRDFLocation

public void setDatatypeRDFLocation(java.lang.String datatypeRDFLocation)
Parameters:
datatypeRDFLocation - the datatypeRDFLocation to set