+ private static boolean _initingFetcher = false;
+
+ private static Thread initingThread = null;
+
+ /**
+ * Blocking method that initialises and returns the shared instance of the
+ * SequenceFetcher client
+ *
+ * @param guiWindow
+ * - where the initialisation delay message should be shown
+ * @return the singleton instance of the sequence fetcher client
+ */
+ public static jalview.ws.SequenceFetcher getSequenceFetcherSingleton(
+ final IProgressIndicator guiWindow)
+ {
+ if (_initingFetcher && initingThread != null && initingThread.isAlive())
+ {
+ if (guiWindow != null)
+ {
+ guiWindow.setProgressBar(
+ "Waiting for Sequence Database Fetchers to initialise",
+ Thread.currentThread().hashCode());
+ }
+ // initting happening on another thread - so wait around to see if it
+ // finishes.
+ while (_initingFetcher && initingThread != null
+ && initingThread.isAlive())
+ {
+ try
+ {
+ Thread.sleep(10);
+ } catch (Exception e)
+ {
+ }
+ ;
+ }
+ if (guiWindow != null)
+ {
+ guiWindow.setProgressBar(
+ "Waiting for Sequence Database Fetchers to initialise",
+ Thread.currentThread().hashCode());
+ }
+ }
+ if (sfetch == null
+ || dasRegistry != DasSourceBrowser.getDasRegistryURL())
+ {
+ _initingFetcher = true;
+ initingThread = Thread.currentThread();
+ /**
+ * give a visual indication that sequence fetcher construction is occuring
+ */
+ if (guiWindow != null)
+ {
+ guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
+ Thread.currentThread().hashCode());
+ }
+ dasRegistry = DasSourceBrowser.getDasRegistryURL();
+ jalview.ws.SequenceFetcher sf = new jalview.ws.SequenceFetcher();
+ if (guiWindow != null)
+ {
+ guiWindow.setProgressBar("Initialising Sequence Database Fetchers",
+ Thread.currentThread().hashCode());
+ }
+ sfetch = sf;
+ _initingFetcher = false;
+ initingThread = null;
+ }
+ return sfetch;
+ }
+