Update to guice 4.0

- Mark a lot of `@Provides` methods as final since guice 4.0 disallows overriding them
This commit is contained in:
Charles Allen 2015-08-07 11:42:16 -07:00
parent ae1736eeb4
commit 7e61216287
30 changed files with 80 additions and 65 deletions

View File

@ -72,14 +72,14 @@ public class DruidSecondaryModule implements Module
}
@Provides @LazySingleton @Json
public ObjectMapper getJsonMapper(final Injector injector)
public final ObjectMapper getJsonMapper(final Injector injector)
{
setupJackson(injector, jsonMapper);
return jsonMapper;
}
@Provides @LazySingleton @Smile
public ObjectMapper getSmileMapper(Injector injector)
public final ObjectMapper getSmileMapper(Injector injector)
{
setupJackson(injector, smileMapper);
return smileMapper;

View File

@ -40,7 +40,7 @@ public class JacksonConfigManagerModule implements Module
}
@Provides @ManageLifecycle
public ConfigManager getConfigManager(
public final ConfigManager getConfigManager(
final MetadataStorageConnector dbConnector,
final Supplier<MetadataStorageTablesConfig> dbTables,
final Supplier<ConfigManagerConfig> config,

View File

@ -98,7 +98,7 @@ public class AzureStorageDruidModule implements DruidModule
@Provides
@LazySingleton
public CloudBlobClient getCloudBlobClient(final AzureAccountConfig config)
public final CloudBlobClient getCloudBlobClient(final AzureAccountConfig config)
throws URISyntaxException, InvalidKeyException
{
CloudStorageAccount account = CloudStorageAccount.parse(
@ -115,7 +115,7 @@ public class AzureStorageDruidModule implements DruidModule
@Provides
@LazySingleton
public AzureStorage getAzureStorageContainer(
public final AzureStorage getAzureStorageContainer(
final CloudBlobClient cloudBlobClient
)
{

View File

@ -71,7 +71,15 @@ public class KafkaExtractionNamespaceModule implements DruidModule
@Provides
@Named("renameKafkaProperties")
@LazySingleton
public Properties getProperties(
public final Properties getProperties(
@Json ObjectMapper mapper,
Properties systemProperties
){
return getPropertiesInner(mapper, systemProperties);
}
// Protected for use in unit tests
protected Properties getPropertiesInner(
@Json ObjectMapper mapper,
Properties systemProperties
)
@ -98,7 +106,7 @@ public class KafkaExtractionNamespaceModule implements DruidModule
@Provides
@LazySingleton
public KafkaExtractionNamespaceFactory factoryFactory(
public final KafkaExtractionNamespaceFactory factoryFactory(
KafkaExtractionManager kafkaManager
)
{

View File

@ -31,9 +31,6 @@ import com.google.inject.Key;
import com.google.inject.Module;
import com.google.inject.Provider;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import com.metamx.common.ISE;
import com.metamx.common.StringUtils;
@ -58,10 +55,6 @@ import kafka.utils.ZKStringSerializer$;
import org.I0Itec.zkclient.ZkClient;
import org.apache.commons.io.FileUtils;
import org.apache.curator.test.TestingServer;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.PatternLayout;
import org.apache.zookeeper.CreateMode;
import org.joda.time.DateTime;
import org.junit.AfterClass;
@ -97,16 +90,18 @@ public class TestKafkaExtractionCluster
private static Injector injector;
public static class KafkaFactoryProvider implements Provider<ExtractionNamespaceFunctionFactory<?>>
{
private final KafkaExtractionManager kafkaExtractionManager;
@Inject
public KafkaFactoryProvider(
KafkaExtractionManager kafkaExtractionManager
){
)
{
this.kafkaExtractionManager = kafkaExtractionManager;
}
@Override
public ExtractionNamespaceFunctionFactory<?> get()
{
@ -222,6 +217,10 @@ public class TestKafkaExtractionCluster
}
System.setProperty("druid.extensions.searchCurrentClassloader", "false");
final Properties consumerProperties = new Properties(kafkaProperties);
consumerProperties.put("zookeeper.connect", zkTestServer.getConnectString() + "/kafka");
consumerProperties.put("zookeeper.session.timeout.ms", "10000");
consumerProperties.put("zookeeper.sync.time.ms", "200");
injector = Initialization.makeInjectorWithModules(
GuiceInjectors.makeStartupInjectorWithModules(
@ -239,15 +238,11 @@ public class TestKafkaExtractionCluster
new KafkaExtractionNamespaceModule()
{
@Override
public Properties getProperties(
protected Properties getPropertiesInner(
@Json ObjectMapper mapper,
Properties systemProperties
)
{
final Properties consumerProperties = new Properties(kafkaProperties);
consumerProperties.put("zookeeper.connect", zkTestServer.getConnectString() + "/kafka");
consumerProperties.put("zookeeper.session.timeout.ms", "10000");
consumerProperties.put("zookeeper.sync.time.ms", "200");
return consumerProperties;
}
}
@ -287,7 +282,8 @@ public class TestKafkaExtractionCluster
if (zkClient.exists("/kafka")) {
try {
zkClient.deleteRecursive("/kafka");
}catch(org.I0Itec.zkclient.exception.ZkException ex){
}
catch (org.I0Itec.zkclient.exception.ZkException ex) {
log.warn(ex, "error deleting /kafka zk node");
}
}
@ -301,7 +297,8 @@ public class TestKafkaExtractionCluster
}
}
private static final Properties makeProducerProperties(){
private static final Properties makeProducerProperties()
{
final Properties kafkaProducerProperties = new Properties();
kafkaProducerProperties.putAll(kafkaProperties);
kafkaProducerProperties.put(
@ -327,7 +324,16 @@ public class TestKafkaExtractionCluster
final Producer<byte[], byte[]> producer = new Producer<byte[], byte[]>(new ProducerConfig(kafkaProducerProperties));
try {
checkServer();
final ConcurrentMap<String, Function<String, String>> fnFn = injector.getInstance(Key.get(new TypeLiteral<ConcurrentMap<String, Function<String, String>>>(){}, Names.named("namespaceExtractionFunctionCache")));
final ConcurrentMap<String, Function<String, String>> fnFn = injector.getInstance(
Key.get(
new TypeLiteral<ConcurrentMap<String, Function<String, String>>>()
{
},
Names.named(
"namespaceExtractionFunctionCache"
)
)
);
KafkaExtractionNamespace extractionNamespace = new KafkaExtractionNamespace(topicName, namespace);
Assert.assertEquals(null, fnFn.get(extractionNamespace.getNamespace()).apply("foo"));

View File

@ -164,14 +164,14 @@ public class NamespacedExtractionModule implements DruidModule
@Provides
@Named("namespaceVersionMap")
@LazySingleton
public ConcurrentMap<String, String> getVersionMap()
public final ConcurrentMap<String, String> getVersionMap()
{
return new ConcurrentHashMap<>();
}
@Provides
@Named("namespaceExtractionFunctionCache")
public ConcurrentMap<String, Function<String, String>> getFnCache()
public final ConcurrentMap<String, Function<String, String>> getFnCache()
{
return fnCache;
}
@ -179,7 +179,7 @@ public class NamespacedExtractionModule implements DruidModule
@Provides
@Named("dimExtractionNamespace")
@LazySingleton
public Function<String, Function<String, String>> getFunctionMaker(
public final Function<String, Function<String, String>> getFunctionMaker(
@Named("namespaceExtractionFunctionCache")
final ConcurrentMap<String, Function<String, String>> fnCache
)

View File

@ -95,14 +95,14 @@ public class S3StorageDruidModule implements DruidModule
@Provides
@LazySingleton
public AWSCredentialsProvider getAWSCredentialsProvider(final AWSCredentialsConfig config)
public final AWSCredentialsProvider getAWSCredentialsProvider(final AWSCredentialsConfig config)
{
return AWSCredentialsUtils.defaultAWSCredentialsProviderChain(config);
}
@Provides
@LazySingleton
public RestS3Service getRestS3Service(AWSCredentialsProvider provider)
public final RestS3Service getRestS3Service(AWSCredentialsProvider provider)
{
if(provider.getCredentials() instanceof com.amazonaws.auth.AWSSessionCredentials) {
return new RestS3Service(new AWSSessionCredentialsAdapter(provider));

View File

@ -44,7 +44,7 @@ public class DruidTestModule implements Module
@Provides
@LazySingleton
public ServiceEmitter getServiceEmitter(Supplier<LoggingEmitterConfig> config, ObjectMapper jsonMapper)
public final ServiceEmitter getServiceEmitter(Supplier<LoggingEmitterConfig> config, ObjectMapper jsonMapper)
{
return new ServiceEmitter("", "", new LoggingEmitter(config.get(), jsonMapper));
}

View File

@ -74,6 +74,7 @@
<log4j.version>2.2</log4j.version>
<slf4j.version>1.7.10</slf4j.version>
<hadoop.compile.version>2.3.0</hadoop.compile.version>
<guice.version>4.0</guice.version>
</properties>
<modules>
@ -235,17 +236,17 @@
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0-beta</version>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>4.0-beta</version>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>4.0-beta</version>
<version>${guice.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.icu</groupId>

View File

@ -39,7 +39,7 @@ public class ConfigModule implements Module
}
@Provides @LazySingleton
public ConfigurationObjectFactory makeFactory(Properties props)
public final ConfigurationObjectFactory makeFactory(Properties props)
{
return Config.createFactory(props);
}

View File

@ -39,13 +39,13 @@ public class JacksonModule implements Module
}
@Provides @LazySingleton @Json
public ObjectMapper jsonMapper()
public final ObjectMapper jsonMapper()
{
return new DefaultObjectMapper();
}
@Provides @LazySingleton @Smile
public ObjectMapper smileMapper()
public final ObjectMapper smileMapper()
{
final SmileFactory smileFactory = new SmileFactory();
smileFactory.configure(SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT, false);

View File

@ -52,7 +52,7 @@ public class MetadataStorageTablesConfigTest
@Provides
@LazySingleton
public ObjectMapper jsonMapper()
public final ObjectMapper jsonMapper()
{
return new DefaultObjectMapper();
}

View File

@ -45,7 +45,7 @@ public class CuratorModule implements Module
}
@Provides @LazySingleton
public CuratorFramework makeCurator(CuratorConfig config, Lifecycle lifecycle) throws IOException
public final CuratorFramework makeCurator(CuratorConfig config, Lifecycle lifecycle) throws IOException
{
final CuratorFramework framework =
CuratorFrameworkFactory.builder()

View File

@ -145,7 +145,7 @@ public class DiscoveryModule implements Module
@Provides
@LazySingleton
@Named(NAME)
public CuratorServiceAnnouncer getServiceAnnouncer(
public final CuratorServiceAnnouncer getServiceAnnouncer(
final CuratorServiceAnnouncer announcer,
final Injector injector,
final Set<KeyHolder<DruidNode>> nodesToAnnounce,
@ -190,7 +190,7 @@ public class DiscoveryModule implements Module
@Provides
@LazySingleton
public ServiceDiscovery<Void> getServiceDiscovery(
public final ServiceDiscovery<Void> getServiceDiscovery(
CuratorFramework curator,
CuratorDiscoveryConfig config,
Lifecycle lifecycle
@ -233,7 +233,7 @@ public class DiscoveryModule implements Module
@Provides
@LazySingleton
public ServerDiscoveryFactory getServerDiscoveryFactory(
public final ServerDiscoveryFactory getServerDiscoveryFactory(
ServiceDiscovery<Void> serviceDiscovery
)
{

View File

@ -38,14 +38,14 @@ public class AWSModule implements Module
@Provides
@LazySingleton
public AWSCredentialsProvider getAWSCredentialsProvider(final AWSCredentialsConfig config)
public final AWSCredentialsProvider getAWSCredentialsProvider(final AWSCredentialsConfig config)
{
return AWSCredentialsUtils.defaultAWSCredentialsProviderChain(config);
}
@Provides
@LazySingleton
public AmazonEC2 getEc2Client(AWSCredentialsProvider credentials)
public final AmazonEC2 getEc2Client(AWSCredentialsProvider credentials)
{
return new AmazonEC2Client(credentials);
}

View File

@ -45,7 +45,7 @@ public class AnnouncerModule implements Module
@Provides
@ManageLifecycle
public Announcer getAnnouncer(CuratorFramework curator)
public final Announcer getAnnouncer(CuratorFramework curator)
{
return new Announcer(curator, Execs.singleThreaded("Announcer-%s"));
}

View File

@ -60,7 +60,7 @@ public class DruidProcessingModule implements Module
@Provides
@BackgroundCaching
@LazySingleton
public ExecutorService getBackgroundExecutorService(
public final ExecutorService getBackgroundExecutorService(
CacheConfig cacheConfig
)
{
@ -81,7 +81,7 @@ public class DruidProcessingModule implements Module
@Provides
@Processing
@ManageLifecycle
public ExecutorService getProcessingExecutorService(
public final ExecutorService getProcessingExecutorService(
ExecutorServiceConfig config,
ServiceEmitter emitter,
Lifecycle lifecycle
@ -100,7 +100,7 @@ public class DruidProcessingModule implements Module
@Provides
@LazySingleton
@Global
public StupidPool<ByteBuffer> getIntermediateResultsPool(DruidProcessingConfig config)
public final StupidPool<ByteBuffer> getIntermediateResultsPool(DruidProcessingConfig config)
{
try {
long maxDirectMemory = VMUtils.getMaxDirectMemory();

View File

@ -38,7 +38,7 @@ public class IndexingServiceDiscoveryModule implements Module
@Provides
@IndexingService
@ManageLifecycle
public ServerDiscoverySelector getServiceProvider(
public final ServerDiscoverySelector getServiceProvider(
IndexingServiceSelectorConfig config,
ServerDiscoveryFactory serverDiscoveryFactory
)

View File

@ -48,7 +48,7 @@ public class ServerModule implements DruidModule
}
@Provides @LazySingleton
public ScheduledExecutorFactory getScheduledExecutorFactory(Lifecycle lifecycle)
public final ScheduledExecutorFactory getScheduledExecutorFactory(Lifecycle lifecycle)
{
return ScheduledExecutors.createFactory(lifecycle);
}

View File

@ -57,7 +57,7 @@ public class StorageNodeModule implements Module
@Provides
@LazySingleton
public DruidServerMetadata getMetadata(@Self DruidNode node, @Nullable NodeTypeConfig nodeType, DruidServerConfig config)
public final DruidServerMetadata getMetadata(@Self DruidNode node, @Nullable NodeTypeConfig nodeType, DruidServerConfig config)
{
if (nodeType == null) {
throw new ProvisionException("Must override the binding for NodeTypeConfig if you want a DruidServerMetadata.");

View File

@ -74,7 +74,7 @@ public class EmitterModule implements Module
@Provides
@ManageLifecycle
public ServiceEmitter getServiceEmitter(@Self Supplier<DruidNode> configSupplier, Emitter emitter)
public final ServiceEmitter getServiceEmitter(@Self Supplier<DruidNode> configSupplier, Emitter emitter)
{
final DruidNode config = configSupplier.get();
final ServiceEmitter retVal = new ServiceEmitter(config.getServiceName(), config.getHostAndPort(), emitter);

View File

@ -60,7 +60,7 @@ public class HttpEmitterModule implements Module
@Provides
@ManageLifecycle
@Named("http")
public Emitter getEmitter(
public final Emitter getEmitter(
Supplier<HttpEmitterConfig> config,
@Nullable SSLContext sslContext,
Lifecycle lifecycle,

View File

@ -42,7 +42,7 @@ public class LogEmitterModule implements Module
}
@Provides @ManageLifecycle @Named(EMITTER_TYPE)
public Emitter makeEmitter(Supplier<LoggingEmitterConfig> config, ObjectMapper jsonMapper)
public final Emitter makeEmitter(Supplier<LoggingEmitterConfig> config, ObjectMapper jsonMapper)
{
return new LoggingEmitter(config.get(), jsonMapper);
}

View File

@ -39,7 +39,7 @@ public class NoopEmitterModule implements Module
@Provides
@ManageLifecycle
@Named(EMITTER_TYPE)
public Emitter makeEmitter()
public final Emitter makeEmitter()
{
return new NoopEmitter();
}

View File

@ -106,7 +106,7 @@ public class JettyServerModule extends JerseyServletModule
@Provides
@LazySingleton
public Server getServer(Injector injector, Lifecycle lifecycle, @Self DruidNode node, ServerConfig config)
public final Server getServer(Injector injector, Lifecycle lifecycle, @Self DruidNode node, ServerConfig config)
{
JettyServerInitializer initializer = injector.getInstance(JettyServerInitializer.class);
@ -145,7 +145,7 @@ public class JettyServerModule extends JerseyServletModule
@Provides
@Singleton
public JacksonJsonProvider getJacksonJsonProvider(@Json ObjectMapper objectMapper)
public final JacksonJsonProvider getJacksonJsonProvider(@Json ObjectMapper objectMapper)
{
final JacksonJsonProvider provider = new JacksonJsonProvider();
provider.setMapper(objectMapper);

View File

@ -67,7 +67,7 @@ public class MetricsModule implements Module
@Provides
@ManageLifecycle
public MonitorScheduler getMonitorScheduler(
public final MonitorScheduler getMonitorScheduler(
Supplier<DruidMonitorSchedulerConfig> config,
MonitorsConfig monitorsConfig,
Set<Class<? extends Monitor>> monitorSet,

View File

@ -118,7 +118,7 @@ public class CliBridge extends ServerRunnable
@Provides
@LazySingleton
@Bridge
public CuratorFramework getBridgeCurator(final BridgeCuratorConfig bridgeCuratorConfig, Lifecycle lifecycle)
public final CuratorFramework getBridgeCurator(final BridgeCuratorConfig bridgeCuratorConfig, Lifecycle lifecycle)
{
final CuratorFramework framework =
CuratorFrameworkFactory.builder()
@ -156,7 +156,7 @@ public class CliBridge extends ServerRunnable
@Provides
@ManageLifecycle
public ServerDiscoverySelector getServerDiscoverySelector(
public final ServerDiscoverySelector getServerDiscoverySelector(
DruidClusterBridgeConfig config,
ServerDiscoveryFactory factory
@ -168,7 +168,7 @@ public class CliBridge extends ServerRunnable
@Provides
@ManageLifecycle
@Bridge
public Announcer getBridgeAnnouncer(
public final Announcer getBridgeAnnouncer(
@Bridge CuratorFramework curator
)
{
@ -178,7 +178,7 @@ public class CliBridge extends ServerRunnable
@Provides
@ManageLifecycleLast
@Bridge
public AbstractDataSegmentAnnouncer getBridgeDataSegmentAnnouncer(
public final AbstractDataSegmentAnnouncer getBridgeDataSegmentAnnouncer(
DruidServerMetadata metadata,
BatchDataSegmentAnnouncerConfig config,
ZkPathsConfig zkPathsConfig,

View File

@ -138,7 +138,7 @@ public class CliCoordinator extends ServerRunnable
@Provides
@LazySingleton
public LoadQueueTaskMaster getLoadQueueTaskMaster(
public final LoadQueueTaskMaster getLoadQueueTaskMaster(
CuratorFramework curator,
ObjectMapper jsonMapper,
ScheduledExecutorFactory factory,

View File

@ -99,7 +99,7 @@ public class CliMiddleManager extends ServerRunnable
@Provides
@LazySingleton
public Worker getWorker(@Self DruidNode node, WorkerConfig config)
public final Worker getWorker(@Self DruidNode node, WorkerConfig config)
{
return new Worker(
node.getHostAndPort(),

View File

@ -93,7 +93,7 @@ public class CliRouter extends ServerRunnable
@Provides
@ManageLifecycle
public ServerDiscoverySelector getCoordinatorServerDiscoverySelector(
public final ServerDiscoverySelector getCoordinatorServerDiscoverySelector(
TieredBrokerConfig config,
ServerDiscoveryFactory factory