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