[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Sat Jun 9 21:58:26 UTC 2007


gordonp
Sat Jun  9 17:58:26 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared
In directory dev.open-bio.org:/tmp/cvs-serv5219/src/main/org/biomoby/shared

Modified Files:
	MobyDataType.java MobyNamespace.java MobyServiceType.java 
Log Message:
Changed to synchronize multi-thread access better (i.e. don't load an ontology more than once)
moby-live/Java/src/main/org/biomoby/shared MobyDataType.java,1.17,1.18 MobyNamespace.java,1.8,1.9 MobyServiceType.java,1.9,1.10
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java	2007/06/09 18:17:12	1.17
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyDataType.java	2007/06/09 21:58:26	1.18
@@ -92,19 +92,21 @@
      * refreshing an in-memory cache.
      */
     public static void loadDataTypes(URL dataDefURL, Registry reg) throws Exception{
-	if(reg == null){
-	    reg = RegistryCache.getDefaultRegistry();
-	}
-
-	MobyDataType[] datatypes;
-	DataTypeParser p = new DataTypeParser(dataDefURL);
-	
-	datatypes = p.getMobyDataTypesFromRDF();
-	for(MobyDataType dataType: datatypes){
-	    dataType.setRegistry(reg);
+	synchronized(datatypesMapBySynonym){
+	    if(reg == null){
+		reg = RegistryCache.getDefaultRegistry();
+	    }
+	    
+	    MobyDataType[] datatypes;
+	    DataTypeParser p = new DataTypeParser(dataDefURL);
+	    
+	    datatypes = p.getMobyDataTypesFromRDF();
+	    for(MobyDataType dataType: datatypes){
+		dataType.setRegistry(reg);
+	    }
+	    datatypesMapBySynonym.put(reg.getSynonym(), datatypes);
+	    datatypesMapByURL.put(dataDefURL, datatypes);  
 	}
-	datatypesMapBySynonym.put(reg.getSynonym(), datatypes);
-	datatypesMapByURL.put(dataDefURL, datatypes);  
     }
 
     public static MobyDataType getDataType(String className){
@@ -125,8 +127,11 @@
 	if(reg == null){
 	    return null;
 	}
-
-	MobyDataType[] datatypes = datatypesMapBySynonym.get(reg.getSynonym());
+	MobyDataType[] datatypes = null;
+	// sync makes sure we don't fetch it if it's currently being loaded by loadDataTypes
+	synchronized(datatypesMapBySynonym){
+	    datatypes = datatypesMapBySynonym.get(reg.getSynonym());
+	}
 
 	// This method has not been called yet in the JVM, populate the datatypes 
 	synchronized(datatypesMapByURL){
@@ -135,7 +140,9 @@
 		    URL dataDefURL = Registry.findResourceURL(reg, Central.DATA_TYPES_RESOURCE_NAME);
 		    datatypes = datatypesMapByURL.get(dataDefURL);		    
 		    if(datatypes == null){
+			System.err.println("Fetching data type ontology from " + dataDefURL);
 			loadDataTypes(dataDefURL, reg);
+			System.err.println(" ... done");
 			datatypes = datatypesMapByURL.get(dataDefURL);
 		    }
 		    

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.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/shared/MobyNamespace.java	2007/06/08 20:30:22	1.8
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyNamespace.java	2007/06/09 21:58:26	1.9
@@ -72,23 +72,23 @@
      * Particularly useful for loading namespace definitions from cached file, or
      * refreshing an in-memory cache.
      */
-    public static void loadNamespaces(URL namespaceDefURL, Registry reg){
-	MobyNamespace[] namespaces;
-	try{
+    public static void loadNamespaces(URL namespaceDefURL, Registry reg) throws Exception{
+	synchronized(namespacesMapBySynonym){
+	    if(reg == null){
+		reg = RegistryCache.getDefaultRegistry();
+	    }
+	    
+	    MobyNamespace[] namespaces;
 	    NamespaceParser p = new NamespaceParser(namespaceDefURL);	    
 	    namespaces = p.getMobyNamespacesFromRDF();
-
+	    
 	    for(MobyNamespace namespace: namespaces){
 		namespace.setRegistry(reg);
 	    }
+	    
+	    namespacesMapBySynonym.put(reg.getSynonym(), namespaces);
+	    namespacesMapByURL.put(namespaceDefURL.toString(), namespaces);  
 	}
-	catch(Exception e){
-	    System.err.println("Cannot parse MOBY Namespace Ontology: " + e);
-	    e.printStackTrace();
-	    return;
-	}
-	namespacesMapBySynonym.put(reg.getSynonym(), namespaces);
-	namespacesMapByURL.put(namespaceDefURL.toString(), namespaces);  
     }
 
     public static MobyNamespace getNamespace(String ns){
@@ -107,32 +107,30 @@
 	    return null;
 	}
 
-	MobyNamespace[] namespaces = namespacesMapBySynonym.get(reg.getSynonym());
+	MobyNamespace[] namespaces = null;
+	// sync makes sure we don't fetch it if it's currently being loaded by loadNamespaces
+	synchronized(namespacesMapBySynonym){  
+	    namespaces = namespacesMapBySynonym.get(reg.getSynonym());
+	}
 
-	// This method has not been called yet in the JVM, populate the datatypes 
+	// This method has not been called yet in the JVM, populate the namespaces 
 	synchronized(namespacesMapByURL){
 	    if(namespaces == null){
-		String namespaceDefURL = null; 
 		try{
-		    namespaces = namespacesMapByURL.get(namespaceDefURL);
-		    
+		    URL namespaceDefURL = Registry.findResourceURL(reg, Central.NAMESPACES_RESOURCE_NAME);
+		    namespaces = namespacesMapByURL.get(namespaceDefURL);		    
 		    if(namespaces == null){
-			namespaceDefURL = convertRegistryToNamespaceResourceURL(reg);
-			NamespaceParser p = new NamespaceParser(namespaceDefURL);
-			namespaces = p.getMobyNamespacesFromRDF();
-
-			for(MobyNamespace namespace: namespaces){
-			    namespace.setRegistry(reg);
-			}
+			System.err.println("Fetching namespace ontology from "+namespaceDefURL);
+			loadNamespaces(namespaceDefURL, reg);
+			namespaces = namespacesMapByURL.get(namespaceDefURL);
 		    }
+		    
 		}
 		catch(Exception e){
 		    System.err.println("Cannot parse MOBY Namespace Ontology: " + e);
 		    e.printStackTrace();
 		    return null;
 		}
-		namespacesMapBySynonym.put(reg.getSynonym(), namespaces);
-		namespacesMapByURL.put(namespaceDefURL, namespaces);
 	    }
 	}
 

===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyServiceType.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/shared/MobyServiceType.java	2007/06/08 20:30:22	1.9
+++ /home/repository/moby/moby-live/Java/src/main/org/biomoby/shared/MobyServiceType.java	2007/06/09 21:58:26	1.10
@@ -77,19 +77,21 @@
      * refreshing an in-memory cache.
      */
     public static void loadServiceTypes(URL serviceDefURL, Registry reg) throws Exception{
-	if(reg == null){
-	    reg = RegistryCache.getDefaultRegistry();
-	}
-
-	MobyServiceType[] servicetypes;
-	ServiceTypeParser p = new ServiceTypeParser(serviceDefURL);	    
-	servicetypes = p.getMobyServiceTypesFromRDF();
-	
-	for(MobyServiceType servicetype: servicetypes){
-	    servicetype.setRegistry(reg);
+	synchronized(servicetypesMapBySynonym){
+	    if(reg == null){
+		reg = RegistryCache.getDefaultRegistry();
+	    }
+	    
+	    MobyServiceType[] servicetypes;
+	    ServiceTypeParser p = new ServiceTypeParser(serviceDefURL);	    
+	    servicetypes = p.getMobyServiceTypesFromRDF();
+	    
+	    for(MobyServiceType servicetype: servicetypes){
+		servicetype.setRegistry(reg);
+	    }
+	    servicetypesMapBySynonym.put(reg.getSynonym(), servicetypes);
+	    servicetypesMapByURL.put(serviceDefURL, servicetypes);  
 	}
-	servicetypesMapBySynonym.put(reg.getSynonym(), servicetypes);
-	servicetypesMapByURL.put(serviceDefURL, servicetypes);  
     }
     
     public static MobyServiceType getServiceType(String className){
@@ -108,7 +110,11 @@
 	    return null;
 	}
 
-	MobyServiceType[] servicetypes = servicetypesMapBySynonym.get(reg.getSynonym());
+	MobyServiceType[] servicetypes = null;
+	// sync makes sure we don't fetch it if it's currently being loaded by loadNamespaces
+	synchronized(servicetypesMapBySynonym){
+	    servicetypes = servicetypesMapBySynonym.get(reg.getSynonym());
+	}
 
 	// This method has not been called yet in the JVM, populate the datatypes 
 	synchronized(servicetypesMapByURL){
@@ -117,6 +123,7 @@
 		    URL serviceDefURL = Registry.findResourceURL(reg, Central.SERVICE_TYPES_RESOURCE_NAME);
 		    servicetypes = servicetypesMapByURL.get(serviceDefURL);		    
 		    if(servicetypes == null){
+			System.err.println("Fetching service type ontology from " + serviceDefURL);
 			loadServiceTypes(serviceDefURL, reg);
 			servicetypes = servicetypesMapByURL.get(serviceDefURL);
 		    }




More information about the MOBY-guts mailing list