16 |
import dk.thoerup.android.traininfo.common.TimetableEntry; |
import dk.thoerup.android.traininfo.common.TimetableEntry; |
17 |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
18 |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
19 |
import dk.thoerup.traininfoservice.StationDAO; |
import dk.thoerup.genericjavautils.TimeoutMap; |
20 |
import dk.thoerup.traininfoservice.Statistics; |
import dk.thoerup.traininfoservice.Statistics; |
21 |
|
import dk.thoerup.traininfoservice.TraininfoSettings; |
22 |
|
import dk.thoerup.traininfoservice.db.StationDAO; |
23 |
|
|
24 |
public class TimetableFetcher { |
public class TimetableFetcher { |
25 |
|
|
31 |
|
|
32 |
|
|
33 |
Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); |
Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); |
34 |
|
|
35 |
|
TraininfoSettings settings; |
36 |
|
|
37 |
private boolean useAzureSite; |
public TimetableFetcher(TraininfoSettings settings) { |
38 |
private int replyTimeout; |
this.settings = settings; |
|
|
|
|
public TimetableFetcher(boolean azureSite, int cacheTimeout, int replyTimeout) { |
|
|
useAzureSite = azureSite; |
|
|
this.replyTimeout = replyTimeout; |
|
39 |
|
|
40 |
cache = new TimeoutMap<String,TimetableBean>(cacheTimeout); |
cache = new TimeoutMap<String,TimetableBean>( settings.getCacheTimeout() ); |
41 |
stationCache = new TimeoutMap<String,Integer>( 3*60*60*1000 ); |
stationCache = new TimeoutMap<String,Integer>( 3*60*60*1000 ); |
42 |
} |
} |
43 |
|
|
57 |
} |
} |
58 |
|
|
59 |
TimetableBean lookupTimetable(String trainID, String type) throws Exception { |
TimetableBean lookupTimetable(String trainID, String type) throws Exception { |
60 |
if (useAzureSite == true ){ |
if (settings.getUseAzureSite() == true ){ |
61 |
return lookupTimetableAzureSite(trainID, type); |
return lookupTimetableAzureSite(trainID, type); |
62 |
|
|
63 |
} else { |
} else { |
64 |
return lookupTimetableWwwSite(trainID, type); |
return lookupTimetableMobileSite(trainID, type); |
65 |
} |
} |
66 |
} |
} |
67 |
|
|
88 |
String url = "http://trafikinfo.bane.dk/TrafikInformation/Ruteplan/" + trainID; |
String url = "http://trafikinfo.bane.dk/TrafikInformation/Ruteplan/" + trainID; |
89 |
logger.fine("URL:" + url); |
logger.fine("URL:" + url); |
90 |
|
|
91 |
JsoupInvocation wrapper = new JsoupInvocation( new URL(url) , replyTimeout); |
JsoupInvocation wrapper = new JsoupInvocation( new URL(url) , settings.getReplyTimeout() ); |
92 |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
93 |
|
|
94 |
Document doc = (Document) breaker.invoke(wrapper); |
Document doc = (Document) breaker.invoke(wrapper); |
171 |
return timetableBean; |
return timetableBean; |
172 |
} |
} |
173 |
|
|
174 |
|
TimetableBean lookupTimetableMobileSite(String trainID, String type) throws Exception { |
175 |
|
return new TimetableBean(); //dummy skeleton method |
176 |
|
} |
177 |
|
|
178 |
|
@Deprecated |
179 |
TimetableBean lookupTimetableWwwSite(String trainID, String type) throws Exception { |
TimetableBean lookupTimetableWwwSite(String trainID, String type) throws Exception { |
180 |
TimetableBean timetableBean = new TimetableBean(); |
TimetableBean timetableBean = new TimetableBean(); |
181 |
|
|
183 |
logger.fine("URL:" + url); |
logger.fine("URL:" + url); |
184 |
|
|
185 |
|
|
186 |
JsoupInvocation wrapper = new JsoupInvocation( new URL(url) , replyTimeout); |
JsoupInvocation wrapper = new JsoupInvocation( new URL(url) , settings.getReplyTimeout() ); |
187 |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk"); |
188 |
|
|
189 |
Document doc = (Document) breaker.invoke(wrapper); |
Document doc = (Document) breaker.invoke(wrapper); |