--- android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2009/10/02 17:18:31 389 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/TimetableFetcher.java 2010/02/02 18:47:55 581 @@ -5,6 +5,7 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.logging.Logger; import com.gargoylesoftware.htmlunit.Page; @@ -14,6 +15,9 @@ import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import dk.thoerup.circuitbreaker.CircuitBreaker; +import dk.thoerup.circuitbreaker.CircuitBreakerManager; + public class TimetableFetcher { class NullRefreshHandler implements RefreshHandler { @@ -22,11 +26,17 @@ } - TimeoutCache> cache = new TimeoutCache>(120 * 1000); + Map> cache = new TimeoutMap>(120 * 1000); Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); + private boolean useTempSite; + + public TimetableFetcher(boolean tmpSite) { + useTempSite = tmpSite; + } + List cachedLookupTimetable(String trainID, String type) throws Exception { String key = trainID+type; @@ -40,8 +50,16 @@ } return list; } + + List lookupTimetable(String trainID, String type) throws Exception { + if (useTempSite == false ){ + return lookupTimetableRealSite(trainID, type); + } else { + return new ArrayList(); // no timetable data on temp site + } + } - List lookupTimetable(String trainID, String type) throws Exception { + List lookupTimetableRealSite(String trainID, String type) throws Exception { List timetableList = new ArrayList(); String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276"; @@ -54,8 +72,11 @@ webClient.setCssEnabled(false); - final HtmlPage page = webClient.getPage(url); + BanedkInvocation wrapper = new BanedkInvocation(webClient, url); + CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); + HtmlPage page = (HtmlPage) breaker.invoke(wrapper); + boolean currentStation = false; boolean currentStationSaved = false;