import org.biojava.dasobert.dasregistry.Das1Source;
/** a thread that connects to a DAS - Feature service and gets the features
- *
+ *
* @author Andreas Prlic
*/
public class FeatureThread
- implements Runnable
+ implements Runnable
{
-
+
/** number of times the client tries to reconnect to the server if a "come back later" is returned.
* the server should provide a reasonable estimation how long it will take him to create results.
* if this number of requests is still not successfull, give up.
String ac ;
List featureListeners;
Thread thread;
-
+
public FeatureThread (String accessionCode, Das1Source dasSource) {
this.dasSource = dasSource;
this.ac = accessionCode;
public void addFeatureListener(FeatureListener li) {
featureListeners.add(li);
}
-
+
public void clearFeatureListeners() {
featureListeners.clear();
}
notify();
}
-
+
public void run() {
cmd = new URL(queryString);
} catch (MalformedURLException e ) {
logger.warning("got MalformedURL from das source " +dasSource);
- e.printStackTrace();
+ e.printStackTrace();
+
}
logger.info("requesting features from " + cmd);
DAS_FeatureRetrieve ftmp = new DAS_FeatureRetrieve(cmd);
-
-
+
+
int comeBackLater = ftmp.getComeBackLater();
int securityCounter = 0;
while ( (thread == me) && ( comeBackLater > 0 )) {
securityCounter++;
if ( securityCounter >= MAX_COME_BACK_ITERATIONS){
- comeBackLater = -1;
+ comeBackLater = -1;
break;
-
+
}
notifyComeBackLater(comeBackLater);
// server is still calculating - asks us to come back later
comeBackLater = -1;
break;
}
-
+
ftmp.reload();
- comeBackLater = ftmp.getComeBackLater();
+ comeBackLater = ftmp.getComeBackLater();
}
if ( ! (thread == me ) ) {
}
List features = ftmp.get_features();
-
+
// a fallback mechanism to prevent DAS sources from bringing down spice
if ( features.size() > MAX_NR_FEATURES){
logger.warning("DAS source returned more than " + MAX_NR_FEATURES + "features. " +
" throwing away excess features at " +cmd);
features = features.subList(0,MAX_NR_FEATURES);
}
-
-
+
+
// notify FeatureListeners
Map[] feats = (Map[])features.toArray(new Map[features.size()]);
notifyFeatureListeners(feats);
fi.newFeatures(fevent);
}
}
-
+
/** the Annotation server requested to be queried again in a while
- *
+ *
* @param comeBackLater
*/
private void notifyComeBackLater(int comeBackLater){
FeatureListener fi = (FeatureListener)fiter.next();
fi.comeBackLater(event);
}
-
+
}