X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?a=blobdiff_plain;f=src%2Fcom%2Ftedpearson%2Fypp%2Fmarket%2FMarketUploader.java;h=6cf889a660f9d0aef519c02786f832cc560dfe82;hb=fdf8031c1556b47f0e3e4cefb9f49b1ea247f32b;hp=a7a90c8c1489d0dfcfaf3f381226c7d866ad2725;hpb=ba378a6dd2f4cf83c4d1b0781fab380259ff1a16;p=jarrg-ian.git diff --git a/src/com/tedpearson/ypp/market/MarketUploader.java b/src/com/tedpearson/ypp/market/MarketUploader.java index a7a90c8..6cf889a 100644 --- a/src/com/tedpearson/ypp/market/MarketUploader.java +++ b/src/com/tedpearson/ypp/market/MarketUploader.java @@ -76,7 +76,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis int index = text.indexOf(":"); String name = text.substring(0,index); islandName = name; - //System.out.println(islandName); + // if (dtxt!=null) dtxt.println(islandName); sidePanel.removePropertyChangeListener(this); latch.countDown(); } @@ -92,8 +92,9 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis } private void progresslog(String s) { + if (dtxt == null) return; long now = new Date().getTime(); - System.out.println("progress "+(now - startTime)+"ms "+s); + dtxt.println("progress "+(now - startTime)+"ms "+s); } private void progressNote(ProgressMonitor pm, String s) { @@ -395,7 +396,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis html = m.replaceAll(" "); } String whole_msg = "
"+html+""; - System.err.println("###" + whole_msg + "###"); + if (dtxt!=null) dtxt.println("###" + whole_msg + "###"); JOptionPane.showMessageDialog(frame,whole_msg,"Error",JOptionPane.ERROR_MESSAGE); } @@ -408,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(); @@ -437,7 +450,7 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis return; } - progresslog("getisland..."); + progresslog("(async) getisland..."); getIsland(); progresslog("getocean..."); getOcean(); @@ -446,6 +459,15 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis if (latch != null) { latch.await(2, java.util.concurrent.TimeUnit.SECONDS); } + 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."); @@ -532,14 +554,16 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis } // get commod map + progresslog("pctb commodmap..."); HashMap
- * Potential issues: When more commodities are added to the server, this
- * program will currently break unless the user deletes the preferences
- * file or we give them a new release with a slighly different storage
- * location for the data.
*
* @return a map where the key is the commodity and the value is the commodity id.
*/
@@ -701,7 +726,6 @@ public class MarketUploader implements TopLevelWindowListener, GUIInitializedLis
return commodMap;
}
HashMapUnexpected output from YARRG server
\n" + output);
+ return false;
}
+ if (dtxt!=null) dtxt.println(output);
return true;
}
private int calculateArbitrageCommodity(ArrayList