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

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

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

dao/DaoAdresseService/src/dk/daoas/daoadresseservice/GoogleStreetnameHelper.java revision 2411 by torben, Sat Feb 28 17:08:59 2015 UTC dao/DaoAdresseService/src/main/java/dk/daoas/daoadresseservice/GoogleStreetnameHelper.java revision 2567 by torben, Sun Jun 7 18:09:16 2015 UTC
# Line 10  import com.google.code.geocoder.model.Ge Line 10  import com.google.code.geocoder.model.Ge
10  import com.google.code.geocoder.model.GeocoderResult;  import com.google.code.geocoder.model.GeocoderResult;
11  import com.google.code.geocoder.model.GeocoderStatus;  import com.google.code.geocoder.model.GeocoderStatus;
12    
13    import com.google.common.util.concurrent.RateLimiter;
14    
15  import dk.daoas.daoadresseservice.admin.ServiceConfig;  import dk.daoas.daoadresseservice.admin.ServiceConfig;
16  import dk.daoas.daoadresseservice.beans.SearchRequest;  import dk.daoas.daoadresseservice.beans.SearchRequest;
17  import dk.daoas.daoadresseservice.beans.SearchResult;  import dk.daoas.daoadresseservice.beans.SearchResult;
# Line 20  import dk.thoerup.circuitbreaker.Circuit Line 22  import dk.thoerup.circuitbreaker.Circuit
22  public class GoogleStreetnameHelper implements StreetnameHelper {  public class GoogleStreetnameHelper implements StreetnameHelper {
23                    
24          ServiceConfig conf;          ServiceConfig conf;
25            RateLimiter limiter;
26    
27          public GoogleStreetnameHelper(ServiceConfig conf) {          public GoogleStreetnameHelper(ServiceConfig conf) {
28                  this.conf = conf;                  this.conf = conf;
29    
30                    limiter = RateLimiter.create( 10.0 ); //max 10 req /sec
31          }          }
32    
33          @Override          @Override
# Line 29  public class GoogleStreetnameHelper impl Line 35  public class GoogleStreetnameHelper impl
35                  if (conf.useGoogle == false)                  if (conf.useGoogle == false)
36                          return null;                          return null;
37                                    
38    
39                  result.google = true;                  result.google = true;
40                                    
41                  try {                  try {
42                          GoogleInvocation wrapper = new GoogleInvocation( conf, request.postnr, request.vejnavn );                          GoogleInvocation wrapper = new GoogleInvocation( limiter, conf, request.postnr, request.vejnavn );
43                          CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("google");                          CircuitBreaker breaker = CircuitBreakerManager.getManager().getCircuitBreaker("google");
44    
45                                                    
# Line 50  public class GoogleStreetnameHelper impl Line 57  public class GoogleStreetnameHelper impl
57                  ServiceConfig conf;                  ServiceConfig conf;
58                  int postnr;                  int postnr;
59                  String vejnavn;                  String vejnavn;
60                    RateLimiter limiter;
61                                    
62                  public GoogleInvocation(ServiceConfig conf, int postnr, String vejnavn) {                  public GoogleInvocation(RateLimiter limiter, ServiceConfig conf, int postnr, String vejnavn) {
63                            this.limiter = limiter;
64                          this.conf = conf;                          this.conf = conf;
65                          this.postnr= postnr;                          this.postnr= postnr;
66                          this.vejnavn = vejnavn;                          this.vejnavn = vejnavn;
# Line 60  public class GoogleStreetnameHelper impl Line 69  public class GoogleStreetnameHelper impl
69    
70                  @Override                  @Override
71                  public String proceed() throws Exception {                  public String proceed() throws Exception {
72                    
73                            limiter.acquire();
74                                                    
75                          final Geocoder geocoder;                          final Geocoder geocoder;
76                          if ( conf.googleApiKey != null ) {                          if ( conf.googleApiKey != null ) {

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

  ViewVC Help
Powered by ViewVC 1.1.20