[MOBY-guts] biomoby commit

senger@ebi.ac.uk senger at pub.open-bio.org
Sun Nov 14 16:12:50 UTC 2004


senger
Sun Nov 14 11:12:50 EST 2004
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv27557/src/main/org/biomoby/client

Modified Files:
	CentralDigestCachedImpl.java 
Log Message:
added client caching data types and service instances in a local file system; useful for debugging apps that use the whole registry

moby-live/Java/src/main/org/biomoby/client CentralDigestCachedImpl.java,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java	2004/10/18 14:35:06	1.1
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java	2004/11/14 16:12:50	1.2
@@ -81,12 +81,14 @@
 	    File cache = createCacheDir (cacheDir, getRegistryEndpoint());
 	    messageLn ("Using cache directory: " + cache);
 	    dataTypesCache = createSubCacheDir (cache, "dataTypes");
+	    long dataTypesCacheAge = (isCacheEmpty (dataTypesCache) ? -1 : dataTypesCache.lastModified());
 	    servicesCache  = createSubCacheDir (cache, "services");
-	    if (cacheAge <= 0) {
-		// cache was not created now, it existed; so find its age
-		cacheAge = Math.min (dataTypesCache.lastModified(),
-				     servicesCache.lastModified());
-	    }
+	    long servicesCacheAge = (isCacheEmpty (servicesCache) ? -1 : servicesCache.lastModified());
+
+	    if (dataTypesCacheAge > -1 && servicesCacheAge > -1)
+		cacheAge = Math.min (dataTypesCacheAge, servicesCacheAge);
+	    else
+		cacheAge = Math.max (dataTypesCacheAge, servicesCacheAge);
 	}
     }
 
@@ -262,13 +264,7 @@
     protected boolean isCacheEmpty (File cache)
 	throws MobyException {
 	String[] list = cache.list();
-	if (list == null) {
-	    // try to re-create the cache (as empty, of course, but
-	    // ready to be used if somebody wants to fill it again)
-	    initCache();
-	    return true;
-	}
-	return (list.length == 0);
+	return ( list == null || list.length == 0 );
     }
 
     protected void fillDataTypesCache()
@@ -282,6 +278,8 @@
 		String xml = getDataTypeAsXML (name);
 		store (dataTypesCache, name, xml);
 	    }
+	    if (cacheAge <= 0)
+		cacheAge = dataTypesCache.lastModified();
 
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
@@ -300,6 +298,9 @@
 		String xml = getServicesAsXML (new MobyService (name), null, true, true);
 		store (servicesCache, name, xml);
 	    }
+	    if (cacheAge <= 0)
+		cacheAge = servicesCache.lastModified();
+
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
 	}
@@ -312,8 +313,10 @@
 	    return super.getDataTypes();
 	synchronized (dataTypesCache) {
 	    Vector v = new Vector();
-	    if (isCacheEmpty (dataTypesCache))
+	    if (isCacheEmpty (dataTypesCache)) {
+		initCache();
 		fillDataTypesCache();
+	    }
 	    File[] list = dataTypesCache.listFiles();
 	    if (list == null)
 		throw new MobyException ("Surprisingly, '" + dataTypesCache.getAbsolutePath() + "' is not a directory. Strange...");
@@ -337,8 +340,10 @@
 	    return super.getServices();
 	synchronized (servicesCache) {
 	    Vector v = new Vector();
-	    if (isCacheEmpty (servicesCache))
+	    if (isCacheEmpty (servicesCache)) {
+		initCache();
 		fillServicesCache();
+	    }
 	    File[] list = servicesCache.listFiles();
 	    if (list == null)
 		throw new MobyException ("Surprisingly, '" + servicesCache.getAbsolutePath() + "' is not a directory. Strange...");
@@ -376,6 +381,8 @@
      * 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.
+     *
+     * The cache age is taken as the oldest (but filled) cache part.
      **************************************************************************/
     public long getCacheAge() {
 	return cacheAge;




More information about the MOBY-guts mailing list