[MOBY-guts] biomoby commit
Martin Senger
senger at pub.open-bio.org
Mon Sep 19 08:08:32 UTC 2005
senger
Mon Sep 19 04:08:32 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv29075/src/main/org/biomoby/client
Modified Files:
CentralDigestCachedImpl.java CentralImpl.java
Log Message:
caching also namespaces
moby-live/Java/src/main/org/biomoby/client CentralDigestCachedImpl.java,1.5,1.6 CentralImpl.java,1.25,1.26
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java 2005/08/26 06:27:04 1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java 2005/09/19 08:08:32 1.6
@@ -50,6 +50,7 @@
private String cacheDir; // as defined in the constructor
protected File dataTypesCache;
protected File servicesCache;
+ protected File namespacesCache;
// cache age
private long cacheAge = -1;
@@ -95,11 +96,15 @@
long dataTypesCacheAge = (isCacheEmpty (dataTypesCache) ? -1 : dataTypesCache.lastModified());
servicesCache = createSubCacheDir (cache, "services");
long servicesCacheAge = (isCacheEmpty (servicesCache) ? -1 : servicesCache.lastModified());
+ namespacesCache = createSubCacheDir (cache, "namespaces");
+ long namespacesCacheAge = (isCacheEmpty (namespacesCache) ? -1 : namespacesCache.lastModified());
- if (dataTypesCacheAge > -1 && servicesCacheAge > -1)
- cacheAge = Math.min (dataTypesCacheAge, servicesCacheAge);
+ if (dataTypesCacheAge > -1 && servicesCacheAge > -1 && namespacesCacheAge > -1)
+ cacheAge = Math.min (Math.min (dataTypesCacheAge, servicesCacheAge),
+ namespacesCacheAge);
else
- cacheAge = Math.max (dataTypesCacheAge, servicesCacheAge);
+ cacheAge = Math.max (Math.max (dataTypesCacheAge, servicesCacheAge),
+ namespacesCacheAge);
}
}
@@ -318,6 +323,20 @@
}
}
+ //
+ protected void fillNamespacesCache()
+ throws MobyException {
+ try {
+ String xml = getNamespacesAsXML();
+ store (namespacesCache, "all_namespaces_in_one_go", xml);
+ if (cacheAge <= 0)
+ cacheAge = namespacesCache.lastModified();
+
+ } catch (Exception e) {
+ throw new MobyException (formatException (e));
+ }
+ }
+
// read all data types
public MobyDataType[] getDataTypes()
throws MobyException {
@@ -375,6 +394,35 @@
}
}
+// public MobyNamespace[] getNamespaces()
+ public Map getNamespaces()
+ throws MobyException {
+ if (namespacesCache == null)
+ return super.getNamespaces();
+ synchronized (namespacesCache) {
+ if (isCacheEmpty (namespacesCache)) {
+ initCache();
+ fillNamespacesCache();
+ }
+ File[] list = namespacesCache.listFiles();
+ if (list == null)
+ throw new MobyException
+ ("Surprisingly, '" + namespacesCache.getAbsolutePath() + "' is not a directory. Strange...");
+ for (int i = 0; i < list.length; i++) {
+ try {
+ if (list[i].getPath().endsWith ("~"))
+ continue; // ignore some files
+ return createNamespacesFromXML (load (list[i]));
+ } catch (MobyException e) {
+ System.err.println ("Ignoring '" + list[i].getPath() +
+ "'. It should not be in the cache directory:" +
+ e.getMessage());
+ }
+ }
+ }
+ return null;
+ }
+
/**************************************************************************
* It always (if it functions as a cache which is when 'cacheDir'
* was given) disables caching in the parent (so no memory caching
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java 2005/09/04 13:45:37 1.25
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralImpl.java 2005/09/19 08:08:32 1.26
@@ -848,14 +848,26 @@
public Map getNamespaces()
throws MobyException {
+ String result = getNamespacesAsXML();
+ return createNamespacesFromXML (result);
+ }
+
+ //
+ protected String getNamespacesAsXML()
+ throws MobyException {
+ return (String)doCall ("retrieveNamespaces",
+ new Object[] {});
+ }
+
+ //
+ protected Map createNamespacesFromXML (String result)
+ throws MobyException {
+
String cacheId = "retrieveNamespaces";
Map cachedResults = (Map)getContents (cacheId);
if (cachedResults != null)
return cachedResults;
- String result = (String)doCall ("retrieveNamespaces",
- new Object[] {});
-
// parse returned XML
Map results = new HashMap();
Document document = null;
More information about the MOBY-guts
mailing list