/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/DepartureFetcher.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1248 by torben, Thu Mar 31 17:13:19 2011 UTC revision 1305 by torben, Tue Apr 19 15:07:23 2011 UTC
# Line 16  import dk.thoerup.android.traininfo.comm Line 16  import dk.thoerup.android.traininfo.comm
16  import dk.thoerup.android.traininfo.common.StationBean.StationEntry;  import dk.thoerup.android.traininfo.common.StationBean.StationEntry;
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 DepartureFetcher {  public class DepartureFetcher {
24                    
# Line 38  public class DepartureFetcher { Line 39  public class DepartureFetcher {
39                    
40          StationDAO stationDao = new StationDAO();          StationDAO stationDao = new StationDAO();
41                    
42          private boolean useAzureSite;  
43          private int replyTimeout;          private TraininfoSettings settings;
44                    
45          public DepartureFetcher(boolean azureSite, int cacheTimeout, int replyTimeout) {          public DepartureFetcher(TraininfoSettings settings) {
46                  this.replyTimeout = replyTimeout;                  this.settings = settings;
47                  useAzureSite = azureSite;                  cache = new TimeoutMap<String,DepartureBean>( settings.getCacheTimeout() );
                 cache = new TimeoutMap<String,DepartureBean>(cacheTimeout);  
48          }          }
49                    
50                    
# Line 75  public class DepartureFetcher { Line 75  public class DepartureFetcher {
75                  StationEntry station = stationDao.getById(stationID);                  StationEntry station = stationDao.getById(stationID);
76                                    
77                  departureBean.stationName = station.getName();                  departureBean.stationName = station.getName();
78                    
79                  if (station.getRegional() != null && (type == FetchTrainType.REGIONAL||type == FetchTrainType.BOTH) ) {                  if (station.getRegional() != null && (type == FetchTrainType.REGIONAL||type == FetchTrainType.BOTH) ) {
80                          DepartureBean tempBean = lookupDepartures(station.getRegional(), TrainType.REGIONAL, arrival);                          DepartureBean tempBean = lookupDepartures(station.getRegional(), TrainType.REGIONAL, arrival);
81                          departureBean.entries.addAll( tempBean.entries );                          departureBean.entries.addAll( tempBean.entries );
# Line 92  public class DepartureFetcher { Line 92  public class DepartureFetcher {
92                          logger.info("No departures found for station " + stationID);                          logger.info("No departures found for station " + stationID);
93                  }                  }
94                                    
95                  Collections.sort( departureBean.entries );                  if (type == FetchTrainType.BOTH) { //if we have both S-tog and regional order by departure/arrival time
96                            Collections.sort( departureBean.entries );
97                    }
98    
99                                    
100                  return departureBean;                  return departureBean;
101          }          }
102                    
103          public DepartureBean lookupDepartures(String stationcode, TrainType type, boolean arrival) throws Exception {          public DepartureBean lookupDepartures(String stationcode, TrainType type, boolean arrival) throws Exception {
104                  if (useAzureSite == true) {                  if ( settings.getUseAzureSite() == true) {
105                          return lookupDeparturesAzureSite(stationcode, type, arrival);                          return lookupDeparturesAzureSite(stationcode, type, arrival);
106                  } else {                  } else {
107                          return lookupDeparturesWwwSite(stationcode, type, arrival);                          return lookupDeparturesWwwSite(stationcode, type, arrival);
# Line 141  public class DepartureFetcher { Line 143  public class DepartureFetcher {
143              String uri = "http://trafikinfo.bane.dk/Trafikinformation/AfgangAnkomst/" + arrivalDeparture + "/" + stationcode + "/" + typeString + "/UdvidetVisning";                      String uri = "http://trafikinfo.bane.dk/Trafikinformation/AfgangAnkomst/" + arrivalDeparture + "/" + stationcode + "/" + typeString + "/UdvidetVisning";        
144                            
145              logger.fine("URI: " + uri);                  logger.fine("URI: " + uri);    
146              JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), replyTimeout);              JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() );
147              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
148                            
149              Document page = (Document) breaker.invoke(wrapper);              Document page = (Document) breaker.invoke(wrapper);
# Line 247  public class DepartureFetcher { Line 249  public class DepartureFetcher {
249              logger.fine("URI:" + uri);              logger.fine("URI:" + uri);
250                            
251    
252              JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), replyTimeout);              JsoupInvocation wrapper = new JsoupInvocation( new URL(uri), settings.getReplyTimeout() );
253              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");              CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("banedk");
254                            
255              Element page = (Element) breaker.invoke(wrapper);              Element page = (Element) breaker.invoke(wrapper);

Legend:
Removed from v.1248  
changed lines
  Added in v.1305

  ViewVC Help
Powered by ViewVC 1.1.20