/* * Copyright 2011-2014 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 com.proofpoint.reporting; import com.google.inject.Binder; import com.google.inject.Module; import com.google.inject.Provides; import com.google.inject.Scopes; import com.proofpoint.configuration.ConfigurationModule; import com.proofpoint.discovery.client.DiscoveryBinder; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy; import java.util.concurrent.TimeUnit; import static com.proofpoint.concurrent.Threads.daemonThreadsNamed; import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; public class ReportingClientModuleWithPrivateIoPool implements Module { @Override public void configure(Binder binder) { binder.bind(ReportCollector.class).in(Scopes.SINGLETON); binder.bind(ReportClient.class).in(Scopes.SINGLETON); DiscoveryBinder.discoveryBinder(binder).bindDiscoveredHttpClient("reporting", ForReportClient.class).withPrivateIoThreadPool(); ConfigurationModule.bindConfig(binder).to(ReportClientConfig.class); } @Provides @ForReportCollector private static ScheduledExecutorService createCollectionExecutorService() { return newSingleThreadScheduledExecutor(daemonThreadsNamed("reporting-collector-%s")); } @Provides @ForReportClient private static ExecutorService createClientExecutorService() { return new ThreadPoolExecutor(1, 1, 0, TimeUnit.NANOSECONDS, new LinkedBlockingQueue<Runnable>(5), daemonThreadsNamed("reporting-client-%s"), new DiscardOldestPolicy()); } }