6 |
import java.util.ArrayList; |
import java.util.ArrayList; |
7 |
import java.util.Collections; |
import java.util.Collections; |
8 |
import java.util.List; |
import java.util.List; |
9 |
|
import java.util.Map; |
10 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
11 |
|
|
12 |
import com.gargoylesoftware.htmlunit.WebClient; |
import com.gargoylesoftware.htmlunit.WebClient; |
14 |
import com.gargoylesoftware.htmlunit.html.HtmlElement; |
import com.gargoylesoftware.htmlunit.html.HtmlElement; |
15 |
import com.gargoylesoftware.htmlunit.html.HtmlPage; |
import com.gargoylesoftware.htmlunit.html.HtmlPage; |
16 |
|
|
17 |
import dk.thoerup.curcuitbreaker.CircuitBreaker; |
import dk.thoerup.circuitbreaker.CircuitBreaker; |
18 |
import dk.thoerup.curcuitbreaker.CircuitBreakerManager; |
import dk.thoerup.circuitbreaker.CircuitBreakerManager; |
19 |
import dk.thoerup.traininfoservice.DBConnection; |
import dk.thoerup.traininfoservice.DBConnection; |
20 |
|
|
21 |
public class DepartureFetcher { |
public class DepartureFetcher { |
22 |
|
|
23 |
Logger logger = Logger.getLogger(DepartureFetcher.class.getName()); |
Logger logger = Logger.getLogger(DepartureFetcher.class.getName()); |
24 |
|
|
25 |
TimeoutCache<Integer, List<DepartureBean>> cache = new TimeoutCache<Integer,List<DepartureBean>>(120 * 1000); |
Map<Integer, List<DepartureBean>> cache = new TimeoutMap<Integer,List<DepartureBean>>(120 * 1000); |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
public List<DepartureBean> cachedLookupDepartures(int stationID) throws Throwable { |
public List<DepartureBean> cachedLookupDepartures(int stationID) throws Exception { |
30 |
|
|
31 |
List<DepartureBean> list = cache.get(stationID); |
List<DepartureBean> list = cache.get(stationID); |
32 |
|
|
40 |
} |
} |
41 |
|
|
42 |
|
|
43 |
public List<DepartureBean> lookupDepartures(int stationID) throws Throwable { |
public List<DepartureBean> lookupDepartures(int stationID) throws Exception { |
44 |
List<DepartureBean> departureList = new ArrayList<DepartureBean>(); |
List<DepartureBean> departureList = new ArrayList<DepartureBean>(); |
45 |
|
|
46 |
Connection conn = null; |
Connection conn = null; |
77 |
return departureList; |
return departureList; |
78 |
} |
} |
79 |
|
|
80 |
public List<DepartureBean> lookupDepartures(String stationcode, String type) throws Throwable { |
public List<DepartureBean> lookupDepartures(String stationcode, String type) throws Exception { |
81 |
|
|
82 |
List<DepartureBean> departureList = new ArrayList<DepartureBean>(); |
List<DepartureBean> departureList = new ArrayList<DepartureBean>(); |
83 |
|
|
189 |
} |
} |
190 |
|
|
191 |
//test |
//test |
192 |
public static void main(String args[]) throws Throwable { |
public static void main(String args[]) throws Exception { |
193 |
DepartureFetcher f = new DepartureFetcher(); |
DepartureFetcher f = new DepartureFetcher(); |
194 |
List<DepartureBean> deps = f.lookupDepartures("AR", "FJRN"); |
List<DepartureBean> deps = f.lookupDepartures("AR", "FJRN"); |
195 |
for(DepartureBean d : deps) { |
for(DepartureBean d : deps) { |