/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.facebook.presto.router;

import com.facebook.presto.router.cluster.ClusterManager;
import com.facebook.presto.router.cluster.ClusterStatusResource;
import com.facebook.presto.router.cluster.ClusterStatusTracker;
import com.facebook.presto.router.cluster.ForClusterInfoTracker;
import com.facebook.presto.router.cluster.ForQueryInfoTracker;
import com.facebook.presto.router.cluster.RemoteInfoFactory;
import com.google.inject.Binder;
import com.google.inject.Scopes;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.airlift.units.Duration;

import static io.airlift.configuration.ConfigBinder.configBinder;
import static io.airlift.http.client.HttpClientBinder.httpClientBinder;
import static io.airlift.http.server.HttpServerBinder.httpServerBinder;
import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder;
import static java.util.concurrent.TimeUnit.SECONDS;

public class RouterModule
        extends AbstractConfigurationAwareModule
{
    @Override
    protected void setup(Binder binder)
    {
        httpServerBinder(binder).bindResource("/ui", "router_ui").withWelcomeFile("index.html");
        configBinder(binder).bindConfig(RouterConfig.class);

        binder.bind(ClusterManager.class).in(Scopes.SINGLETON);
        binder.bind(RemoteInfoFactory.class).in(Scopes.SINGLETON);

        httpClientBinder(binder).bindHttpClient("query-tracker", ForQueryInfoTracker.class)
                .withConfigDefaults(config -> {
                    config.setIdleTimeout(new Duration(30, SECONDS));
                    config.setRequestTimeout(new Duration(10, SECONDS));
                });
        httpClientBinder(binder).bindHttpClient("query-tracker", ForClusterInfoTracker.class)
                .withConfigDefaults(config -> {
                    config.setIdleTimeout(new Duration(30, SECONDS));
                    config.setRequestTimeout(new Duration(10, SECONDS));
                });
        binder.bind(ClusterStatusTracker.class).in(Scopes.SINGLETON);

        jaxrsBinder(binder).bind(RouterResource.class);
        jaxrsBinder(binder).bind(ClusterStatusResource.class);
    }
}

@@ -1135,16 +1135,57 @@
 ation;%0A%0A
+import java.lang.annotation.Annotation;%0A%0A
 import s
@@ -1573,16 +1573,195 @@
 odule%0A%7B%0A
+    private static final int IDLE_TIMEOUT_SECOND = 30;%0A    private static final int REQUEST_TIMEOUT_SECOND = 10;%0A    private static final String QUERY_TRACKER = %22query-tracker%22;%0A%0A
     @Ove
@@ -2103,33 +2103,37 @@
 ETON);%0A%0A        
-h
+bindH
 ttpClientBinder(
@@ -2129,63 +2129,116 @@
 ient
-B
+(b
 inder
-(binder).bindHttpClient(%22query-tracker%22, ForQu
+, QUERY_TRACKER, ForQueryInfoTracker.class);%0A        bindHttpClient(binder, QUERY_TRACKER, ForClust
 er
-y
 Info
@@ -2243,32 +2243,34 @@
 foTracker.class)
+;%0A
 %0A               
@@ -2266,210 +2266,302 @@
     
-        .withConfigDefaults(config -%3E %7B%0A                    config.setIdleTimeout(new Duration(30, SECONDS));%0A                    config.setRequestTimeout(new Duration(10, SECONDS));%0A                %7D);
+binder.bind(ClusterStatusTracker.class).in(Scopes.SINGLETON);%0A%0A        jaxrsBinder(binder).bind(RouterResource.class);%0A        jaxrsBinder(binder).bind(ClusterStatusResource.class);%0A    %7D%0A%0A    private void bindHttpClient(Binder binder, String name, Class%3C? extends Annotation%3E annotation)%0A    %7B
 %0A   
@@ -2609,52 +2609,24 @@
 ent(
-%22query-tracker%22, ForClusterInfoTracker.class
+name, annotation
 )%0A  
@@ -2726,18 +2726,35 @@
 uration(
-30
+IDLE_TIMEOUT_SECOND
 , SECOND
@@ -2820,122 +2820,51 @@
 ion(
-10, SECONDS));%0A                %7D);%0A        binder.bind(ClusterStatusTracker.class).in(Scopes.SINGLETON
+REQUEST_TIMEOUT_SECOND, SECONDS)
 );%0A
-%0A
         
 jaxr
@@ -2863,116 +2863,17 @@
     
-jaxrsBinder(binder).bind(RouterResource.class);%0A        jaxrsBinder(binder).bind(ClusterStatusResource.class
+        %7D
 );%0A 

Refactor http client bindings to a common method