[MOBY-guts] biomoby commit
Martin Senger
senger at pub.open-bio.org
Wed Oct 12 11:17:59 UTC 2005
senger
Wed Oct 12 07:17:59 EDT 2005
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/client
In directory pub.open-bio.org:/tmp/cvs-serv13525/src/main/org/biomoby/client
Modified Files:
CentralDigestCachedImpl.java CentralDigestImpl.java
Log Message:
moby-live/Java/src/main/org/biomoby/client CentralDigestCachedImpl.java,1.8,1.9 CentralDigestImpl.java,1.5,1.6
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java 2005/09/24 17:51:51 1.8
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestCachedImpl.java 2005/10/12 11:17:59 1.9
@@ -107,7 +107,6 @@
throws MobyException {
if (cacheDir != null) {
File cache = createCacheDir (cacheDir, getRegistryEndpoint());
- messageLn ("Using cache directory: " + cache);
dataTypesCache = createSubCacheDir (cache, "dataTypes");
servicesCache = createSubCacheDir (cache, "services");
namespacesCache = createSubCacheDir (cache, "namespaces");
@@ -116,6 +115,16 @@
}
/**************************************************************************
+ * Return a directory name representing the current cache. This is
+ * the same name as given in constructors. <p>
+ *
+ * @return current cache directory name
+ **************************************************************************/
+ public String getCacheDir() {
+ return cacheDir;
+ }
+
+ /**************************************************************************
* 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
@@ -318,12 +327,14 @@
String typesAsXML = getDataTypeNamesAsXML();
store (dataTypesCache, LIST_FILE, typesAsXML);
Map types = createDataTypeNamesFromXML (typesAsXML);
+ fireEvent (DATA_TYPE_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();
- messageLn ("(CDCI) Processing data type " + name + "...");
+ fireEvent (DATA_TYPE_LOADING, name);
String xml = getDataTypeAsXML (name);
store (dataTypesCache, name, xml);
+ fireEvent (DATA_TYPE_LOADED, name);
}
} catch (Exception e) {
throw new MobyException (formatException (e));
@@ -333,16 +344,17 @@
protected void fillServicesCache()
throws MobyException {
try {
- messageLn ("(CDCI) Asking for all service names...");
String byAuthorityAsXML = getServiceNamesByAuthorityAsXML();
store (servicesCache, LIST_FILE, byAuthorityAsXML);
Map authorities = createServiceNamesByAuthorityFromXML (byAuthorityAsXML);
+ fireEvent (AUTHORITY_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();
- messageLn ("(CDCI) Processing authority " + authority + "...");
+ fireEvent (AUTHORITY_LOADING, authority);
String xml = getServicesAsXML (new MobyService (MobyService.DUMMY_NAME, authority), null, true, true);
store (servicesCache, authority, xml);
+ fireEvent (AUTHORITY_LOADED, authority);
}
} catch (Exception e) {
throw new MobyException (formatException (e));
@@ -353,16 +365,17 @@
protected void fillServiceTypesCache()
throws MobyException {
try {
- messageLn ("(CDCI) Asking for all service type names...");
String typesAsXML = getServiceTypesAsXML();
store (serviceTypesCache, LIST_FILE, typesAsXML);
Map types = createServiceTypesFromXML (typesAsXML);
+ fireEvent (SERVICE_TYPE_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();
- messageLn ("(CDCI) Processing service type " + name + "...");
+ fireEvent (SERVICE_TYPE_LOADING, name);
String xml = getServiceTypeRelationshipsAsXML (name, false);
store (serviceTypesCache, name, xml);
+ fireEvent (SERVICE_TYPE_LOADED, name);
}
} catch (Exception e) {
throw new MobyException (formatException (e));
@@ -373,8 +386,10 @@
protected void fillNamespacesCache()
throws MobyException {
try {
+ fireEvent (NAMESPACE_LOADING, "Loading started.");
String xml = getNamespacesAsXML();
store (namespacesCache, LIST_FILE, xml);
+ fireEvent (NAMESPACE_LOADED, "Loaded.");
} catch (Exception e) {
throw new MobyException (formatException (e));
}
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestImpl.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/CentralDigestImpl.java 2005/09/22 16:07:09 1.5
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/client/CentralDigestImpl.java 2005/10/12 11:17:59 1.6
@@ -7,6 +7,9 @@
package org.biomoby.client;
import org.biomoby.shared.CentralDigest;
+import org.biomoby.shared.event.Notifier;
+import org.biomoby.shared.event.NotificationEvent;
+import org.biomoby.shared.event.NotificationListener;
import org.biomoby.shared.MobyDataType;
import org.biomoby.shared.MobyException;
import org.biomoby.shared.MobyService;
@@ -30,7 +33,7 @@
public class CentralDigestImpl
extends CentralImpl
- implements CentralDigest {
+ implements CentralDigest, Notifier {
// cached (digested) Moby
protected MobyDataType[] dataTypes = new MobyDataType[] {};
@@ -75,11 +78,13 @@
try {
Vector v = new Vector();
Map types = getDataTypeNames();
+ fireEvent (DATA_TYPE_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();
- messageLn ("(CDI) Processing data type " + name + "...");
+ fireEvent (DATA_TYPE_LOADING, name);
v.addElement (getDataType (name));
+ fireEvent (DATA_TYPE_LOADED, name, v.lastElement());
}
MobyDataType[] result = new MobyDataType [v.size()];
v.copyInto (result);
@@ -98,14 +103,16 @@
try {
Vector v = new Vector();
Map types = getServiceTypes();
+ fireEvent (SERVICE_TYPE_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();
- messageLn ("(CDI) Processing service type " + typeName + "...");
+ fireEvent (SERVICE_TYPE_LOADING, typeName);
MobyServiceType serviceType = new MobyServiceType (typeName);
serviceType.setDescription ((String)entry.getValue());
serviceType.setParentNames (getServiceTypeRelationships (typeName, false));
v.addElement (serviceType);
+ fireEvent (SERVICE_TYPE_LOADED, typeName, v.lastElement());
}
MobyServiceType[] result = new MobyServiceType [v.size()];
v.copyInto (result);
@@ -130,6 +137,7 @@
throws MobyException {
try {
Map names = getNamespaces();
+ fireEvent (NAMESPACE_COUNT, new Integer (names.size()));
MobyNamespace[] result = new MobyNamespace [ names.size() ];
int i = 0;
for (Iterator it = names.entrySet().iterator(); it.hasNext(); ) {
@@ -138,6 +146,7 @@
MobyNamespace ns = new MobyNamespace (name);
ns.setDescription ((String)entry.getValue());
result[i++] = ns;
+ fireEvent (NAMESPACE_LOADED, name, ns);
}
return result;
@@ -153,18 +162,19 @@
throws MobyException {
try {
Vector v = new Vector();
- messageLn ("(CDI) Asking for all service names...");
Map authorities = getServiceNamesByAuthority();
+ fireEvent (AUTHORITY_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();
+ fireEvent (AUTHORITY_LOADING, authority);
String[] names = (String[])entry.getValue();
for (int i = 0; i < names.length; i++) {
- messageLn ("(CDI) Processing service " + names[i] + "...");
MobyService[] servs = findService (new MobyService (names[i], authority));
for (int j = 0; j < servs.length; j++)
v.addElement (servs[j]);
}
+ fireEvent (AUTHORITY_LOADED, authority);
}
MobyService[] result = new MobyService [v.size()];
v.copyInto (result);
@@ -186,6 +196,8 @@
buf.append (e.toString());
buf.append (DGUtils.stackTraceToString (e));
return new String (buf);
+ } else if (e instanceof MobyException) {
+ return e.getMessage();
} else {
return e.toString();
}
@@ -291,6 +303,74 @@
}
}
+ /*************************************************************************
+ *
+ * Methods implementing Notifier interface.
+ *
+ *************************************************************************/
+
+ private Vector listeners;
+
+ /*********************************************************************
+ *
+ ********************************************************************/
+ public synchronized void addNotificationListener (NotificationListener l) {
+ if (listeners == null)
+ listeners = new Vector();
+ listeners.addElement (l);
+ }
+
+ /*********************************************************************
+ *
+ ********************************************************************/
+ public void removeNotificationListener (NotificationListener l) {
+ if (listeners != null)
+ listeners.removeElement (l);
+ }
+
+ /*********************************************************************
+ *
+ ********************************************************************/
+ public NotificationListener[] getNotificationListeners() {
+ if (listeners == null)
+ return new NotificationListener[] {};
+ synchronized (listeners) {
+ NotificationListener[] result = new NotificationListener [listeners.size()];
+ listeners.copyInto (result);
+ return result;
+ }
+ }
+
+ /*********************************************************************
+ *
+ ********************************************************************/
+ protected void fireEvent (String type, Object message) {
+ fireEvent (type, message, null);
+ }
+
+ /*********************************************************************
+ *
+ ********************************************************************/
+ protected void fireEvent (String type, Object message, Object details) {
+ NotificationEvent event = null;
+ if (details == null)
+ event = new NotificationEvent (this, type, message.toString());
+ else
+ event = new NotificationEvent (this, type, message.toString(), details);
+ if (listeners != null) {
+ synchronized (listeners) {
+ for (int i = 0; i < listeners.size(); i++) {
+ NotificationListener listener = (NotificationListener)listeners.elementAt(i);
+ listener.notified (event);
+ }
+ }
+ }
+ }
+
+
+
+
+
// Work in progress - implement the methods above by getting RDF
// graphs in-one-go and parsing them. Actually ability to get such
// graphs was the main motivation for this implementation, and for
More information about the MOBY-guts
mailing list