39 |
Logger logger = Logger.getLogger(MetroFetcher.class.getName()); |
Logger logger = Logger.getLogger(MetroFetcher.class.getName()); |
40 |
StationDAO stationDAO = new StationDAO(); |
StationDAO stationDAO = new StationDAO(); |
41 |
|
|
42 |
Map<String, MetroBean> cache = new TimeoutMap<String,MetroBean>(1000); |
Map<String, MetroBean> cache = new TimeoutMap<String,MetroBean>(60000); //TODO: make metro cache timeout configurable |
43 |
|
|
44 |
public MetroBean cachedLookupMetroDepartures(int stationID) throws Exception { |
public MetroBean cachedLookupMetroDepartures(int stationID) throws Exception { |
45 |
final String key = "metro:" + stationID; |
final String key = "metro:" + stationID; |
62 |
|
|
63 |
|
|
64 |
URL url = new URL("http://www.m.dk/layouts/Metro/Widgets/MetroWidget.ashx?StationId=" + station.getMetro() + "&Congestion=true&Application=MyMetro&Expiration=true"); |
URL url = new URL("http://www.m.dk/layouts/Metro/Widgets/MetroWidget.ashx?StationId=" + station.getMetro() + "&Congestion=true&Application=MyMetro&Expiration=true"); |
65 |
|
logger.fine("URL:" + url); |
66 |
|
|
67 |
JsoupInvocation wrapper = new JsoupInvocation( url, 3000); |
JsoupInvocation wrapper = new JsoupInvocation( url, 3000); |
68 |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("metro"); |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("metro"); |
101 |
bean.entries.add(entry); |
bean.entries.add(entry); |
102 |
} |
} |
103 |
|
|
104 |
bean.operationInfo = contentElems.get(3).text(); |
bean.operationInfo = contentElems.get(3).text(); |
105 |
bean.plan = contentElems.get(5).text(); |
|
106 |
|
int planIndex; |
107 |
|
if (contentElems.get(4).text().trim().equalsIgnoreCase("stationsinformation")) { |
108 |
|
planIndex = 7; |
109 |
|
} else { |
110 |
|
planIndex = 5; |
111 |
|
} |
112 |
|
|
113 |
|
bean.plan = contentElems.get(planIndex).text(); |
114 |
|
|
115 |
return bean; |
return bean; |
116 |
} |
} |