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

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

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

revision 835 by torben, Wed May 5 20:11:03 2010 UTC revision 836 by torben, Fri Jun 11 17:12:29 2010 UTC
# Line 3  package dk.thoerup.traininfoservice.bane Line 3  package dk.thoerup.traininfoservice.bane
3    
4  import java.io.IOException;  import java.io.IOException;
5  import java.net.URL;  import java.net.URL;
6    import java.sql.SQLException;
7  import java.util.ArrayList;  import java.util.ArrayList;
8  import java.util.List;  import java.util.List;
9  import java.util.Map;  import java.util.Map;
10    import java.util.logging.Level;
11  import java.util.logging.Logger;  import java.util.logging.Logger;
12    
13  import com.gargoylesoftware.htmlunit.BrowserVersion;  import com.gargoylesoftware.htmlunit.BrowserVersion;
# Line 18  import com.gargoylesoftware.htmlunit.htm Line 20  import com.gargoylesoftware.htmlunit.htm
20    
21  import dk.thoerup.circuitbreaker.CircuitBreaker;  import dk.thoerup.circuitbreaker.CircuitBreaker;
22  import dk.thoerup.circuitbreaker.CircuitBreakerManager;  import dk.thoerup.circuitbreaker.CircuitBreakerManager;
23    import dk.thoerup.traininfoservice.StationDAO;
24  import dk.thoerup.traininfoservice.Statistics;  import dk.thoerup.traininfoservice.Statistics;
25    
26  public class TimetableFetcher {  public class TimetableFetcher {
# Line 29  public class TimetableFetcher { Line 32  public class TimetableFetcher {
32          }          }
33                                    
34          Map<String, List<TimetableBean>> cache;          Map<String, List<TimetableBean>> cache;
35            Map<String, Integer> stationCache;
36    
37            StationDAO stationDao = new StationDAO();
38                    
39                    
40          Logger logger = Logger.getLogger(TimetableFetcher.class.getName());          Logger logger = Logger.getLogger(TimetableFetcher.class.getName());
# Line 39  public class TimetableFetcher { Line 45  public class TimetableFetcher {
45                  useTempSite = tmpSite;                  useTempSite = tmpSite;
46                                    
47                  cache = new TimeoutMap<String,List<TimetableBean>>(cacheTimeout);                  cache = new TimeoutMap<String,List<TimetableBean>>(cacheTimeout);
48                    stationCache = new TimeoutMap<String,Integer>( 3*60*60*1000 );
49          }          }
50                    
51                    
52          List<TimetableBean> cachedLookupTimetable(String trainID, String type) throws Exception {          List<TimetableBean> cachedLookupTimetable(String trainID, String type) throws Exception {
53                  String key = trainID+type;                  String key = trainID+type;
54                  List<TimetableBean> list = cache.get(key);                  List<TimetableBean> list = null;//cache.get(key);
55                                    
56                  if (list == null) {                  if (list == null) {
57                          list = lookupTimetable(trainID,type);                          list = lookupTimetable(trainID,type);
# Line 63  public class TimetableFetcher { Line 70  public class TimetableFetcher {
70                          return new ArrayList<TimetableBean>(); // no timetable data on temp site                          return new ArrayList<TimetableBean>(); // no timetable data on temp site
71                  }                  }
72          }          }
73            
74            int getStationId(String name) {
75                    Integer id = stationCache.get(name);
76                    
77                    if (id == null) {
78                            try {
79                                    id = stationDao.getBySpecificName(name);
80                                    stationCache.put(name, id);
81                            } catch (SQLException e) {
82                                    logger.log(Level.SEVERE, "getStationId failed", e);
83                                    id = -1;
84                            }
85                    }
86    
87                    return id;
88            }
89    
90          List<TimetableBean> lookupTimetableRealSite(String trainID, String type) throws Exception {                      List<TimetableBean> lookupTimetableRealSite(String trainID, String type) throws Exception {            
91                  List<TimetableBean> timetableList = new ArrayList<TimetableBean>();                  List<TimetableBean> timetableList = new ArrayList<TimetableBean>();
# Line 105  public class TimetableFetcher { Line 128  public class TimetableFetcher {
128                          }                          }
129                                                    
130                          TimetableBean bean = new TimetableBean();                          TimetableBean bean = new TimetableBean();
131                          bean.setStation( fields.get(0).asText() );                          
132                            String station = fields.get(0).asText() ;
133                            if (station.equals("København"))
134                                    station = "København H"; //correct inconsistency in naming
135                            
136                            bean.setStation( station );
137                          bean.setArrival( fields.get(1).asText() );                          bean.setArrival( fields.get(1).asText() );
138                          bean.setDeparture( fields.get(2).asText() );                          bean.setDeparture( fields.get(2).asText() );
139                                                    
# Line 114  public class TimetableFetcher { Line 142  public class TimetableFetcher {
142                                  currentStationSaved = true;                                  currentStationSaved = true;
143                          }                          }
144                                                    
145                            bean.setStationId( getStationId( station ));
146                            
147                          timetableList.add(bean);                          timetableList.add(bean);
148    
149                  }                  }

Legend:
Removed from v.835  
changed lines
  Added in v.836

  ViewVC Help
Powered by ViewVC 1.1.20