/[projects]/dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/OSMStreetnameHelper.java
ViewVC logotype

Diff of /dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/OSMStreetnameHelper.java

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

dao/DaoAdresseService/src/dk/daoas/daoadresseservice/OSMStreetnameHelper.java revision 2411 by torben, Sat Feb 28 17:08:59 2015 UTC dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/OSMStreetnameHelper.java revision 2998 by torben, Fri Apr 15 06:19:18 2016 UTC
# Line 4  import java.net.URLEncoder; Line 4  import java.net.URLEncoder;
4    
5  import com.google.gson.Gson;  import com.google.gson.Gson;
6    
7    import com.google.common.util.concurrent.RateLimiter;
8    
9    
10  import dk.daoas.daoadresseservice.admin.ServiceConfig;  import dk.daoas.daoadresseservice.admin.ServiceConfig;
11  import dk.daoas.daoadresseservice.beans.OSMAddress;  import dk.daoas.daoadresseservice.beans.OSMAddress;
12  import dk.daoas.daoadresseservice.beans.SearchRequest;  import dk.daoas.daoadresseservice.beans.SearchRequest;
# Line 16  import dk.thoerup.circuitbreaker.Circuit Line 19  import dk.thoerup.circuitbreaker.Circuit
19  public class OSMStreetnameHelper implements StreetnameHelper {  public class OSMStreetnameHelper implements StreetnameHelper {
20                    
21          ServiceConfig conf;          ServiceConfig conf;
22            RateLimiter limiter;
23                    
24          public OSMStreetnameHelper(ServiceConfig conf) {          public OSMStreetnameHelper(ServiceConfig conf) {
25                  this.conf = conf;                  this.conf = conf;
26    
27                    // http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
28                    limiter = RateLimiter.create( 10.0 ); //Max 10 requests pr sekund
29          }          }
30    
31          @Override          @Override
# Line 26  public class OSMStreetnameHelper impleme Line 33  public class OSMStreetnameHelper impleme
33                  if (conf.useOpenStreetMaps == false)                  if (conf.useOpenStreetMaps == false)
34                          return null;                          return null;
35                                    
36    
37                  result.osm = true;                  result.osm = true;
38                                    
39                  try {                  try {
40    
41                          OSMInvocation wrapper = new OSMInvocation( conf, request.postnr, request.vejnavn );                          OSMInvocation wrapper = new OSMInvocation( limiter, conf, request.postnr, request.vejnavn );
42                          CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("osm");                          CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("osm");
43    
44                          result.osmVej = (String) breaker.invoke(wrapper);                          result.osmVej = (String) breaker.invoke(wrapper);
# Line 46  public class OSMStreetnameHelper impleme Line 54  public class OSMStreetnameHelper impleme
54                  int postnr;                  int postnr;
55                  String vejnavn;                  String vejnavn;
56                  ServiceConfig conf;                  ServiceConfig conf;
57                    RateLimiter limiter;
58                                    
59                  public OSMInvocation(ServiceConfig conf, int postnr, String vejnavn) {                  public OSMInvocation(RateLimiter limiter, ServiceConfig conf, int postnr, String vejnavn) {
60                            this.limiter = limiter;
61                          this.conf = conf;                          this.conf = conf;
62                          this.postnr= postnr;                          this.postnr= postnr;
63                          this.vejnavn = vejnavn;                                          this.vejnavn = vejnavn;                
# Line 55  public class OSMStreetnameHelper impleme Line 65  public class OSMStreetnameHelper impleme
65                                    
66                  @Override                  @Override
67                  public String proceed() throws Exception {                  public String proceed() throws Exception {
68                            limiter.acquire();
69    
70    
71                          //TimingHelper timer = new TimingHelper();                          //TimingHelper timer = new TimingHelper();
72                          String encVej = URLEncoder.encode(vejnavn, "UTF-8");                          String encVej = URLEncoder.encode(vejnavn, "UTF-8");
73                                                    
# Line 76  public class OSMStreetnameHelper impleme Line 89  public class OSMStreetnameHelper impleme
89                          if (adrList.length != 1)                          if (adrList.length != 1)
90                                  return null;                                  return null;
91                                                                    
92                          if (adrList[0].address != null) {                          if (adrList[0].getAddress() != null) {
93                                  return adrList[0].address.road;                                  return adrList[0].getAddress().getRoad();
94                          }                          }
95    
96                          return null;                          return null;

Legend:
Removed from v.2411  
changed lines
  Added in v.2998

  ViewVC Help
Powered by ViewVC 1.1.20