Version: 1.1.1

org.biomoby.client
Class CentralDigestCachedSimpleImpl

java.lang.Object
  extended by org.biomoby.client.CentralImpl
      extended by org.biomoby.client.CentralDigestImpl
          extended by org.biomoby.client.CentralDigestCachedSimpleImpl
All Implemented Interfaces:
SimpleCache, Central, CentralAll, CentralCached, CentralDigest, Notifier
Direct Known Subclasses:
CentralDigestCachedImpl

public class CentralDigestCachedSimpleImpl
extends CentralDigestImpl
implements CentralCached

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: CentralDigestCachedSimpleImpl.java,v 1.5 2009/08/13 21:26:26 kawas Exp $
Author:
Martin Senger

Field Summary
 
Fields inherited from class org.biomoby.client.CentralImpl
CENTRAL_IMPL_RESOURCE_NAME, DEFAULT_CENTRAL_IMPL_CLASSNAME, DEFAULT_ENDPOINT, DEFAULT_NAMESPACE, DOCUMENT_BUILDER_FACTORIES
 
Fields inherited from interface org.biomoby.shared.CentralCached
CACHE_PART_DATATYPES, CACHE_PART_NAMESPACES, CACHE_PART_SERVICES, CACHE_PART_SERVICETYPES, CACHE_PROP_COUNT, CACHE_PROP_LOCATION, CACHE_PROP_NAME, CACHE_PROP_OLDEST, CACHE_PROP_REGISTRY_URL, CACHE_PROP_SIZE, CACHE_PROP_YOUNGEST, LIST_FILE, RDF_FILE
 
Fields inherited from interface org.biomoby.shared.Central
DATA_TYPES_RESOURCE_NAME, FULL_RESOURCE_NAME, HAS, HASA, iHAS, iHASA, iISA, ISA, NAMESPACES_RESOURCE_NAME, SERVICE_INSTANCES_RESOURCE_NAME, SERVICE_TYPES_RESOURCE_NAME
 
Fields inherited from interface org.biomoby.shared.event.Notifier
AUTHORITIES_CANCELLED, AUTHORITIES_COUNT, AUTHORITIES_END, AUTHORITIES_RESET, AUTHORITIES_START, AUTHORITIES_UPDATED, AUTHORITY_LOADED, AUTHORITY_LOADING, DATA_TYPE_LOADED, DATA_TYPE_LOADING, DATA_TYPES_CANCELLED, DATA_TYPES_COUNT, DATA_TYPES_END, DATA_TYPES_RESET, DATA_TYPES_START, DATA_TYPES_UPDATED, NAMESPACE_LOADED, NAMESPACE_LOADING, NAMESPACES_CANCELLED, NAMESPACES_COUNT, NAMESPACES_END, NAMESPACES_RESET, NAMESPACES_START, NAMESPACES_UPDATED, SERVICE_TYPE_LOADED, SERVICE_TYPE_LOADING, SERVICE_TYPES_CANCELLED, SERVICE_TYPES_COUNT, SERVICE_TYPES_END, SERVICE_TYPES_RESET, SERVICE_TYPES_START, SERVICE_TYPES_UPDATED, SIGNAL_CANCEL_DATA_TYPES, SIGNAL_CANCEL_NAMESPACES, SIGNAL_CANCEL_SERVICE_TYPES, SIGNAL_CANCEL_SERVICES
 
Constructor Summary
CentralDigestCachedSimpleImpl(String cacheDir)
          Create an instance that will access a default Moby registry and will cache results in the 'cacheDir' directory.
CentralDigestCachedSimpleImpl(String endpoint, String namespace, 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.
 String getCacheDir()
          Return a directory name representing the current cache.
 Properties getCacheInfo(String id)
          Return as many properties describing the given part of a cache as possible.
 String getCacheInfoFormatted(String id)
          Similar as CentralCached.getCacheInfo(java.lang.String) but formatted into a single string.
 boolean getCacheMode()
          It always (again, if it functions as a cache which is when 'cacheDir' is given) reports that caching is disabled (even though for the cumulative results is actually always enabled - but that is obvious from the name of this class, isn't it?).
 Map getDataTypeNames()
          Parses and imports the following XML.
 MobyDataType[] getDataTypes()
          Get definition of all known data types.
 MobyNamespace[] getFullNamespaces()
          Parses and imports the following XML.
 Map getServiceNamesByAuthority()
          Parses and imports the following XML.
 MobyService[] getServices()
          Get definition of all registered service instances.
 boolean isUsingCache()
          Indicate whether the implementtaion really is using a local cache.
 void removeFromCache(String id)
          Removes object groups from the cache.
 void setCacheMode(boolean shouldCache)
          It always (if it functions as a cache which is when 'cacheDir' was given) disables caching in the parent (so no memory caching happens there).
 void updateCache(String id)
          Update the indicated part of the cache.
 
Methods inherited from class org.biomoby.client.CentralDigestImpl
addNotificationListener, addNotificationListeners, callback, fireEvent, fireEvent, getFullServiceTypes, getNotificationListeners, removeNotificationListener, removeNotificationListeners
 
Methods inherited from class org.biomoby.client.CentralImpl
call, createId, escapeXML, existsInCache, extractServices, findService, findService, findService, findService, findService, formatFault, formatFault, getContents, getDataType, getDataTypeRelationships, getDataTypeRelationships, getDefaultCentral, getDefaultCentral, getDefaultURI, getDefaultURL, getNamespaces, getProviders, getRegisterDataTypeXML, getRegisterNamespaceXML, getRegisterServiceTypeXML, getRegisterServiceXML, getRegistryEndpoint, getRegistryNamespace, getResource, getResourceRefs, getServiceNames, getServicesByAuthority, getServiceTypeRelationships, getServiceTypes, getServiceWSDL, getServiceWSDL, loadDocument, registerDataType, registerNamespace, registerService, registerServiceType, setContents, setDebug, unregisterDataType, unregisterNamespace, unregisterService, unregisterServiceType
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.biomoby.shared.Central
call, findService, findService, findService, findService, findService, getDataType, getDataTypeRelationships, getDataTypeRelationships, getNamespaces, getProviders, getRegistryEndpoint, getRegistryNamespace, getResource, getResourceRefs, getServiceNames, getServiceTypeRelationships, getServiceTypes, getServiceWSDL, getServiceWSDL, registerDataType, registerNamespace, registerService, registerServiceType, setDebug, unregisterDataType, unregisterNamespace, unregisterService, unregisterServiceType
 
Methods inherited from interface org.biomoby.shared.CentralDigest
getFullServiceTypes
 
Methods inherited from interface org.biomoby.shared.event.Notifier
addNotificationListener, addNotificationListeners, callback, fireEvent, fireEvent, getNotificationListeners, removeNotificationListener, removeNotificationListeners
 

Constructor Detail

CentralDigestCachedSimpleImpl

public CentralDigestCachedSimpleImpl(String cacheDir)
                              throws MobyException
Create an instance that will access a default Moby registry and will cache results in the 'cacheDir' directory.

Throws:
MobyException

CentralDigestCachedSimpleImpl

public CentralDigestCachedSimpleImpl(String endpoint,
                                     String namespace,
                                     String cacheDir)
                              throws 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:
MobyException
Method Detail

getCacheDir

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

Returns:
current cache directory name

isUsingCache

public boolean isUsingCache()
Indicate whether the implementtaion really is using a local cache.

Specified by:
isUsingCache in interface CentralCached
Returns:
true if a local cache is used

removeFromCache

public void removeFromCache(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.

Specified by:
removeFromCache in interface SimpleCache
Specified by:
removeFromCache in interface CentralCached
Overrides:
removeFromCache in class CentralImpl
Parameters:
id - should be either null, or one of the following: CentralCached.CACHE_PART_DATATYPES, CentralCached.CACHE_PART_SERVICES, CentralCached.CACHE_PART_SERVICETYPES, and CentralCached.CACHE_PART_NAMESPACES.

updateCache

public void updateCache(String id)
                 throws MobyException
Update the indicated part of the cache. If 'id' is null it updates the whole cache (for that Moby registry this instance was initiated for).

Updates means to fetch a new list of entities, compare it with existing entities in the cache, fetch the missing ones and remove the redundant ones.

Specified by:
updateCache in interface CentralCached
Parameters:
id - should be either null, or one of the following: CentralCached.CACHE_PART_DATATYPES, CentralCached.CACHE_PART_SERVICES, CentralCached.CACHE_PART_SERVICETYPES, and CentralCached.CACHE_PART_NAMESPACES.
Throws:
MobyException

getDataTypeNames

public Map getDataTypeNames()
                     throws MobyException
Description copied from class: CentralImpl
Parses and imports the following XML.
  <objectNames>
     <Object name="objectName" lsid="...">
            <Description><![CDATA[free text description here]]></Description>
     </Object>
          ...
          ...
  </objectNames>
 

Specified by:
getDataTypeNames in interface Central
Overrides:
getDataTypeNames in class CentralImpl
Returns:
a hash table where keys are names of data types while values are their descriptions
Throws:
MobyException - if communication with the Moby Registry fails

getDataTypes

public MobyDataType[] getDataTypes()
                            throws MobyException
Description copied from interface: CentralDigest
Get definition of all known data types. It is a cumulation of many individual calls to Central.getDataType(java.lang.String) for all registered data type names.

Specified by:
getDataTypes in interface Central
Specified by:
getDataTypes in interface CentralDigest
Overrides:
getDataTypes in class CentralDigestImpl
Throws:
MobyException - if communication with the Moby Registry fails

getServiceNamesByAuthority

public Map getServiceNamesByAuthority()
                               throws MobyException
Description copied from class: CentralImpl
Parses and imports the following XML.
 <serviceNames>
   <serviceName name="serviceName" lsid="..." authURI='authority.info.here'/>
   ...
   ...
 </serviceNames>
 

Specified by:
getServiceNamesByAuthority in interface Central
Overrides:
getServiceNamesByAuthority in class CentralImpl
Returns:
a Map which has authorities as keys, and String arrays with service names as a values.
Throws:
MobyException - if communication with the Moby Registry fails

getServices

public MobyService[] getServices()
                          throws MobyException
Description copied from interface: CentralDigest
Get definition of all registered service instances. It is a cumulation of many individual calls to findService by name for all known service names.

Specified by:
getServices in interface CentralDigest
Overrides:
getServices in class CentralDigestImpl
Throws:
MobyException - if communication with the Moby Registry fails

getFullNamespaces

public MobyNamespace[] getFullNamespaces()
                                  throws MobyException
Description copied from class: CentralImpl
Parses and imports the following XML.
  <Namespaces>
     <Namespace name="namespace" lsid="...">
            <Description><![CDATA[free text description here]]></Description>
            <contactEmail>...</contactEmail>
            <authURI>...</authURI>
     </Namespace>
          ...
          ...
  </Namespaces>
 

Specified by:
getFullNamespaces in interface Central
Overrides:
getFullNamespaces in class CentralDigestImpl
Returns:
array of namespaces
Throws:
MobyException - if communication with the Moby Registry fails

setCacheMode

public void setCacheMode(boolean shouldCache)
It always (if it functions as a cache which is when 'cacheDir' was given) disables caching in the parent (so no memory caching happens there).

Specified by:
setCacheMode in interface Central
Overrides:
setCacheMode in class CentralDigestImpl
Parameters:
shouldCache - whether retrieveXXX call results should be cached in case they are called again (i.e. don't request MobyCentral every time)

getCacheMode

public boolean getCacheMode()
It always (again, if it functions as a cache which is when 'cacheDir' is given) reports that caching is disabled (even though for the cumulative results is actually always enabled - but that is obvious from the name of this class, isn't it?).

Specified by:
getCacheMode in interface Central
Overrides:
getCacheMode in class CentralImpl
Returns:
true if caching is enabled

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.

Specified by:
getCacheAge in interface CentralCached
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)

getCacheInfo

public Properties getCacheInfo(String id)
Return as many properties describing the given part of a cache as possible. The key used for returned properties are publicly available from this class but other may be returned as well.

Specified by:
getCacheInfo in interface CentralCached
Parameters:
id - is a part of cache to be described, or null if the whole cache should be described (this may return different kind of properties than for individual cache parts)
Returns:
properties describing a cache

getCacheInfoFormatted

public String getCacheInfoFormatted(String id)
Description copied from interface: CentralCached
Similar as CentralCached.getCacheInfo(java.lang.String) but formatted into a single string.

Specified by:
getCacheInfoFormatted in interface CentralCached
Parameters:
id - is a part of cache to be described, or null if the whole cache should be described (this may return different kind of properties than for individual cache parts)
Returns:
a cache description

Version: 1.1.1

Submit a bug or feature
Generated: Sat May 29 04:26:35 EDT 2010