7 |
import java.util.List; |
import java.util.List; |
8 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
9 |
|
|
10 |
import com.gargoylesoftware.htmlunit.*; |
import com.gargoylesoftware.htmlunit.Page; |
11 |
import com.gargoylesoftware.htmlunit.html.*; |
import com.gargoylesoftware.htmlunit.RefreshHandler; |
12 |
|
import com.gargoylesoftware.htmlunit.WebClient; |
13 |
|
import com.gargoylesoftware.htmlunit.html.DomNodeList; |
14 |
|
import com.gargoylesoftware.htmlunit.html.HtmlElement; |
15 |
|
import com.gargoylesoftware.htmlunit.html.HtmlPage; |
16 |
|
|
17 |
public class TimetableFetcher { |
public class TimetableFetcher { |
18 |
|
|
21 |
} |
} |
22 |
|
|
23 |
} |
} |
24 |
|
|
25 |
|
TimeoutCache<String, List<TimetableBean>> cache = new TimeoutCache<String,List<TimetableBean>>(120 * 1000); |
26 |
|
|
27 |
|
|
28 |
Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); |
Logger logger = Logger.getLogger(TimetableFetcher.class.getName()); |
29 |
|
|
30 |
|
|
31 |
|
List<TimetableBean> cachedLookupTimetable(String trainID, String type) throws Exception { |
32 |
|
String key = trainID+type; |
33 |
|
List<TimetableBean> list = cache.get(key); |
34 |
|
|
35 |
|
if (list == null) { |
36 |
|
logger.warning("Timetable: Cache miss " + trainID); //remove before production |
37 |
|
list = lookupTimetable(trainID,type); |
38 |
|
cache.put(key, list); |
39 |
|
} else { |
40 |
|
logger.warning("Timetable: Cache hit " + trainID); //remove before production |
41 |
|
} |
42 |
|
return list; |
43 |
|
} |
44 |
|
|
45 |
List<TimetableBean> lookupTimetable(String trainID, String type) throws Exception { |
List<TimetableBean> lookupTimetable(String trainID, String type) throws Exception { |
46 |
List<TimetableBean> timetableList = new ArrayList<TimetableBean>(); |
List<TimetableBean> timetableList = new ArrayList<TimetableBean>(); |
47 |
|
|
48 |
String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276"; |
String url = "http://www.bane.dk/visRute.asp?W=" + type + "&TogNr=" + trainID + "&artikelId=4276"; |