From 6d5977c5b7b2fcec4aae8fd1e8efb375d54efef5 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Tue, 3 Oct 2006 09:25:24 +0000 Subject: [PATCH] Send DAS requests in batches of 20 --- src/jalview/io/DasSequenceFeatureFetcher.java | 32 ++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/jalview/io/DasSequenceFeatureFetcher.java b/src/jalview/io/DasSequenceFeatureFetcher.java index f78f943..b203270 100755 --- a/src/jalview/io/DasSequenceFeatureFetcher.java +++ b/src/jalview/io/DasSequenceFeatureFetcher.java @@ -58,6 +58,7 @@ public class DasSequenceFeatureFetcher implements Runnable long startTime; int threadsRunning = 0; + boolean allBatchesComplete = false; /** @@ -208,7 +209,9 @@ public class DasSequenceFeatureFetcher implements Runnable return f; } catch (Exception e) { + System.out.println("ERRR "+e); e.printStackTrace(); + System.out.println("############"); Cache.log.debug("Failed to parse "+dasfeature.toString(), e); return null; } @@ -308,7 +311,7 @@ public class DasSequenceFeatureFetcher implements Runnable synchronized void setThreadsRunning(int i) { threadsRunning += i; - if(threadsRunning<1) + if(threadsRunning<1 && allBatchesComplete) { af.setProgressBar("DAS Feature Fetching Complete", startTime); @@ -356,9 +359,20 @@ public class DasSequenceFeatureFetcher implements Runnable try { + //We must limit the feature fetching to 20 to prevent + //Servers being overloaded with too many requests + int batchCount = 0; + int batchMaxSize = 20; int seqIndex = 0; while (seqIndex < sequences.length) { + batchCount ++; + if(batchCount>=batchMaxSize) + { + waitTillBatchComplete(); + batchCount = 0; + } + DBRefEntry [] uprefs = jalview.util.DBRefUtils.selectRefs(sequences[seqIndex].getDBRef(), new String[] { jalview.datamodel.DBRefSource.PDB, @@ -423,6 +437,22 @@ public class DasSequenceFeatureFetcher implements Runnable { ex.printStackTrace(); } + allBatchesComplete = true; + } + + void waitTillBatchComplete() + { + while( threadsRunning > 0 ) + { + try{ + Thread.sleep(1000); + + }catch(Exception ex) + { + ex.printStackTrace(); + } + } + } -- 1.7.10.2