[MOBY-guts] biomoby commit

Paul Gordon gordonp at dev.open-bio.org
Wed Apr 4 01:31:38 UTC 2007


gordonp
Tue Apr  3 21:31:38 EDT 2007
Update of /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services
In directory dev.open-bio.org:/tmp/cvs-serv9410/src/main/ca/ucalgary/seahawk/services

Modified Files:
	MobyClient.java 
Log Message:
Temporarily adding a call to Eddie's ValidateService applet as a substitute for isAlive metadata check (much, much faster)
moby-live/Java/src/main/ca/ucalgary/seahawk/services MobyClient.java,1.8,1.9
===================================================================
RCS file: /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java	2007/04/03 02:29:54	1.8
+++ /home/repository/moby/moby-live/Java/src/main/ca/ucalgary/seahawk/services/MobyClient.java	2007/04/04 01:31:38	1.9
@@ -22,7 +22,7 @@
 
 import javax.xml.parsers.*;
 
-import java.io.File;
+import java.io.*;
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.util.*;
@@ -60,9 +60,11 @@
     public static final String ENCODING_ATTR_BASE64_VAL = "Base64";
     public static final String ENCODING_ATTR_NONE_VAL = "none";
     public static final String SINGLE_RETURNED_VALUE_KEY = "_no_acd_param_should_have_this_name";
+    public static final String IS_ALIVE_SERVICE_URL = "http://mobycentral.icapture.ubc.ca:8090/authority/ValidateService";
 
     private NamespaceContextImpl nsContext;
     private CentralImpl c;
+    private Map isDeadMap; 
     private HashMap xpathMap; 
     private HashMap urlRegexMap; 
     private Map<Pattern,MobyComplexBuilder> regexMap; 
@@ -905,9 +907,10 @@
  		// Paul: commenting out is temporary until we can fetch the services more quickly
 		//MobyService service = MobyService.getService(mService[j].getName(), mService[j].getAuthority());
  		//if(service != null){
-		//mService[j] = service;
+		//    mService[j] = service;
  		//}
 
+		mService[j].setStatus(MobyService.ALIVE, isServiceAlive(mService[j]));
 		mService[j].setServiceType(MobyServiceType.getServiceType(mService[j].getServiceType().getName()));
 		if(serviceLevel != MobyService.UNCHECKED){
 		    int serviceStatus = mService[j].getStatus();
@@ -919,7 +922,7 @@
 	    }
 
 	    // Paul: false is temporary until we can fetch the services more quickly (and check isAlive)
-	    if(false && serviceLevel != MobyService.UNCHECKED){
+	    if(serviceLevel != MobyService.UNCHECKED){
 		mService = (MobyService []) filteredServices.toArray(new MobyService[filteredServices.size()]);
 	    }
 
@@ -1160,5 +1163,55 @@
 	}
 	return false;
     }
+
+    /**
+     * @return true unless we can contact ValidateService, and it tells us the service is dead 
+     */
+    private boolean isServiceAlive(MobyService service){
+	// first time method is called
+	if(isDeadMap == null){
+	    isDeadMap = new HashMap(); // keys are authority:serviceName
+	    try{
+		URL u = new URL(IS_ALIVE_SERVICE_URL);
+		LineNumberReader reader = new LineNumberReader(new InputStreamReader(u.openStream()));
+		String currentAuthority = null;
+		for(String line = reader.readLine();
+		    line != null; 
+		    line = reader.readLine()){
+		    // authority declarations look like "  host.domain.tld"
+		    if(line.indexOf("  ") == 0){
+			currentAuthority = line.trim();
+		    }
+		    else if(line.indexOf("\t") == 0){
+			String[] fields = line.trim().split(",");
+			if(fields.length != 2){ 
+			    System.err.println("Unrecognized line (not 2 comma delimited fields) " +
+					       "from ValidateService: " + line.trim());
+			}
+			else if(fields[1].equals("true")){
+			    // service is okay, don't add to dead map
+			}
+			else if(fields[1].equals("false")){
+			    isDeadMap.put(currentAuthority+":"+fields[0], "dead");
+			}
+			else{
+			    System.err.println("Unrecognized line (second field not 'true' or 'false') " +
+					       "from ValidateService: " + line.trim());			    
+			}
+		    }
+		}
+		    
+	    } catch(Exception e){
+		e.printStackTrace();
+		// will not attempt to retrieve map again, as it's not null anymore
+		return true;
+	    }
+	}
+
+	if(isDeadMap.containsKey(service.getAuthority()+":"+service.getName())){
+	    return false;  // dead for sure
+	}
+	return true;  // be optimistic by default, assume it's alive
+    }
 }
 




More information about the MOBY-guts mailing list