[MOBY-guts] biomoby commit

Martin Senger senger at pub.open-bio.org
Sat Oct 22 01:38:04 UTC 2005


senger
Fri Oct 21 21:38:04 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv3384/src/main/org/biomoby/client

Modified Files:
	BaseClient.java CentralDigestCachedImpl.java 
	CentralDigestImpl.java 
Log Message:


moby-live/Java/src/main/org/biomoby/client BaseClient.java,1.2,1.3 CentralDigestCachedImpl.java,1.9,1.10 CentralDigestImpl.java,1.6,1.7
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/BaseClient.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/BaseClient.java	2005/09/04 13:45:37	1.2
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/BaseClient.java	2005/10/22 01:38:04	1.3
@@ -169,9 +169,9 @@
 	} catch (MalformedURLException e) {
 	    throw new MobyException ("Service endpoint '" + serviceEndpoint +
 				     "' is not a valid URL.");
- 	} catch (GException e) {
-	    throw new MobyException (e.getMessage());
- 	}
+  	} catch (GException e) {
+ 	    throw new MobyException (e.getMessage());
+  	}
     }
 
     /**************************************************************************

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java	2005/10/12 11:17:59	1.9
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java	2005/10/22 01:38:04	1.10
@@ -15,6 +15,7 @@
 import java.io.PrintWriter;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.TreeMap;
 import java.util.Vector;
 import java.util.Arrays;
 import java.util.Comparator;
@@ -126,9 +127,9 @@
 
     /**************************************************************************
      * Removes object groups from the cache. If 'id' is null it
-     * removes the whole cache (for the Moby registry this instance as
-     * initiated for). Otherwise 'id' indicates what part of the cache
-     * that will be removed. <p>
+     * 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. <p>
      *
      * @param id should be either null, or one of the fillowing:
      * {@link #CACHE_PART_DATATYPES}, {@link #CACHE_PART_SERVICES},
@@ -313,21 +314,38 @@
 	}
     }
 
-    //
+    /**************************************************************************
+     * Is the given cache empty (meaning: cache directory does not
+     * exist, is empty, or contains only files to be ignored)?
+     *************************************************************************/
     protected boolean isCacheEmpty (File cache)
 	throws MobyException {
 	if (cache == null) return true;
 	String[] list = cache.list();
-	return ( list == null || list.length == 0 );
+	if (list == null || list.length == 0)
+	    return true;
+	for (int i = 0; i < list.length; i++) {
+	    if ( ! ignored (new File (list[i])) )
+		return false;
+	}
+	return true;
     }
 
-    protected void fillDataTypesCache()
+    /**************************************************************************
+     * Load data types from a moby registry into local cache. If it is
+     * interrupted (by a callback signal) it removes what was already
+     * put into this cache and returns false. Otherwise returns
+     * true. It raises an exception if it cannot fill the cache (from
+     * some other reasons).
+     *************************************************************************/
+    protected boolean fillDataTypesCache()
 	throws MobyException {
 	try {
+	    fireEvent (DATA_TYPES_START);
 	    String typesAsXML = getDataTypeNamesAsXML();
 	    store (dataTypesCache, LIST_FILE, typesAsXML);
 	    Map types = createDataTypeNamesFromXML (typesAsXML);
-	    fireEvent (DATA_TYPE_COUNT, new Integer (types.size()));
+	    fireEvent (DATA_TYPES_COUNT, new Integer (types.size()));
 	    for (Iterator it = types.entrySet().iterator(); it.hasNext(); ) {
 		Map.Entry entry = (Map.Entry)it.next();
 		String name = (String)entry.getKey();
@@ -335,19 +353,28 @@
 		String xml = getDataTypeAsXML (name);
 		store (dataTypesCache, name, xml);
 		fireEvent (DATA_TYPE_LOADED, name);
+		if (stopDT) {
+		    removeFromCache (CACHE_PART_DATATYPES);
+		    return false;
+		}
 	    }
+	    return true;
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
+	} finally {
+	    fireEvent (stopDT ? DATA_TYPES_CANCELLED : DATA_TYPES_END);
+	    stopDT = false;
 	}
     }
 
-    protected void fillServicesCache()
+    protected boolean fillServicesCache()
 	throws MobyException {
 	try {
+	    fireEvent (AUTHORITIES_START);
 	    String byAuthorityAsXML = getServiceNamesByAuthorityAsXML();
 	    store (servicesCache, LIST_FILE, byAuthorityAsXML);
 	    Map authorities = createServiceNamesByAuthorityFromXML (byAuthorityAsXML);
-	    fireEvent (AUTHORITY_COUNT, new Integer (authorities.size()));
+	    fireEvent (AUTHORITIES_COUNT, new Integer (authorities.size()));
 	    for (Iterator it = authorities.entrySet().iterator(); it.hasNext(); ) {
 		Map.Entry entry = (Map.Entry)it.next();
 		String authority = (String)entry.getKey();
@@ -355,20 +382,29 @@
 		String xml = getServicesAsXML (new MobyService (MobyService.DUMMY_NAME, authority), null, true, true);
 		store (servicesCache, authority, xml);
 		fireEvent (AUTHORITY_LOADED, authority);
+		if (stopS) {
+		    removeFromCache (CACHE_PART_SERVICES);
+		    return false;
+		}
 	    }
+	    return true;
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
+	} finally {
+	    fireEvent (stopS ? AUTHORITIES_CANCELLED : AUTHORITIES_END);
+	    stopS = false;
 	}
     }
 
     //
-    protected void fillServiceTypesCache()
+    protected boolean fillServiceTypesCache()
 	throws MobyException {
 	try {
+	    fireEvent (SERVICE_TYPES_START);
 	    String typesAsXML = getServiceTypesAsXML();
 	    store (serviceTypesCache, LIST_FILE, typesAsXML);
 	    Map types = createServiceTypesFromXML (typesAsXML);
-	    fireEvent (SERVICE_TYPE_COUNT, new Integer (types.size()));
+	    fireEvent (SERVICE_TYPES_COUNT, new Integer (types.size()));
 	    for (Iterator it = types.entrySet().iterator(); it.hasNext(); ) {
 		Map.Entry entry = (Map.Entry)it.next();
 		String name = (String)entry.getKey();
@@ -376,22 +412,32 @@
 		String xml = getServiceTypeRelationshipsAsXML (name, false);
 		store (serviceTypesCache, name, xml);
 		fireEvent (SERVICE_TYPE_LOADED, name);
+		if (stopST) {
+		    removeFromCache (CACHE_PART_SERVICETYPES);
+		    return false;
+		}
 	    }
+	    return true;
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
+	} finally {
+	    fireEvent (stopST ? SERVICE_TYPES_CANCELLED :SERVICE_TYPES_END);
+	    stopST = false;
 	}
     }
 
     //
-    protected void fillNamespacesCache()
+    protected boolean fillNamespacesCache()
 	throws MobyException {
 	try {
-	    fireEvent (NAMESPACE_LOADING, "Loading started.");
+	    fireEvent (NAMESPACES_START);
 	    String xml = getNamespacesAsXML();
 	    store (namespacesCache, LIST_FILE, xml);
-	    fireEvent (NAMESPACE_LOADED, "Loaded.");
+	    return true;
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
+	} finally {
+	    fireEvent (NAMESPACES_END);
 	}
     }
 
@@ -405,7 +451,9 @@
 	synchronized (dataTypesCache) {
 	    if (isCacheEmpty (dataTypesCache)) {
 		initCache();
-		fillDataTypesCache();
+		if (! fillDataTypesCache())
+		    // callback stopped filling
+		    return new TreeMap();
 	    }
 
 	    // get a list file (with all data type names)
@@ -425,7 +473,9 @@
 	    Vector v = new Vector();
 	    if (isCacheEmpty (dataTypesCache)) {
 		initCache();
-		fillDataTypesCache();
+		if (! fillDataTypesCache())
+		    // callback stopped filling
+		    return new MobyDataType[] {};
 	    }
 	    File[] list = dataTypesCache.listFiles();
 	    if (list == null)
@@ -456,7 +506,9 @@
 	synchronized (servicesCache) {
 	    if (isCacheEmpty (servicesCache)) {
 		initCache();
-		fillServicesCache();
+		if (! fillServicesCache())
+		    // callback stopped filling
+		    return new TreeMap();
 	    }
 
 	    // get a list file (with all service names)
@@ -476,7 +528,9 @@
 	    Vector v = new Vector();
 	    if (isCacheEmpty (servicesCache)) {
 		initCache();
-		fillServicesCache();
+		if (! fillServicesCache())
+		    // callback stopped filling
+		    return new MobyService[] {};
 	    }
 	    File[] list = servicesCache.listFiles();
 	    if (list == null)
@@ -529,7 +583,9 @@
 	synchronized (serviceTypesCache) {
 	    if (isCacheEmpty (serviceTypesCache)) {
 		initCache();
-		fillServiceTypesCache();
+		if (! fillServiceTypesCache())
+		    // callback stopped filling
+		    return new MobyServiceType[] {};
 	    }
 
 	    // get a list file (with all service type names)

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestImpl.java	2005/10/12 11:17:59	1.6
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestImpl.java	2005/10/22 01:38:04	1.7
@@ -41,6 +41,9 @@
     protected MobyService[] services = new MobyService[] {};
     protected MobyNamespace[] namespaces = new MobyNamespace[] {};
 
+    protected boolean stopDT = false;
+    protected boolean stopST = false;
+    protected boolean stopS  = false;
 
     /*************************************************************************
      * Default constructor. It connects to a default Moby registry
@@ -77,14 +80,19 @@
 	throws MobyException {
 	try {
 	    Vector v = new Vector();
+	    fireEvent (DATA_TYPES_START);
 	    Map types = getDataTypeNames();
-	    fireEvent (DATA_TYPE_COUNT, new Integer (types.size()));
+	    fireEvent (DATA_TYPES_COUNT, new Integer (types.size()));
 	    for (Iterator it = types.entrySet().iterator(); it.hasNext(); ) {
 		Map.Entry entry = (Map.Entry)it.next();
 		String name = (String)entry.getKey();
 		fireEvent (DATA_TYPE_LOADING, name);
 		v.addElement (getDataType (name));
 		fireEvent (DATA_TYPE_LOADED, name, v.lastElement());
+		if (stopDT) {
+		    v = new Vector();
+		    break;
+		}
 	    }
 	    MobyDataType[] result = new MobyDataType [v.size()];
 	    v.copyInto (result);
@@ -92,6 +100,9 @@
 
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
+	} finally {
+	    fireEvent (stopDT ? DATA_TYPES_CANCELLED : DATA_TYPES_END);
+	    stopDT = false;
 	}
     }
 
@@ -102,8 +113,9 @@
 	throws MobyException {
 	try {
 	    Vector v = new Vector();
+	    fireEvent (SERVICE_TYPES_START);
 	    Map types = getServiceTypes();
-	    fireEvent (SERVICE_TYPE_COUNT, new Integer (types.size()));
+	    fireEvent (SERVICE_TYPES_COUNT, new Integer (types.size()));
 	    for (Iterator it = types.entrySet().iterator(); it.hasNext(); ) {
 		Map.Entry entry = (Map.Entry)it.next();
 		String typeName = (String)entry.getKey();
@@ -113,6 +125,10 @@
 		serviceType.setParentNames (getServiceTypeRelationships (typeName, false));
 		v.addElement (serviceType);
 		fireEvent (SERVICE_TYPE_LOADED, typeName, v.lastElement());
+		if (stopST) {
+		    v = new Vector();
+		    break;
+		}
 	    }
 	    MobyServiceType[] result = new MobyServiceType [v.size()];
 	    v.copyInto (result);
@@ -120,6 +136,9 @@
 
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
+	} finally {
+	    fireEvent (stopST ? SERVICE_TYPES_CANCELLED : SERVICE_TYPES_END);
+	    stopST = false;
 	}
     }
 
@@ -136,8 +155,9 @@
     protected MobyNamespace[] readNamespaces()
 	throws MobyException {
 	try {
+	    fireEvent (NAMESPACES_START);
 	    Map names = getNamespaces();
-	    fireEvent (NAMESPACE_COUNT, new Integer (names.size()));
+	    fireEvent (NAMESPACES_COUNT, new Integer (names.size()));
 	    MobyNamespace[] result = new MobyNamespace [ names.size() ];
 	    int i = 0;
 	    for (Iterator it = names.entrySet().iterator(); it.hasNext(); ) {
@@ -152,6 +172,8 @@
 
 	} catch (Exception e) {
 	    throw new MobyException (formatException (e));
+	} finally {
+	    fireEvent (NAMESPACES_END);
 	}
     }
 
@@ -162,8 +184,9 @@
 	throws MobyException {
 	try {
 	    Vector v = new Vector();
+	    fireEvent (AUTHORITIES_START);
 	    Map authorities = getServiceNamesByAuthority();
-	    fireEvent (AUTHORITY_COUNT, new Integer (authorities.size()));
+	    fireEvent (AUTHORITIES_COUNT, new Integer (authorities.size()));
 	    for (Iterator it = authorities.entrySet().iterator(); it.hasNext(); ) {
 		Map.Entry entry = (Map.Entry)it.next();
 		String authority = (String)entry.getKey();
@@ -175,15 +198,20 @@
 			v.addElement (servs[j]);
 		}
 		fireEvent (AUTHORITY_LOADED, authority);
+		if (stopS) {
+		    v = new Vector();
+		    break;
+		}
 	    }
 	    MobyService[] result = new MobyService [v.size()];
 	    v.copyInto (result);
 	    return result;
 
 	} catch (Exception e) {
-	    System.err.println ("HERE:\n" + e.toString());
-	    e.printStackTrace();
 	    throw new MobyException (formatException (e));
+	} finally {
+	    fireEvent (stopS ? AUTHORITIES_CANCELLED : AUTHORITIES_END);
+	    stopS = false;
 	}
     }
 
@@ -323,6 +351,14 @@
     /*********************************************************************
      *
      ********************************************************************/
+    public void addNotificationListeners (NotificationListener[] l) {
+	for (int i = 0; i < l.length; i++)
+	    addNotificationListener (l[i]);
+    }
+
+    /*********************************************************************
+     *
+     ********************************************************************/
     public void removeNotificationListener (NotificationListener l) {
 	if (listeners != null)
 	    listeners.removeElement (l);
@@ -331,6 +367,14 @@
     /*********************************************************************
      *
      ********************************************************************/
+    public void removeNotificationListeners (NotificationListener[] l) {
+	for (int i = 0; i < l.length; i++)
+	    removeNotificationListener (l[i]);
+    }
+
+    /*********************************************************************
+     *
+     ********************************************************************/
     public NotificationListener[] getNotificationListeners() {
      	if (listeners == null)
 	    return new NotificationListener[] {};
@@ -344,14 +388,21 @@
     /*********************************************************************
      *
      ********************************************************************/
-    protected void fireEvent (String type, Object message) {
-	fireEvent (type, message, null);
+    public void callback (int signal) {
+	switch (signal) {
+	case SIGNAL_CANCEL_DATA_TYPES:
+	    stopDT = true; break;
+	case SIGNAL_CANCEL_SERVICE_TYPES:
+	    stopST = true; break;
+	case SIGNAL_CANCEL_SERVICES:
+	    stopS = true; break;
+	}
     }
 
     /*********************************************************************
      *
      ********************************************************************/
-    protected void fireEvent (String type, Object message, Object details) {
+    public void fireEvent (int type, Object message, Object details) {
 	NotificationEvent event = null;
 	if (details == null)
 	    event = new NotificationEvent (this, type, message.toString());
@@ -367,6 +418,21 @@
 	}
     }
 
+    /*********************************************************************
+     *
+     ********************************************************************/
+    protected void fireEvent (int type) {
+	fireEvent (type, "", null);
+    }
+
+    /*********************************************************************
+     *
+     ********************************************************************/
+    protected void fireEvent (int type, Object message) {
+	fireEvent (type, message, null);
+    }
+
+
 
 
 




More information about the MOBY-guts mailing list