4 |
|
|
5 |
import java.net.URL; |
import java.net.URL; |
6 |
import java.sql.SQLException; |
import java.sql.SQLException; |
7 |
|
import java.util.HashMap; |
8 |
import java.util.Map; |
import java.util.Map; |
9 |
import java.util.logging.Level; |
import java.util.logging.Level; |
10 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
11 |
|
|
12 |
|
import net.sf.jsr107cache.Cache; |
13 |
|
import net.sf.jsr107cache.CacheException; |
14 |
|
import net.sf.jsr107cache.CacheManager; |
15 |
|
|
16 |
import org.jsoup.nodes.Document; |
import org.jsoup.nodes.Document; |
17 |
import org.jsoup.nodes.Element; |
import org.jsoup.nodes.Element; |
18 |
import org.jsoup.select.Elements; |
import org.jsoup.select.Elements; |
19 |
|
|
20 |
|
import com.google.appengine.api.memcache.jsr107cache.GCacheFactory; |
21 |
|
|
22 |
import dk.thoerup.android.traininfo.common.TimetableBean; |
import dk.thoerup.android.traininfo.common.TimetableBean; |
23 |
import dk.thoerup.android.traininfo.common.TimetableEntry; |
import dk.thoerup.android.traininfo.common.TimetableEntry; |
24 |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
29 |
public class TimetableFetcher { |
public class TimetableFetcher { |
30 |
|
|
31 |
|
|
32 |
Map<String, TimetableBean> cache; |
Cache cache; |
33 |
Map<String, Integer> stationCache; |
Cache stationCache; |
34 |
|
|
35 |
StationDAO stationDao = new StationDAO(); |
StationDAO stationDao = new StationDAO(); |
36 |
|
|
40 |
private boolean useAzureSite; |
private boolean useAzureSite; |
41 |
private int replyTimeout; |
private int replyTimeout; |
42 |
|
|
43 |
|
@SuppressWarnings("unchecked") |
44 |
public TimetableFetcher(boolean azureSite, int cacheTimeout, int replyTimeout) { |
public TimetableFetcher(boolean azureSite, int cacheTimeout, int replyTimeout) { |
45 |
useAzureSite = azureSite; |
useAzureSite = azureSite; |
46 |
this.replyTimeout = replyTimeout; |
this.replyTimeout = replyTimeout; |
47 |
|
|
48 |
|
Map props = new HashMap(); |
49 |
|
props.put(GCacheFactory.EXPIRATION_DELTA_MILLIS, cacheTimeout); |
50 |
|
|
51 |
|
try { |
52 |
|
cache = CacheManager.getInstance().getCacheFactory().createCache(props); |
53 |
|
} catch (CacheException e) { |
54 |
|
logger.log(Level.WARNING, "error creating cache", e); |
55 |
|
} |
56 |
|
|
57 |
|
props = new HashMap(); |
58 |
|
props.put(GCacheFactory.EXPIRATION_DELTA_MILLIS, 3*60*60*1000); |
59 |
|
|
60 |
cache = new TimeoutMap<String,TimetableBean>(cacheTimeout); |
try { |
61 |
stationCache = new TimeoutMap<String,Integer>( 3*60*60*1000 ); |
stationCache = CacheManager.getInstance().getCacheFactory().createCache(props); |
62 |
|
} catch (CacheException e) { |
63 |
|
logger.log(Level.WARNING, "error creating cache", e); |
64 |
|
} |
65 |
} |
} |
66 |
|
|
67 |
|
|