chiark / gitweb /
fetch yarrg timestamp asynchronously
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 5 Sep 2010 12:28:19 +0000 (13:28 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 5 Sep 2010 12:28:19 +0000 (13:28 +0100)
src/com/tedpearson/ypp/market/MarketUploader.java

index b3fa49fdb99ed99dc0eb60974d88bc4f18fd380d..bac55220cf9658d6538a907bc754f30214a5d6c2 100644 (file)
@@ -409,19 +409,31 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
        *
        *       @exception Exception if an error we didn't expect occured
        */
+        private class YarrgTimestampFetcher extends Thread {
+           public String ts = null;
+           public void run() {
+               try {
+                   ts = getYarrgTimestamp();
+                   progresslog("(async) yarrg timestamp ready.");
+               } catch(Exception e) {
+                   error("Error getting YARRG timestamp: "+e);
+               }
+           }
+       };
+
        private void runUpload() throws Exception {
                progresslog("starting");
 
-               String yarrgts = "";
                ProgressMonitor pm = new ProgressMonitor(frame,"Processing Market Data","Getting table data",0,100);
                pm.setMillisToDecideToPopup(0);
                pm.setMillisToPopup(0);
                boolean doneyarrg = false, donepctb = false;
+               YarrgTimestampFetcher yarrgts_thread = null;
 
                if (uploadToYarrg) {
-                       progresslog("yarrg timestamp...");
-                       yarrgts = getYarrgTimestamp();
-                       progresslog("yarrg timestamp done.");
+                       progresslog("(async) yarrg timestamp...");
+                       yarrgts_thread = new YarrgTimestampFetcher();
+                       yarrgts_thread.start();
                }
 
                AccessibleTable accesstable = findMarketTable();
@@ -449,6 +461,14 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
                }
                progresslog("(async) getisland done");
 
+               String yarrgts = null;
+               if (yarrgts_thread != null) {
+                   progresslog("(async) yarrg timestamp join...");
+                   yarrgts_thread.join();
+                   progresslog("(async) yarrg timestamp joined.");
+                   yarrgts = yarrgts_thread.ts;
+               }
+
                if (islandName == null) {
                    error("Could not find island name in YPP user interface.");
                    return;