--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/MetroFetcher.java 2010/09/13 17:57:31 1042 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/MetroFetcher.java 2010/09/16 13:32:10 1060 @@ -2,44 +2,60 @@ import java.net.URL; - import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.logging.Logger; - import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; import dk.thoerup.circuitbreaker.CircuitBreaker; import dk.thoerup.circuitbreaker.CircuitBreakerManager; -import dk.thoerup.traininfoservice.StationBean; import dk.thoerup.traininfoservice.StationDAO; import dk.thoerup.traininfoservice.Statistics; +import dk.thoerup.traininfoservice.StationBean.StationEntry; public class MetroFetcher { + @Root(name="entry") public static class MetroEntry { + + @org.simpleframework.xml.Element String metro; + + @org.simpleframework.xml.Element String destination; + + @org.simpleframework.xml.Element String minutes; } + @Root(name="metrodepatures") public static class MetroBean { + + @org.simpleframework.xml.Element String head; - String operationInfo; //driftsinfo - String plan; // koereplan + + @org.simpleframework.xml.Element(name="operations") + String operationInfo; //driftsinfo + + @ElementList List entries = new ArrayList(); + + @org.simpleframework.xml.Element + String plan; // koereplan } Logger logger = Logger.getLogger(MetroFetcher.class.getName()); StationDAO stationDAO = new StationDAO(); - Map cache = new TimeoutMap(1000); + Map cache = new TimeoutMap(60000); //TODO: make metro cache timeout configurable public MetroBean cachedLookupMetroDepartures(int stationID) throws Exception { final String key = "metro:" + stationID; @@ -58,10 +74,11 @@ public MetroBean lookupMetroDepartures(int stationID) throws Exception { - StationBean station = stationDAO.getById(stationID) ; + StationEntry station = stationDAO.getById(stationID) ; URL url = new URL("http://www.m.dk/layouts/Metro/Widgets/MetroWidget.ashx?StationId=" + station.getMetro() + "&Congestion=true&Application=MyMetro&Expiration=true"); + logger.fine("URL:" + url); JsoupInvocation wrapper = new JsoupInvocation( url, 3000); CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("metro"); @@ -82,27 +99,41 @@ for (int i=1; i