--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java 2009/09/28 19:14:18 349 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java 2009/10/02 15:06:08 387 @@ -8,7 +8,7 @@ import java.util.List; import java.util.logging.Logger; -import com.gargoylesoftware.htmlunit.ProxyConfig; + import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.DomNodeList; import com.gargoylesoftware.htmlunit.html.HtmlElement; @@ -19,6 +19,24 @@ public class DepartureFetcher { Logger logger = Logger.getLogger(DepartureFetcher.class.getName()); + + TimeoutCache> cache = new TimeoutCache>(120 * 1000); + + + + public List cachedLookupDepartures(int stationID) throws Exception { + + List list = cache.get(stationID); + + if (list == null) { + logger.warning("Departure: Cache miss " + stationID); //remove before production + list = lookupDepartures(stationID); + cache.put(stationID, list); + } else { + logger.warning("Departure: Cache hit " + stationID); //remove before production + } + return list; + } public List lookupDepartures(int stationID) throws Exception { @@ -63,7 +81,7 @@ List departureList = new ArrayList(); final WebClient webClient = new WebClient(); - webClient.setTimeout(1000); + webClient.setTimeout(2500); webClient.setJavaScriptEnabled(false); @@ -82,6 +100,8 @@ DepartureBean departure = new DepartureBean(); String time = fields.get(0).asText(); + if (time.equals("")) + time = "0:00"; //Bane.dk bug work-around departure.setTime(time); int updated = extractUpdated( fields.get(1) );