/*
 * Copyright 2010 Proofpoint, Inc.
 *
 * 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 io.airlift.discovery.client.testing;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.multibindings.Multibinder;
import io.airlift.discovery.client.Announcer;
import io.airlift.discovery.client.DiscoveryAnnouncementClient;
import io.airlift.discovery.client.DiscoveryLookupClient;
import io.airlift.discovery.client.ForDiscoveryClient;
import io.airlift.discovery.client.ServiceAnnouncement;
import io.airlift.discovery.client.ServiceSelector;
import io.airlift.discovery.client.ServiceSelectorFactory;
import io.airlift.discovery.client.ServiceSelectorManager;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

public class TestingDiscoveryModule implements Module
{
    @Override
    public void configure(Binder binder)
    {
        // bind discovery client and dependencies
        binder.bind(InMemoryDiscoveryClient.class).in(Scopes.SINGLETON);
        binder.bind(DiscoveryAnnouncementClient.class).to(Key.get(InMemoryDiscoveryClient.class)).in(Scopes.SINGLETON);
        binder.bind(DiscoveryLookupClient.class).to(Key.get(InMemoryDiscoveryClient.class)).in(Scopes.SINGLETON);

        // bind announcer
        binder.bind(Announcer.class).in(Scopes.SINGLETON);
        // Must create a multibinder for service announcements or construction will fail if no
        // service announcements are bound, which is legal for processes that don't have public services
        Multibinder.newSetBinder(binder, ServiceAnnouncement.class);

        binder.bind(ServiceSelectorFactory.class).to(SimpleServiceSelectorFactory.class).in(Scopes.SINGLETON);

        // bind selector manager with initial empty multibinder
        Multibinder.newSetBinder(binder, ServiceSelector.class);
        binder.bind(ServiceSelectorManager.class).in(Scopes.SINGLETON);
    }

    @Provides
    @ForDiscoveryClient
    public ScheduledExecutorService createDiscoveryExecutor()
    {
        return new ScheduledThreadPoolExecutor(10, new ThreadFactoryBuilder().setNameFormat("Discovery-%s").setDaemon(true).build());
    }
}

@@ -643,71 +643,8 @@
 g;%0A%0A
-import com.google.common.util.concurrent.ThreadFactoryBuilder;%0A
 impo
@@ -668,24 +668,24 @@
 ect.Binder;%0A
+
 import com.g
@@ -739,43 +739,8 @@
 le;%0A
-import com.google.inject.Provides;%0A
 impo
@@ -992,63 +992,8 @@
 nt;%0A
-import io.airlift.discovery.client.ForDiscoveryClient;%0A
 impo
@@ -1219,120 +1219,8 @@
 r;%0A%0A
-import java.util.concurrent.ScheduledExecutorService;%0Aimport java.util.concurrent.ScheduledThreadPoolExecutor;%0A%0A
 publ
@@ -1250,16 +1250,24 @@
 ryModule
+%0A       
  impleme
@@ -2375,254 +2375,7 @@
    %7D
-%0A%0A    @Provides%0A    @ForDiscoveryClient%0A    public ScheduledExecutorService createDiscoveryExecutor()%0A    %7B%0A        return new ScheduledThreadPoolExecutor(10, new ThreadFactoryBuilder().setNameFormat(%22Discovery-%25s%22).setDaemon(true).build());%0A    %7D
 %0A%7D%0A

Remove unused executor from TestingDiscoveryModule