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