JAL-1083 - graceful failover to single ID query mode for fetching features
authorjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 10 May 2012 16:06:39 +0000 (17:06 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Thu, 10 May 2012 16:06:39 +0000 (17:06 +0100)
src/jalview/ws/DasSequenceFeatureFetcher.java
src/jalview/ws/dbsources/das/datamodel/DasSequenceSource.java

index c530b62..2a5476b 100644 (file)
@@ -29,6 +29,7 @@ import jalview.ws.dbsources.das.api.DasSourceRegistryI;
 import jalview.ws.dbsources.das.api.jalviewSourceI;\r
 \r
 import java.util.ArrayList;\r
+import java.util.Arrays;\r
 import java.util.Enumeration;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
@@ -41,6 +42,7 @@ import java.util.Vector;
 \r
 import javax.swing.JOptionPane;\r
 \r
+import org.biodas.jdas.client.FeaturesClient;\r
 import org.biodas.jdas.client.adapters.features.DasGFFAdapter;\r
 import org.biodas.jdas.client.adapters.features.DasGFFAdapter.GFFAdapter;\r
 import org.biodas.jdas.client.threads.FeaturesClientMultipleSources;\r
@@ -97,7 +99,7 @@ public class DasSequenceFeatureFetcher
   long startTime;\r
 \r
   private DasSourceRegistryI sourceRegistry;\r
-\r
+  private boolean useJDASMultiThread=true;\r
   /**\r
    * Creates a new SequenceFeatureFetcher object. Uses default\r
    * \r
@@ -109,13 +111,20 @@ public class DasSequenceFeatureFetcher
   public DasSequenceFeatureFetcher(SequenceI[] sequences,\r
           FeatureSettings fsettings, Vector selectedSources)\r
   {\r
-    this(sequences, fsettings, selectedSources, true, true);\r
+    this(sequences, fsettings, selectedSources, true, true, true);\r
   }\r
 \r
   public DasSequenceFeatureFetcher(SequenceI[] oursequences,\r
           FeatureSettings fsettings, List<jalviewSourceI> selectedSources2,\r
           boolean checkDbrefs, boolean promptFetchDbrefs)\r
   {\r
+    this(oursequences,fsettings,selectedSources2,checkDbrefs,promptFetchDbrefs,true);\r
+  }\r
+  public DasSequenceFeatureFetcher(SequenceI[] oursequences,\r
+          FeatureSettings fsettings, List<jalviewSourceI> selectedSources2,\r
+          boolean checkDbrefs, boolean promptFetchDbrefs, boolean useJDasMultiThread)\r
+  {\r
+    this.useJDASMultiThread=useJDasMultiThread;\r
     this.selectedSources = new ArrayList<jalviewSourceI>();\r
     // filter both sequences and sources to eliminate duplicates\r
     for (jalviewSourceI src : selectedSources2)\r
@@ -343,6 +352,38 @@ public class DasSequenceFeatureFetcher
     }\r
     Map<String, Map<List<String>, Exception>> errors = new HashMap<String, Map<List<String>, Exception>>();\r
     Map<String, Map<List<String>, DasGFFAdapter>> results = new HashMap<String, Map<List<String>, DasGFFAdapter>>();\r
+    if (!useJDASMultiThread)\r
+    {\r
+      Iterator<String> sources=src.iterator();\r
+      // iterate over each query for each source and do each one individually\r
+      for (List<String> idl:ids)\r
+      {\r
+        String source=sources.next();\r
+        FeaturesClient featuresc=new FeaturesClient(sourceRegistry.getSessionHandler().getConnectionPropertyProviderFor(source));\r
+        for (String id:idl)\r
+        {\r
+          List<String> qid=Arrays.asList(new String[] { id});\r
+          try {\r
+            DasGFFAdapter dga=featuresc.fetchData(source, qid);\r
+            Map<List<String>,DasGFFAdapter> ers=results.get(source);\r
+            if (ers==null)\r
+            {\r
+              results.put(source, ers=new HashMap<List<String>,DasGFFAdapter>());\r
+            }\r
+            ers.put(qid, dga);\r
+          } catch (Exception ex)\r
+          {\r
+            Map<List<String>,Exception> ers=errors.get(source);\r
+            if (ers==null)\r
+            {\r
+              errors.put(source, ers=new HashMap<List<String>,Exception>());\r
+            }\r
+            ers.put(qid, ex);\r
+          }\r
+        }\r
+      }\r
+    } else {\r
+      // pass them all at once\r
     fc.fetchData(src, ids, false, results, errors);\r
     fc.shutDown();\r
     while (!fc.isTerminated())\r
@@ -355,6 +396,7 @@ public class DasSequenceFeatureFetcher
 \r
       }\r
     }\r
+    }\r
     Iterator<List<String>> idset = ids.iterator();\r
     Iterator<List<DBRefEntry>> idobjset = idobj.iterator();\r
     Iterator<Map<String, SequenceI>> seqset = sqset.iterator();\r
index 4a7b4bd..7a78d8d 100644 (file)
@@ -271,8 +271,8 @@ public class DasSequenceSource extends DbSourceProxyImpl implements
         srcs.addElement(jsrc);\r
         try\r
         {\r
-          new jalview.ws.DasSequenceFeatureFetcher(sqs, null, srcs, false,\r
-                  false);\r
+          jalview.ws.DasSequenceFeatureFetcher dssf=new jalview.ws.DasSequenceFeatureFetcher(sqs, null, srcs, false,\r
+                  false, multiple);\r
         } catch (Exception x)\r
         {\r
           Cache.log\r