/[projects]/android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/banedk/MetroFetcher.java
ViewVC logotype

Diff of /android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/banedk/MetroFetcher.java

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

android/TrainInfoService/src/dk/thoerup/traininfoservice/banedk/MetroFetcher.java revision 1056 by torben, Tue Sep 14 17:01:24 2010 UTC android/TrainInfoServiceGoogle/src/dk/thoerup/traininfoservice/banedk/MetroFetcher.java revision 1093 by torben, Tue Sep 21 20:10:46 2010 UTC
# Line 2  package dk.thoerup.traininfoservice.bane Line 2  package dk.thoerup.traininfoservice.bane
2    
3    
4  import java.net.URL;  import java.net.URL;
5    import java.util.HashMap;
 import java.util.ArrayList;  
 import java.util.List;  
6  import java.util.Map;  import java.util.Map;
7    import java.util.logging.Level;
8  import java.util.logging.Logger;  import java.util.logging.Logger;
9    
10    import net.sf.jsr107cache.Cache;
11    import net.sf.jsr107cache.CacheException;
12    import net.sf.jsr107cache.CacheManager;
13    
14  import org.jsoup.nodes.Document;  import org.jsoup.nodes.Document;
15  import org.jsoup.nodes.Element;  import org.jsoup.nodes.Element;
16  import org.jsoup.select.Elements;  import org.jsoup.select.Elements;
17    
18    import com.google.appengine.api.memcache.jsr107cache.GCacheFactory;
19    
20    import dk.thoerup.android.traininfo.common.MetroBean;
21    import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry;
22  import dk.thoerup.circuitbreaker.CircuitBreaker;  import dk.thoerup.circuitbreaker.CircuitBreaker;
23  import dk.thoerup.circuitbreaker.CircuitBreakerManager;  import dk.thoerup.circuitbreaker.CircuitBreakerManager;
 import dk.thoerup.traininfoservice.StationBean;  
24  import dk.thoerup.traininfoservice.StationDAO;  import dk.thoerup.traininfoservice.StationDAO;
25  import dk.thoerup.traininfoservice.Statistics;  import dk.thoerup.traininfoservice.Statistics;
26    import dk.thoerup.traininfoservice.jdo.JdoStationBean;
27    
28    
29    
30  public class MetroFetcher {  public class MetroFetcher {
         public static class MetroEntry {  
                 String metro;  
                 String destination;  
                 String minutes;          
         }  
           
         public static class MetroBean {  
                 String head;  
                 String operationInfo; //driftsinfo  
                 String plan; // koereplan  
                   
                 List<MetroEntry> entries = new ArrayList<MetroEntry>();  
         }  
31                    
32          Logger logger = Logger.getLogger(MetroFetcher.class.getName());          Logger logger = Logger.getLogger(MetroFetcher.class.getName());
33          StationDAO stationDAO = new StationDAO();          StationDAO stationDAO = new StationDAO();
34                    
35          Map<String, MetroBean> cache = new TimeoutMap<String,MetroBean>(60000); //TODO: make metro cache timeout configurable          //Map<String, MetroBean> cache = new TimeoutMap<String,MetroBean>(60000); //TODO: make metro cache timeout configurable
36            Cache cache;
37            
38            public MetroFetcher() {
39                    Map props = new HashMap();
40                    props.put(GCacheFactory.EXPIRATION_DELTA_MILLIS, 60000);        
41                            
42                    try {
43                            cache = CacheManager.getInstance().getCacheFactory().createCache(props);            
44                    } catch (CacheException e) {
45                            logger.log(Level.WARNING, "error creating cache", e);
46                    }
47            }
48                    
49          public MetroBean cachedLookupMetroDepartures(int stationID) throws Exception {          public MetroBean cachedLookupMetroDepartures(int stationID) throws Exception {
50                  final String key = "metro:" + stationID;                  final String key = "metro:" + stationID;
51                                    
52                  MetroBean metroBean = cache.get(key);                  MetroBean metroBean = (MetroBean) cache.get(key);
53                                    
54                  if (metroBean == null) {                  if (metroBean == null) {
55                          metroBean = lookupMetroDepartures(stationID);                          metroBean = lookupMetroDepartures(stationID);
# Line 58  public class MetroFetcher { Line 63  public class MetroFetcher {
63    
64          public MetroBean lookupMetroDepartures(int stationID) throws Exception {          public MetroBean lookupMetroDepartures(int stationID) throws Exception {
65                                    
66                  StationBean station = stationDAO.getById(stationID) ;                  JdoStationBean station = stationDAO.getById(stationID) ;
67                                                    
68                                    
69                  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");

Legend:
Removed from v.1056  
changed lines
  Added in v.1093

  ViewVC Help
Powered by ViewVC 1.1.20