From ce8e1028c8d11baabd2ae2263c4e458061b6deb2 Mon Sep 17 00:00:00 2001 From: Eran Landau Date: Sat, 28 May 2016 17:04:55 -0700 Subject: [PATCH] Remove a bunch of classes that are no longer in use at Netflix. --- .../governator/guice/main/Arguments.java | 0 .../com/netflix/governator/Governator.java | 309 ------------------ .../netflix/governator/GovernatorTest.java | 51 --- .../governator/LifecycleModuleTest.java | 118 ------- .../ProvisionMetricsModuleTest.java | 7 +- .../JettyGuiceContextListenerExample.java | 8 +- .../netflix/governator/guice/AutoBinds.java | 35 -- .../governator/guice/BootstrapBinder.java | 34 +- .../governator/guice/BootstrapModule.java | 2 + .../DelegatingLifecycleInjectorBuilder.java | 21 -- .../guice/InternalBootstrapModule.java | 6 +- .../governator/guice/LifecycleInjector.java | 38 +-- .../guice/LifecycleInjectorBuilder.java | 35 +- .../guice/LifecycleInjectorBuilderImpl.java | 38 --- .../governator/guice/ModuleTransformer.java | 16 - .../netflix/governator/guice/ModulesEx.java | 110 ------- .../guice/actions/GrapherAction.java | 23 -- .../actions/LifecycleManagerStarter.java | 21 -- .../guice/annotations/Bootstrap.java | 5 + .../annotations/GovernatorConfiguration.java | 17 +- .../guice/bootstrap/GovernatorBootstrap.java | 9 - .../governator/guice/main/BootstrapMain.java | 57 ---- .../guice/runner/LifecycleRunner.java | 23 -- .../guice/runner/TerminationEvent.java | 29 -- .../events/BlockingTerminationEvent.java | 33 -- .../SelfDestructingTerminationEvent.java | 23 -- .../standalone/StandaloneRunnerModule.java | 181 ---------- .../OverrideAllDuplicateBindings.java | 35 -- .../transformer/StripStaticInjections.java | 36 -- .../WarnAboutStaticInjections.java | 32 -- .../com/netflix/governator/BootstrapTest.java | 83 ----- .../governator/autobind/TestAutoBind.java | 23 +- .../guice/TestPostInjectAction.java | 161 --------- .../guice/TestStandaloneApplication.java | 97 ------ .../OverrideAllDuplicateBindingsTest.java | 60 ---- 35 files changed, 50 insertions(+), 1726 deletions(-) rename {governator-legacy => governator-commons-cli}/src/main/java/com/netflix/governator/guice/main/Arguments.java (100%) delete mode 100644 governator-core/src/main/java/com/netflix/governator/Governator.java delete mode 100644 governator-core/src/test/java/com/netflix/governator/GovernatorTest.java delete mode 100644 governator-core/src/test/java/com/netflix/governator/LifecycleModuleTest.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/AutoBinds.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/ModuleTransformer.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/ModulesEx.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/actions/GrapherAction.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/actions/LifecycleManagerStarter.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/main/BootstrapMain.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/runner/LifecycleRunner.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/runner/TerminationEvent.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/runner/events/BlockingTerminationEvent.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/runner/events/SelfDestructingTerminationEvent.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/runner/standalone/StandaloneRunnerModule.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/transformer/OverrideAllDuplicateBindings.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/transformer/StripStaticInjections.java delete mode 100644 governator-legacy/src/main/java/com/netflix/governator/guice/transformer/WarnAboutStaticInjections.java delete mode 100644 governator-legacy/src/test/java/com/netflix/governator/BootstrapTest.java delete mode 100644 governator-legacy/src/test/java/com/netflix/governator/guice/TestPostInjectAction.java delete mode 100644 governator-legacy/src/test/java/com/netflix/governator/guice/TestStandaloneApplication.java delete mode 100644 governator-legacy/src/test/java/com/netflix/governator/guice/transformer/OverrideAllDuplicateBindingsTest.java diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/main/Arguments.java b/governator-commons-cli/src/main/java/com/netflix/governator/guice/main/Arguments.java similarity index 100% rename from governator-legacy/src/main/java/com/netflix/governator/guice/main/Arguments.java rename to governator-commons-cli/src/main/java/com/netflix/governator/guice/main/Arguments.java diff --git a/governator-core/src/main/java/com/netflix/governator/Governator.java b/governator-core/src/main/java/com/netflix/governator/Governator.java deleted file mode 100644 index 53d4f0c8..00000000 --- a/governator-core/src/main/java/com/netflix/governator/Governator.java +++ /dev/null @@ -1,309 +0,0 @@ -package com.netflix.governator; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.IdentityHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import com.google.inject.Module; -import com.google.inject.util.Modules; -import com.netflix.governator.annotations.SuppressLifecycleUninitialized; -import com.netflix.governator.internal.DefaultPropertySource; -import com.netflix.governator.internal.GovernatorFeatureSet; -import com.netflix.governator.internal.ModulesEx; -import com.netflix.governator.spi.ModuleListTransformer; -import com.netflix.governator.spi.ModuleTransformer; -import com.netflix.governator.spi.PropertySource; -import com.netflix.governator.spi.LifecycleListener; - -/** - * Main entry point for creating a LifecycleInjector with guice extensions such as - * support for @PostConstruct, @PreDestroy annotations and LifecycleListener. - * - * Example: - * - new Governator() - .addModules( - new ArchaiusGovernatorModule(), - new JettyModule(), - new JerseyServletModule() { - {@literal @}@Override - protected void configureServlets() { - serve("/*").with(GuiceContainer.class); - - bind(GuiceContainer.class).asEagerSingleton(); - bind(HelloWorldApp.class).asEagerSingleton(); - } - } - ) - .run() - .awaitTermination(); - * - * - * @deprecated 2015-12-13 Use {@link InjectorBuilder} instead - */ -@Deprecated -public class Governator { - protected Set profiles = new LinkedHashSet<>(); - protected List modules = new ArrayList<>(); - protected List transformers = new ArrayList<>(); - protected List overrideModules = new ArrayList<>(); - protected IdentityHashMap, Object> featureOverrides = new IdentityHashMap<>(); - - // This is a hack to make sure that if archaius is used at some point we make use - // of the bridge so any access to the legacy Archaius1 API is actually backed by - // the Archaius2 implementation - static { - System.setProperty("archaius.default.configuration.class", "com.netflix.archaius.bridge.StaticAbstractConfiguration"); - System.setProperty("archaius.default.deploymentContext.class", "com.netflix.archaius.bridge.StaticDeploymentContext"); - } - - @Singleton - @SuppressLifecycleUninitialized - class GovernatorFeatureSetImpl implements GovernatorFeatureSet { - private final IdentityHashMap, Object> featureOverrides; - - @Inject - private PropertySource properties = new DefaultPropertySource(); - - @Inject - public GovernatorFeatureSetImpl(IdentityHashMap, Object> featureOverrides) { - this.featureOverrides = featureOverrides; - } - - @SuppressWarnings("unchecked") - @Override - public T get(GovernatorFeature feature) { - return featureOverrides.containsKey(feature) - ? (T) featureOverrides.get(feature) - : (T) properties.get(feature.getKey(), feature.getType(), feature.getDefaultValue()); - } - } - - /** - * Add Guice modules to Governator. - * - * @param modules Guice modules to add. - * @return this - */ - public Governator addModules(Module ... modules) { - if (modules != null) { - this.modules.addAll(Arrays.asList(modules)); - } - return this; - } - - /** - * Add Guice modules to Governator. - * - * @param modules Guice modules to add. - * @return this - */ - public Governator addModules(List modules) { - if (modules != null) { - this.modules.addAll(modules); - } - return this; - } - - /** - * Add a runtime profile. Profiles are processed by the conditional binding {@literal @}ConditionalOnProfile and - * are injectable as {@literal @}Profiles Set{@literal <}String{@literal >}. - * - * @param profile A profile - * @return this - */ - public Governator addProfile(String profile) { - if (profile != null) { - this.profiles.add(profile); - } - return this; - } - - /** - * Add a runtime profiles. Profiles are processed by the conditional binding {@literal @}ConditionalOnProfile and - * are injectable as {@literal @}Profiles Set{@literal <}String{@literal >}. - * - * @param profiles Set of profiles - * @return this - */ - public Governator addProfiles(String... profiles) { - if (profiles != null) { - this.profiles.addAll(Arrays.asList(profiles)); - } - return this; - } - - /** - * Add a runtime profiles. Profiles are processed by the conditional binding {@literal @}ConditionalOnProfile and - * are injectable as {@literal @}Profiles Set{@literal <}String{@literal >}. - * - * @param profiles Set of profiles - * @return this - */ - public Governator addProfiles(Collection profiles) { - if (profiles != null) { - this.profiles.addAll(profiles); - } - return this; - } - - /** - * Enable the specified feature - * @param feature Boolean feature to enable - * @return this - */ - public Governator enableFeature(GovernatorFeature feature) { - return setFeature(feature, true); - } - - /** - * Enable or disable the specified feature - * @param feature Boolean feature to disable - * @return this - */ - public Governator enableFeature(GovernatorFeature feature, boolean enabled) { - return setFeature(feature, enabled); - } - - /** - * Disable the specified feature - * @param feature Boolean feature to enable/disable - * @return this - */ - public Governator disableFeature(GovernatorFeature feature) { - return setFeature(feature, false); - } - - /** - * Set a feature - * @param feature Feature to set - * @return this - */ - public Governator setFeature(GovernatorFeature feature, T value) { - this.featureOverrides.put(feature, value); - return this; - } - - /** - * Add a ModuleListTransformer that will be invoked on the final list of modules - * prior to creating the injectors. Multiple transformers may be added with each - * transforming the result of the previous one. - * - * @param transformer A transformer - * @return this - */ - public Governator addModuleListTransformer(ModuleListTransformer transformer) { - if (transformer != null) { - this.transformers.add(transformer); - } - return this; - } - - /** - * Add override modules for any modules add via addModules or that are - * conditionally loaded. This is useful for testing or when an application - * absolutely needs to override a binding to fix a binding problem in the - * code modules - * @param modules Modules that will be applied as overrides to modules - * @return this - */ - public Governator addOverrideModules(Module ... modules) { - if (modules != null) { - this.overrideModules.addAll(Arrays.asList(modules)); - } - return this; - } - - /** - * Add override modules for any modules add via addModules or that are - * conditionally loaded. This is useful for testing or when an application - * absolutely needs to override a binding to fix a binding problem in the - * code modules - * @param modules Modules that will be applied as overrides to modules - * @return this - */ - public Governator addOverrideModules(List modules) { - if (modules != null) { - this.overrideModules.addAll(modules); - } - return this; - } - - /** - * @deprecated Call new Governator().addModules(modules).run() instead. - */ - @Deprecated - public LifecycleInjector createInjector(Module ... modules) { - return new Governator().addModules(modules).run(); - } - - /** - * @deprecated Call new Governator().addModules(modules).run() instead. - */ - public LifecycleInjector createInjector(Collection modules) { - return new Governator().addModules(new ArrayList(modules)).run(); - } - - /** - * Create the injector and call any LifecycleListeners - * @return the LifecycleInjector for this run - */ - public LifecycleInjector run() { - return run(ModulesEx.emptyModule(), new String[]{}); - } - - public LifecycleInjector run(final String[] args) { - return run(ModulesEx.emptyModule(), args); - } - - public LifecycleInjector run(final Class mainClass) { - return run(mainClass, new String[]{}); - } - - public LifecycleInjector run(LifecycleListener mainClass) { - return run(ModulesEx.fromInstance(mainClass), new String[]{}); - } - - public LifecycleInjector run(LifecycleListener mainClass, final String[] args) { - return run(ModulesEx.fromInstance(mainClass), args); - } - - public LifecycleInjector run(final Class mainClass, final String[] args) { - return run(ModulesEx.fromEagerSingleton(mainClass), args); - } - - /** - * Create the injector and call any LifecycleListeners - * @param args - Runtime parameter (from main) injectable as {@literal @}Arguments String[] - * @return the LifecycleInjector for this run - */ - private LifecycleInjector run(Module externalModule, final String[] args) { - return InjectorBuilder - .fromModules(modules) - .combineWith(externalModule) - .map(new ModuleTransformer() { - @Override - public Module transform(Module module) { - List modulesToTransform = Collections.singletonList(module); - for (ModuleListTransformer transformer : transformers) { - modulesToTransform = transformer.transform(Collections.unmodifiableList(modulesToTransform)); - } - - return Modules.combine(modulesToTransform); - } - }) - .overrideWith(overrideModules) - .createInjector(new LifecycleInjectorCreator() - .withArguments(args) - .withFeatures(featureOverrides) - .withProfiles(profiles)); - } -} diff --git a/governator-core/src/test/java/com/netflix/governator/GovernatorTest.java b/governator-core/src/test/java/com/netflix/governator/GovernatorTest.java deleted file mode 100644 index 02a7e09c..00000000 --- a/governator-core/src/test/java/com/netflix/governator/GovernatorTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.netflix.governator; - -import java.util.concurrent.atomic.AtomicBoolean; - -import junit.framework.Assert; - -import org.junit.Test; - -import com.google.inject.AbstractModule; -import com.netflix.governator.spi.LifecycleListener; - -public class GovernatorTest { - @Test - public void testSimpleExecution() { - final AtomicBoolean isStopped = new AtomicBoolean(); - final AtomicBoolean isStarted = new AtomicBoolean(); - LifecycleInjector injector = new Governator() - .addModules(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).toInstance("foo"); - } - }) - .run(new LifecycleListener() { - @Override - public void onStarted() { - isStarted.set(true); - } - - @Override - public void onStopped(Throwable error) { - isStopped.set(true); - } - - @Override - public String toString() { - return "UnitTest[]"; - } - }); - - try { - Assert.assertTrue(isStarted.get()); - Assert.assertFalse(isStopped.get()); - Assert.assertEquals("foo", injector.getInstance(String.class)); - } - finally { - injector.shutdown(); - } - Assert.assertTrue(isStopped.get()); - } -} diff --git a/governator-core/src/test/java/com/netflix/governator/LifecycleModuleTest.java b/governator-core/src/test/java/com/netflix/governator/LifecycleModuleTest.java deleted file mode 100644 index 1ea9f8c9..00000000 --- a/governator-core/src/test/java/com/netflix/governator/LifecycleModuleTest.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.netflix.governator; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; - -import com.google.inject.Injector; -import com.netflix.governator.spi.LifecycleListener; - -public class LifecycleModuleTest { - - private static enum Events { - Injected, - Initialized, - Destroyed, - Started, - Stopped, - Error - } - - @Rule - public final TestName name = new TestName(); - - class TrackingLifecycleListener implements LifecycleListener { - final List events = new ArrayList<>(); - - @Inject - public void initialize(Injector injector) { - events.add(Events.Injected); - } - - @PostConstruct - public void initialized() { - events.add(Events.Initialized); - } - - @PreDestroy - public void destroyed() { - events.add(Events.Destroyed); - } - - @Override - public void onStarted() { - events.add(Events.Started); - } - - @Override - public void onStopped(Throwable t) { - events.add(Events.Stopped); - if (t != null) { - events.add(Events.Error); - } - } - - @Override - public String toString() { - return "TrackingLifecycleListener[" + name.getMethodName() + "]"; - } - } - - @Test - public void confirmLifecycleListenerEventsForSuccessfulStart() { - final TrackingLifecycleListener listener = new TrackingLifecycleListener(); - - new Governator() - .run(listener) - .shutdown(); - - assertThat(listener.events, equalTo(Arrays.asList(Events.Injected, Events.Initialized, Events.Started, Events.Destroyed, Events.Stopped))); - } - - @Test(expected=RuntimeException.class) - public void confirmLifecycleListenerEventsForFailedStart() { - final TrackingLifecycleListener listener = new TrackingLifecycleListener() { - @Override - @Inject - public void initialize(Injector injector) { - super.initialize(injector); - throw new RuntimeException("Failed"); - } - }; - - try { - new Governator() - .run(listener) - .shutdown(); - } - finally { - assertThat(listener.events, equalTo(Arrays.asList(Events.Injected, Events.Initialized, Events.Stopped, Events.Error, Events.Destroyed))); - } - } - - @Test(expected=AssertionError.class) - public void assertionExampleInListener() { - new Governator() - .run(new TrackingLifecycleListener() { - @Override - public void onStopped(Throwable t) { - super.onStopped(t); - assertThat(t, nullValue()); - assertThat(false, equalTo(true)); - } - }) - .shutdown(); - } -} diff --git a/governator-core/src/test/java/com/netflix/governator/ProvisionMetricsModuleTest.java b/governator-core/src/test/java/com/netflix/governator/ProvisionMetricsModuleTest.java index 214d9ff4..e91e81de 100644 --- a/governator-core/src/test/java/com/netflix/governator/ProvisionMetricsModuleTest.java +++ b/governator-core/src/test/java/com/netflix/governator/ProvisionMetricsModuleTest.java @@ -6,7 +6,7 @@ public class ProvisionMetricsModuleTest { @Test public void defaultMetricsAreEmpty() { - LifecycleInjector injector = new Governator().run(); + LifecycleInjector injector = InjectorBuilder.fromModules().createInjector(); try { ProvisionMetrics metrics = injector.getInstance(ProvisionMetrics.class); LoggingProvisionMetricsVisitor visitor = new LoggingProvisionMetricsVisitor(); @@ -20,9 +20,8 @@ public void defaultMetricsAreEmpty() { @Test public void installedMetricsHaveData() { - LifecycleInjector injector = new Governator() - .addModules(new ProvisionMetricsModule()) - .run(); + LifecycleInjector injector = InjectorBuilder.fromModules(new ProvisionMetricsModule()) + .createInjector(); try { ProvisionMetrics metrics = injector.getInstance(ProvisionMetrics.class); diff --git a/governator-jetty/src/test/java/com/netflix/governator/guice/jetty/JettyGuiceContextListenerExample.java b/governator-jetty/src/test/java/com/netflix/governator/guice/jetty/JettyGuiceContextListenerExample.java index 31ad3971..aa70ede1 100644 --- a/governator-jetty/src/test/java/com/netflix/governator/guice/jetty/JettyGuiceContextListenerExample.java +++ b/governator-jetty/src/test/java/com/netflix/governator/guice/jetty/JettyGuiceContextListenerExample.java @@ -1,17 +1,15 @@ package com.netflix.governator.guice.jetty; -import com.netflix.governator.Governator; +import com.netflix.governator.InjectorBuilder; import com.netflix.governator.ShutdownHookModule; -import com.netflix.governator.guice.jetty.JettyModule; public class JettyGuiceContextListenerExample { public static void main(String args[]) throws Exception { - new Governator() - .addModules( + InjectorBuilder.fromModules( new SampleServletModule(), new ShutdownHookModule(), new JettyModule()) - .run() + .createInjector() .awaitTermination(); } } diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/AutoBinds.java b/governator-legacy/src/main/java/com/netflix/governator/guice/AutoBinds.java deleted file mode 100644 index 507593f7..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/AutoBinds.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2013 Netflix, 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.netflix.governator.guice; - -import com.netflix.governator.annotations.AutoBind; - -/** - * Used to build an {@link AutoBind} instance. Normally you won't - * use this directly. - */ -public class AutoBinds -{ - public static AutoBind withValue(String value) - { - return new AutoBindImpl(value); - } - - private AutoBinds() - { - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/BootstrapBinder.java b/governator-legacy/src/main/java/com/netflix/governator/guice/BootstrapBinder.java index 23bffaf1..c2e7be2e 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/BootstrapBinder.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/BootstrapBinder.java @@ -16,14 +16,6 @@ package com.netflix.governator.guice; -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.Collection; - -import org.aopalliance.intercept.MethodInterceptor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.collect.Lists; import com.google.inject.Binder; import com.google.inject.Binding; @@ -50,6 +42,15 @@ import com.netflix.governator.lifecycle.LifecycleListener; import com.netflix.governator.lifecycle.ResourceLocator; +import org.aopalliance.intercept.MethodInterceptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.Collection; + +@Deprecated public class BootstrapBinder implements Binder { private final Logger log = LoggerFactory.getLogger(getClass()); @@ -59,23 +60,18 @@ public class BootstrapBinder implements Binder private ModuleListBuilder modules; private boolean disableAutoBinding; - BootstrapBinder(Binder binder, Stage stage, LifecycleInjectorMode mode, ModuleListBuilder modules, Collection actions, Collection transformers, boolean disableAutoBinding) + BootstrapBinder(Binder binder, Stage stage, LifecycleInjectorMode mode, ModuleListBuilder modules, Collection actions, boolean disableAutoBinding) { this.binder = binder; this.mode = mode; this.stage = stage; this.modules = modules; - Multibinder transformerBinder = Multibinder.newSetBinder(binder, ModuleTransformer.class); Multibinder actionBinder = Multibinder.newSetBinder(binder, PostInjectorAction.class); for (PostInjectorAction action : actions) { actionBinder.addBinding().toInstance(action); } - - for (ModuleTransformer transformer : transformers) { - transformerBinder.addBinding().toInstance(transformer); - } } private String getBindingLocation() { @@ -110,16 +106,6 @@ public LinkedBindingBuilder bindPostInjectorAction() return Multibinder.newSetBinder(binder, PostInjectorAction.class).addBinding(); } - /** - * Bind module transform operations to perform on the final list of modul. - * - * @return a binding builder used to add a new element in the set. - */ - public LinkedBindingBuilder bindModuleTransformer() - { - return Multibinder.newSetBinder(binder, ModuleTransformer.class).addBinding(); - } - /** * Use this to bind a {@link LifecycleListener}. It internally uses a Multibinder to do the * binding so that you can bind multiple LifecycleListeners diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/BootstrapModule.java b/governator-legacy/src/main/java/com/netflix/governator/guice/BootstrapModule.java index 3abbb93e..3e65da11 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/BootstrapModule.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/BootstrapModule.java @@ -18,7 +18,9 @@ /** * Abstraction for binding during the bootstrap phase + * @deprecated Use standard Guice modules instead */ +@Deprecated public interface BootstrapModule { /** diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/DelegatingLifecycleInjectorBuilder.java b/governator-legacy/src/main/java/com/netflix/governator/guice/DelegatingLifecycleInjectorBuilder.java index 0ce5af32..c593c983 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/DelegatingLifecycleInjectorBuilder.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/DelegatingLifecycleInjectorBuilder.java @@ -154,27 +154,6 @@ public LifecycleInjectorBuilder withMode(LifecycleInjectorMode mode) { return this; } - @Override - public LifecycleInjectorBuilder withModuleTransformer( - ModuleTransformer transformer) { - this.delegate = delegate.withModuleTransformer(transformer); - return this; - } - - @Override - public LifecycleInjectorBuilder withModuleTransformer( - Collection transformers) { - this.delegate = delegate.withModuleTransformer(transformers); - return this; - } - - @Override - public LifecycleInjectorBuilder withModuleTransformer( - ModuleTransformer... transformers) { - this.delegate = delegate.withModuleTransformer(transformers); - return this; - } - @Override public LifecycleInjectorBuilder withPostInjectorAction( PostInjectorAction action) { diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/InternalBootstrapModule.java b/governator-legacy/src/main/java/com/netflix/governator/guice/InternalBootstrapModule.java index 281eecce..b705f484 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/InternalBootstrapModule.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/InternalBootstrapModule.java @@ -45,7 +45,6 @@ class InternalBootstrapModule extends AbstractModule private LifecycleInjectorMode mode; private ModuleListBuilder modules; private Collection actions; - private Collection transformers; private boolean disableAutoBinding; private final Collection bootstrapModules; @@ -61,13 +60,12 @@ public LifecycleConfigurationProviders get() } } - public InternalBootstrapModule(Collection bootstrapModules, ClasspathScanner scanner, Stage stage, LifecycleInjectorMode mode, ModuleListBuilder modules, Collection actions, Collection transformers, boolean disableAutoBinding) { + public InternalBootstrapModule(Collection bootstrapModules, ClasspathScanner scanner, Stage stage, LifecycleInjectorMode mode, ModuleListBuilder modules, Collection actions, boolean disableAutoBinding) { this.scanner = scanner; this.stage = stage; this.mode = mode; this.modules = modules; this.actions = actions; - this.transformers = transformers; this.bootstrapModules = bootstrapModules; this.disableAutoBinding = disableAutoBinding; } @@ -85,7 +83,7 @@ protected void configure() bindScope(LazySingleton.class, LazySingletonScope.get()); bindScope(FineGrainedLazySingleton.class, FineGrainedLazySingletonScope.get()); - bootstrapBinder = new BootstrapBinder(binder(), stage, mode, modules, actions, transformers, disableAutoBinding); + bootstrapBinder = new BootstrapBinder(binder(), stage, mode, modules, actions, disableAutoBinding); if ( bootstrapModules != null ) { diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjector.java b/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjector.java index 0197d6b1..2014333a 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjector.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjector.java @@ -16,22 +16,6 @@ package com.netflix.governator.guice; -import java.lang.annotation.Annotation; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; - -import javax.annotation.Resource; -import javax.annotation.Resources; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; @@ -60,6 +44,22 @@ import com.netflix.governator.lifecycle.ClasspathScanner; import com.netflix.governator.lifecycle.LifecycleManager; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.annotation.Annotation; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; + +import javax.annotation.Resource; +import javax.annotation.Resources; + /** *

* When using Governator, do NOT create a Guice injector manually. Instead, use a LifecycleInjector to create a Guice injector. @@ -91,7 +91,6 @@ public class LifecycleInjector private final Stage stage; private final LifecycleInjectorMode mode; private Set actions; - private Set transformers; /** * Create a new LifecycleInjector builder @@ -318,9 +317,6 @@ public Injector createChildInjector(Collection modules) Injector childInjector; Collection localModules = modules; - for (ModuleTransformer transformer : transformers) { - localModules = transformer.call(localModules); - } //noinspection deprecation if ( mode == LifecycleInjectorMode.REAL_CHILD_INJECTORS ) { @@ -417,7 +413,6 @@ public Injector createInjector(Collection additionalModules) builder.getLifecycleInjectorMode(), builder.getModuleListBuilder(), builder.getPostInjectorActions(), - builder.getModuleTransformers(), builder.isDisableAutoBinding()); injector = Guice.createInjector @@ -433,7 +428,6 @@ public Injector createInjector(Collection additionalModules) this.ignoreClasses = ImmutableList.copyOf(builder.getIgnoreClasses()); this.actions = injector.getInstance(Key.get(new TypeLiteral>() {})); - this.transformers = injector.getInstance(Key.get(new TypeLiteral>() {})); try { this.modules = internalBootstrapModule.getModuleListBuilder().build(injector); diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjectorBuilder.java b/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjectorBuilder.java index d4411b7c..1a5b6eac 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjectorBuilder.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjectorBuilder.java @@ -21,6 +21,7 @@ import com.google.inject.Stage; import com.netflix.governator.annotations.AutoBindSingleton; import com.netflix.governator.lifecycle.ClasspathScanner; + import java.util.Collection; /** @@ -109,6 +110,7 @@ public interface LifecycleInjectorBuilder * @param module root application module * @return this */ + @Deprecated public LifecycleInjectorBuilder withModuleClass(Class module); /** @@ -240,39 +242,6 @@ public interface LifecycleInjectorBuilder */ public LifecycleInjectorBuilder withMode(LifecycleInjectorMode mode); - /** - * Just before creating the injector all the modules will run through the transformer. - * Transformers will be executed in the order in which withModuleTransformer - * is called. Note that once the first filter is called subsequent calls will only be - * given the previous set of filtered modules. - * - * @param transformer - * @return this - */ - public LifecycleInjectorBuilder withModuleTransformer(ModuleTransformer transformer); - - /** - * Just before creating the injector all the modules will run through the filter. - * Transformers will be executed in the order in which withModuleTransformer - * is called. Note that once the first filter is called subsequent calls will only be - * given the previous set of filtered modules. - * - * @param transformer - * @return this - */ - public LifecycleInjectorBuilder withModuleTransformer(Collection transformer); - - /** - * Just before creating the injector all the modules will run through the filter. - * Transformers will be executed in the order in which withModuleTransformer - * is called. Note that once the first filter is called subsequent calls will only be - * given the previous set of filtered modules. - * - * @param transformer - * @return this - */ - public LifecycleInjectorBuilder withModuleTransformer(ModuleTransformer... transformer); - /** * Action to perform after the injector is created. Note that post injection actions * are performed in the same order as calls to withPostInjectorAction diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjectorBuilderImpl.java b/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjectorBuilderImpl.java index c47897d0..58d39257 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjectorBuilderImpl.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/LifecycleInjectorBuilderImpl.java @@ -41,7 +41,6 @@ class LifecycleInjectorBuilderImpl implements LifecycleInjectorBuilder @SuppressWarnings("deprecation") private LifecycleInjectorMode lifecycleInjectorMode = LifecycleInjectorMode.REAL_CHILD_INJECTORS; private List actions = ImmutableList.of(); - private List transformers = ImmutableList.of(); public LifecycleInjectorBuilder withBootstrapModule(BootstrapModule module) { @@ -236,39 +235,6 @@ public LifecycleInjectorBuilder inStage(Stage stage) return this; } - @Override - public LifecycleInjectorBuilder withModuleTransformer(ModuleTransformer filter) { - if (filter != null) { - this.transformers = ImmutableList.builder() - .addAll(this.transformers) - .add(filter) - .build(); - } - return this; - } - - @Override - public LifecycleInjectorBuilder withModuleTransformer(Collection filters) { - if (this.transformers != null) { - this.transformers = ImmutableList.builder() - .addAll(this.transformers) - .addAll(filters) - .build(); - } - return this; - } - - @Override - public LifecycleInjectorBuilder withModuleTransformer(ModuleTransformer... filters) { - if (this.transformers != null) { - this.transformers = ImmutableList.builder() - .addAll(this.transformers) - .addAll(ImmutableList.copyOf(filters)) - .build(); - } - return this; - } - @Override public LifecycleInjectorBuilder withPostInjectorAction(PostInjectorAction action) { this.actions = ImmutableList.builder() @@ -351,10 +317,6 @@ List getPostInjectorActions() { return actions; } - List getModuleTransformers() { - return transformers; - } - boolean isDisableAutoBinding() { return this.disableAutoBinding; } diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/ModuleTransformer.java b/governator-legacy/src/main/java/com/netflix/governator/guice/ModuleTransformer.java deleted file mode 100644 index 8c8b6176..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/ModuleTransformer.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.netflix.governator.guice; - -import java.util.Collection; - -import com.google.inject.Module; - -/** - * Before creating the injector the modules are passed through a collection - * of filters that can filter out or modify bindings - * - * @author elandau - * - */ -public interface ModuleTransformer { - public Collection call(Collection modules); -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/ModulesEx.java b/governator-legacy/src/main/java/com/netflix/governator/guice/ModulesEx.java deleted file mode 100644 index e827aa45..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/ModulesEx.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.netflix.governator.guice; - -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.inject.Module; -import com.google.inject.util.Modules; -import com.netflix.governator.guice.annotations.Bootstrap; - -/** - * Utility class similar to Guice's Modules that simplifies recipes for - * combing Guice modules. - * - * @author elandau - * - */ -public class ModulesEx { - private static final Logger LOG = LoggerFactory.getLogger(ModulesEx.class); - - public static Module combineAndOverride(Module ... modules) { - return combineAndOverride(Arrays.asList(modules)); - } - - /** - * Generate a single module that is produced by accumulating and overriding - * each module with the next. - * - *

-     * {@code 
-     * Guice.createInjector(ModuleUtils.combineAndOverride(moduleA, moduleAOverrides, moduleB));
-     * }
-     * 
- * - * @param modules - * @return - */ - public static Module combineAndOverride(List modules) { - Iterator iter = modules.iterator(); - Module current = Modules.EMPTY_MODULE; - if (iter.hasNext()) { - current = iter.next(); - if (iter.hasNext()) { - current = Modules.override(current).with(iter.next()); - } - } - - return current; - } - - public static Module fromClass(final Class cls) { - return fromClass(cls, true); - } - - /** - * Create a single module that derived from all bootstrap annotations - * on a class, where that class itself is a module. - * - * For example, - *
-     * {@code 
-     *    public class MainApplicationModule extends AbstractModule {
-     *        @Override
-     *        public void configure() {
-     *            // Application specific bindings here
-     *        }
-     *        
-     *        public static void main(String[] args) {
-     *            Guice.createInjector(ModulesEx.fromClass(MainApplicationModule.class));
-     *        }
-     *    }
-     * }
-     * 
- * @author elandau - */ - public static Module fromClass(final Class cls, final boolean override) { - List modules = new ArrayList<>(); - // Iterate through all annotations of the main class, create a binding for the annotation - // and add the module to the list of modules to install - for (final Annotation annot : cls.getDeclaredAnnotations()) { - final Class type = annot.annotationType(); - Bootstrap bootstrap = type.getAnnotation(Bootstrap.class); - if (bootstrap != null) { - LOG.info("Adding Module {}", bootstrap.module()); - try { - modules.add(bootstrap.module().getConstructor(type).newInstance(annot)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - - try { - if (override) { - return Modules.override(combineAndOverride(modules)).with((Module)cls.newInstance()); - } - else { - return Modules.combine(Modules.combine(modules), (Module)cls.newInstance()); - } - } - catch (Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/actions/GrapherAction.java b/governator-legacy/src/main/java/com/netflix/governator/guice/actions/GrapherAction.java deleted file mode 100644 index 28194331..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/actions/GrapherAction.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.netflix.governator.guice.actions; - -import com.google.inject.Injector; -import com.netflix.governator.guice.Grapher; -import com.netflix.governator.guice.PostInjectorAction; - -public class GrapherAction implements PostInjectorAction { - private String text; - - @Override - public void call(Injector injector) { - Grapher grapher = injector.getInstance(Grapher.class); - try { - text = grapher.graph(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - public String getText() { - return text; - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/actions/LifecycleManagerStarter.java b/governator-legacy/src/main/java/com/netflix/governator/guice/actions/LifecycleManagerStarter.java deleted file mode 100644 index 5b2ad58d..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/actions/LifecycleManagerStarter.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.netflix.governator.guice.actions; - -import com.google.inject.Injector; -import com.netflix.governator.guice.PostInjectorAction; -import com.netflix.governator.lifecycle.LifecycleManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class LifecycleManagerStarter implements PostInjectorAction { - private static final Logger log = LoggerFactory.getLogger(LifecycleManagerStarter.class); - - @Override - public void call(Injector injector) { - LifecycleManager manager = injector.getInstance(LifecycleManager.class); - try { - manager.start(); - } catch (Exception e) { - log.error("Failed to start LifecycleManager", e); - } - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/annotations/Bootstrap.java b/governator-legacy/src/main/java/com/netflix/governator/guice/annotations/Bootstrap.java index e4981a8e..ae9a0391 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/annotations/Bootstrap.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/annotations/Bootstrap.java @@ -12,6 +12,11 @@ import com.netflix.governator.guice.LifecycleInjectorBuilder; import com.netflix.governator.guice.LifecycleInjectorBuilderSuite; +/** + * @deprecated 2016-05-26 All annotation based module loading APIs are being removed in favor of + * pure Guice and InjectoBuilder + */ +@Deprecated @Documented @Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/annotations/GovernatorConfiguration.java b/governator-legacy/src/main/java/com/netflix/governator/guice/annotations/GovernatorConfiguration.java index fb51159c..00246e64 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/annotations/GovernatorConfiguration.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/annotations/GovernatorConfiguration.java @@ -1,16 +1,15 @@ package com.netflix.governator.guice.annotations; -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - import com.google.inject.Stage; import com.netflix.governator.guice.LifecycleInjectorMode; -import com.netflix.governator.guice.ModuleTransformer; import com.netflix.governator.guice.PostInjectorAction; import com.netflix.governator.guice.bootstrap.GovernatorBootstrap; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + /** * Governator configuration for the main bootstrap class with 'good' default */ @@ -45,10 +44,4 @@ * @return */ Class[] actions() default {}; - - /** - * {@link ModuleTransform} operations to perform on the final list of modules - * @return - */ - Class[] transformers() default {}; } diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/bootstrap/GovernatorBootstrap.java b/governator-legacy/src/main/java/com/netflix/governator/guice/bootstrap/GovernatorBootstrap.java index 7d194dc7..81e457ce 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/bootstrap/GovernatorBootstrap.java +++ b/governator-legacy/src/main/java/com/netflix/governator/guice/bootstrap/GovernatorBootstrap.java @@ -4,7 +4,6 @@ import com.google.inject.ProvisionException; import com.netflix.governator.guice.BootstrapBinder; import com.netflix.governator.guice.BootstrapModule; -import com.netflix.governator.guice.ModuleTransformer; import com.netflix.governator.guice.PostInjectorAction; import com.netflix.governator.guice.annotations.GovernatorConfiguration; @@ -34,13 +33,5 @@ public void configure(BootstrapBinder binder) { throw new ProvisionException("Error creating postInjectorAction '" + action.getName() + "'", e); } } - - for (Class transformer : config.transformers()) { - try { - binder.bindModuleTransformer().to(transformer); - } catch (Exception e) { - throw new ProvisionException("Error creating postInjectorAction '" + transformer.getName() + "'", e); - } - } } } diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/main/BootstrapMain.java b/governator-legacy/src/main/java/com/netflix/governator/guice/main/BootstrapMain.java deleted file mode 100644 index 25e04018..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/main/BootstrapMain.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.netflix.governator.guice.main; - -import com.google.inject.AbstractModule; -import com.google.inject.ProvisionException; -import com.netflix.governator.guice.LifecycleInjector; - -/** - * Main class for loading a bootstrap configuration via main(). When running an application set - * this to the main class and set the first argument to the name of the bootstrap'd class. - * - * java BootstrapMain com.org.MyApplicationBootstrap ... - * - * Where, - * - *
- * {@code
- *  @GovernatorConfiguration
- *  public class MyApplicationBootstrap extends AbstractModule {
- *     public void configure() {
- *        // your application bindings here
- *     }
- *  }
- * }
- * 
- * - * Note that any component in your application can gain access to the command line arguments by injecting - * Arguments. Also, it is the responsibility of your application to parse the command line and manage - * the application lifecycle. In the future there may be governator subprojects for various cli parsing - * and command line processing libraries (such as apache commons cli) - * - *
- * {@code
- * @Singleton
- * public class MyApplication {
- *    @Inject
- *    MyApplication(Arguments args) {
- *    }
- * }
- * }
- * 
- * @author elandau - */ -public class BootstrapMain { - public static void main(final String args[]) { - try { - Class mainClass = Class.forName(args[0]); - LifecycleInjector.bootstrap(mainClass, new AbstractModule() { - @Override - protected void configure() { - bind(Arguments.class).toInstance(new Arguments(args)); - } - }); - } catch (Exception e) { - throw new ProvisionException("Error instantiating main class", e); - } - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/LifecycleRunner.java b/governator-legacy/src/main/java/com/netflix/governator/guice/runner/LifecycleRunner.java deleted file mode 100644 index a5b9d687..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/LifecycleRunner.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.netflix.governator.guice.runner; - -import com.netflix.governator.guice.runner.standalone.StandaloneRunnerModule; - -/** - * Abstraction defining the application runtime framework for an application using - * Governator. If a binding for ApplicationFramework exists Governator will - * create the instance of the ApplicationFramework immediately after creating - * the bootstrap module. It is the application framework's responsibility - * to call {@link com.netflix.governator.lifecycle.LifecycleManager LifecycleManager} - * start and stop as well as manage the application termination mechanism. - * - * A {@link StandaloneRunnerModule} is provided for simple command line - * applications. - * - * Additional LifecycleRunner implementations may be provided for running - * Jetty, Karyon, etc... - * - * @author elandau - * - */ -public interface LifecycleRunner { -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/TerminationEvent.java b/governator-legacy/src/main/java/com/netflix/governator/guice/runner/TerminationEvent.java deleted file mode 100644 index 679bc5a5..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/TerminationEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.netflix.governator.guice.runner; - -/** - * Abstraction for an event that when fired should tell the LifecycleRunner - * to terminate. A concrete TerminatEvent type is normally paired with a - * specific runner implementation. - * - * @author elandau - * - * TODO: Add additional listeners of the termination event - */ -public interface TerminationEvent { - /** - * Block until the termination event is fired. - * - * @throws InterruptedException - */ - public void await() throws InterruptedException; - - /** - * Fire the termination event. - */ - public void terminate(); - - /** - * @return True if the termination event was set. - */ - public boolean isTerminated(); -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/events/BlockingTerminationEvent.java b/governator-legacy/src/main/java/com/netflix/governator/guice/runner/events/BlockingTerminationEvent.java deleted file mode 100644 index bf4081aa..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/events/BlockingTerminationEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.netflix.governator.guice.runner.events; - -import javax.inject.Singleton; - -import com.netflix.governator.guice.runner.TerminationEvent; - -/** - * Simple TerminatEvent using a countdown latch as the termination signal. - * - * @author elandau - */ -@Singleton -public class BlockingTerminationEvent implements TerminationEvent { - private volatile boolean isTerminated = false; - - @Override - public synchronized void await() throws InterruptedException { - while (!isTerminated) { - this.wait(); - } - } - - @Override - public synchronized void terminate() { - isTerminated = true; - this.notifyAll(); - } - - @Override - public boolean isTerminated() { - return isTerminated; - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/events/SelfDestructingTerminationEvent.java b/governator-legacy/src/main/java/com/netflix/governator/guice/runner/events/SelfDestructingTerminationEvent.java deleted file mode 100644 index 9ff96ca1..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/events/SelfDestructingTerminationEvent.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.netflix.governator.guice.runner.events; - -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; - -/** - * Used mainly for testing the SelfDestructingTerminationEvent will fire the main TerminateEvent - * after a specified amount of time has elapsed, causing the application to exit. - * @author elandau - */ -public class SelfDestructingTerminationEvent extends BlockingTerminationEvent { - public SelfDestructingTerminationEvent(final long timeout, final TimeUnit units) { - Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).build()) - .schedule(new Runnable() { - @Override - public void run() { - terminate(); - } - }, timeout, units); - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/standalone/StandaloneRunnerModule.java b/governator-legacy/src/main/java/com/netflix/governator/guice/runner/standalone/StandaloneRunnerModule.java deleted file mode 100644 index 329614db..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/runner/standalone/StandaloneRunnerModule.java +++ /dev/null @@ -1,181 +0,0 @@ -package com.netflix.governator.guice.runner.standalone; - -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import javax.annotation.PostConstruct; -import javax.inject.Singleton; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.TypeLiteral; -import com.netflix.governator.annotations.binding.Main; -import com.netflix.governator.guice.BootstrapBinder; -import com.netflix.governator.guice.BootstrapModule; -import com.netflix.governator.guice.lazy.LazySingleton; -import com.netflix.governator.guice.lazy.LazySingletonScope; -import com.netflix.governator.guice.runner.LifecycleRunner; -import com.netflix.governator.guice.runner.TerminationEvent; -import com.netflix.governator.guice.runner.events.BlockingTerminationEvent; -import com.netflix.governator.lifecycle.LifecycleManager; - -/** - * Implementation of a Runner module that should be used for runtime applications. - * - * @author elandau - */ -public class StandaloneRunnerModule implements BootstrapModule { - private static Logger LOG = LoggerFactory.getLogger(StandaloneRunnerModule.class); - - /** - * This builder simplifies creation of the module in main() - */ - public static class Builder { - private List args = Lists.newArrayList(); - private Class main; - private TerminationEvent terminateEvent; - - /** - * Specify optional command line arguments to be injected. The arguments can be injected - * as - * - * - * @Main List - * - * @param args - */ - public Builder withArgs(String[] args) { - this.args.addAll(Lists.newArrayList(args)); - return this; - } - - /** - * Specify an optional main class to instantiate. Alternatively the - * main class can be added as an eager singleton - * @param main - */ - public Builder withMainClass(Class main) { - this.main = main; - return this; - } - - /** - * Specify an externally provided {@link TerminationEvent}. If not specified - * the default {@link BlockingTerminationEvent} will be used. - * @param event - */ - public Builder withTerminateEvent(TerminationEvent event) { - this.terminateEvent = event; - return this; - } - - public StandaloneRunnerModule build() { - return new StandaloneRunnerModule(this); - } - } - - public static Builder builder() { - return new Builder(); - } - - @LazySingleton - public static class StandaloneFramework implements LifecycleRunner { - @Inject - private Injector injector ; - - @Inject - private LifecycleManager manager; - - @Inject(optional=true) - private @Main Class mainClass; - - @Inject(optional=true) - private @Main List args; - - @Inject - private @Main TerminationEvent terminateEvent; - - /** - * This is the application's main 'run' loop. which blocks on the termination event - */ - @PostConstruct - public void init() { - try { - LOG.info("Starting application"); - manager.start(); - - if (mainClass != null) - injector.getInstance(mainClass); - - final ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("GovernatorStandaloneTerminator-%d").build()); - executor.execute(new Runnable() { - @Override - public void run() { - LOG.info("Waiting for terminate event"); - try { - terminateEvent.await(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - LOG.info("Terminating application"); - manager.close(); - executor.shutdown(); - } - }); - } - catch (Exception e) { - LOG.error("Error executing application ", e); - } - } - } - - private final List args; - private final Class main; - private final TerminationEvent terminateEvent; - - public StandaloneRunnerModule(String[] args, Class main) { - this.args = ImmutableList.copyOf(args); - this.main = main; - this.terminateEvent = null; - } - - private StandaloneRunnerModule(Builder builder) { - this.args = builder.args; - this.main = builder.main; - this.terminateEvent = builder.terminateEvent; - } - - @Singleton - public static class MainInjectorModule extends AbstractModule { - @Override - protected void configure() { - bind(LifecycleRunner.class).to(StandaloneFramework.class).asEagerSingleton(); - } - } - - @Override - public void configure(BootstrapBinder binder) { - binder.bind(MainInjectorModule.class); - - if (main != null) { - binder.bind(main).in(LazySingletonScope.get()); - binder.bind(new TypeLiteral>() {}).annotatedWith(Main.class).toInstance(main); - } - if (args != null) { - binder.bind(new TypeLiteral>() {}).annotatedWith(Main.class).toInstance(args); - } - - if (terminateEvent == null) - binder.bind(TerminationEvent.class).annotatedWith(Main.class).to(BlockingTerminationEvent.class); - else - binder.bind(TerminationEvent.class).annotatedWith(Main.class).toInstance(terminateEvent); - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/OverrideAllDuplicateBindings.java b/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/OverrideAllDuplicateBindings.java deleted file mode 100644 index 0af70326..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/OverrideAllDuplicateBindings.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.netflix.governator.guice.transformer; - -import java.util.Collection; - -import com.google.common.collect.ImmutableList; -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.util.Modules; -import com.netflix.governator.guice.ModuleTransformer; - -/** - * Treat any binding in list order as an override for previous bindings. - * - * @author elandau - */ -public class OverrideAllDuplicateBindings implements ModuleTransformer { - - @Override - public Collection call(Collection modules) { - // Starting point - Module current = new AbstractModule() { - @Override - protected void configure() { - } - }; - - // Accumulate bindings while allowing for each to override all - // previous bindings - for (Module module : modules) { - current = Modules.override(current).with(module); - } - return ImmutableList.of(current); - } - -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/StripStaticInjections.java b/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/StripStaticInjections.java deleted file mode 100644 index 2dc3ba05..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/StripStaticInjections.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.netflix.governator.guice.transformer; - -import java.util.Collection; -import java.util.List; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.inject.Module; -import com.google.inject.spi.DefaultElementVisitor; -import com.google.inject.spi.Element; -import com.google.inject.spi.Elements; -import com.google.inject.spi.StaticInjectionRequest; -import com.netflix.governator.guice.ModuleTransformer; - -public class StripStaticInjections implements ModuleTransformer { - @Override - public Collection call(Collection modules) { - final List noStatics = Lists.newArrayList(); - for(Element element : Elements.getElements(modules)) { - element.acceptVisitor(new DefaultElementVisitor() { - @Override - public Void visit(StaticInjectionRequest request) { - // override to not call visitOther - return null; - } - - @Override - public Void visitOther(Element element) { - noStatics.add(element); - return null; - } - }); - } - return ImmutableList.of(Elements.getModule(noStatics)); - } -} diff --git a/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/WarnAboutStaticInjections.java b/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/WarnAboutStaticInjections.java deleted file mode 100644 index 4da305bc..00000000 --- a/governator-legacy/src/main/java/com/netflix/governator/guice/transformer/WarnAboutStaticInjections.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.netflix.governator.guice.transformer; - -import java.util.Collection; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.inject.Module; -import com.google.inject.spi.DefaultElementVisitor; -import com.google.inject.spi.Element; -import com.google.inject.spi.Elements; -import com.google.inject.spi.StaticInjectionRequest; -import com.netflix.governator.guice.ModuleTransformer; - -public class WarnAboutStaticInjections implements ModuleTransformer { - private static Logger LOG = LoggerFactory.getLogger(WarnAboutStaticInjections.class); - - @Override - public Collection call(Collection modules) { - for(Element element : Elements.getElements(modules)) { - element.acceptVisitor(new DefaultElementVisitor() { - @Override - public Void visit(StaticInjectionRequest request) { - LOG.warn("You shouldn't be using static injection at: " + request.getSource()); - return null; - } - }); - } - return modules; - } - -} diff --git a/governator-legacy/src/test/java/com/netflix/governator/BootstrapTest.java b/governator-legacy/src/test/java/com/netflix/governator/BootstrapTest.java deleted file mode 100644 index 1fad5d51..00000000 --- a/governator-legacy/src/test/java/com/netflix/governator/BootstrapTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.netflix.governator; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.CreationException; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Stage; -import com.netflix.governator.guice.ModulesEx; -import com.netflix.governator.guice.annotations.Bootstrap; - -public class BootstrapTest { - - public static interface Foo { - } - - public static class Foo1 implements Foo { - } - - public static class Foo2 implements Foo { - } - - @Documented - @Retention(java.lang.annotation.RetentionPolicy.RUNTIME) - @Target({ElementType.TYPE}) - @Bootstrap(module=FooBootstrap.class) - public static @interface FooConfiguration { - Class foo() default Foo1.class; - } - - public static class FooBootstrap extends AbstractModule { - private FooConfiguration config; - public FooBootstrap(FooConfiguration config) { - this.config = config; - } - - @Override - protected void configure() { - bind(Foo.class).to(config.foo()); - } - } - - @FooConfiguration - public static class MyApplication extends AbstractModule { - @Override - protected void configure() { - } - } - - @FooConfiguration - public static class MyApplicationWithOverride extends AbstractModule { - @Override - protected void configure() { - bind(Foo.class).to(Foo2.class); - } - } - - @Test - public void testWithoutOverride() { - Injector injector = Guice.createInjector(Stage.DEVELOPMENT, ModulesEx.fromClass(MyApplication.class)); - Assert.assertEquals(Foo1.class, injector.getInstance(Foo.class).getClass()); - } - - @Test(expectedExceptions=CreationException.class) - public void testDuplicateWithoutOverride() { - Injector injector = Guice.createInjector(Stage.DEVELOPMENT, ModulesEx.fromClass(MyApplicationWithOverride.class, false)); - Assert.fail("Should have failed with duplicate binding exception"); - } - - @Test - public void testDuplicateWithOverride() { - Injector injector = Guice.createInjector(Stage.DEVELOPMENT, ModulesEx.fromClass(MyApplicationWithOverride.class)); - Assert.assertEquals(Foo2.class, injector.getInstance(Foo.class).getClass()); - } - -} diff --git a/governator-legacy/src/test/java/com/netflix/governator/autobind/TestAutoBind.java b/governator-legacy/src/test/java/com/netflix/governator/autobind/TestAutoBind.java index 145a248c..30a9d21f 100644 --- a/governator-legacy/src/test/java/com/netflix/governator/autobind/TestAutoBind.java +++ b/governator-legacy/src/test/java/com/netflix/governator/autobind/TestAutoBind.java @@ -18,19 +18,18 @@ import com.google.common.collect.Lists; import com.google.inject.Binder; -import com.google.inject.Guice; import com.google.inject.Injector; -import com.google.inject.Module; import com.google.inject.TypeLiteral; import com.netflix.governator.LifecycleInjectorBuilderProvider; import com.netflix.governator.annotations.AutoBind; import com.netflix.governator.guice.AutoBindProvider; -import com.netflix.governator.guice.AutoBinds; import com.netflix.governator.guice.BootstrapBinder; import com.netflix.governator.guice.BootstrapModule; import com.netflix.governator.guice.LifecycleInjectorBuilder; + import org.testng.Assert; import org.testng.annotations.Test; + import java.util.Collections; public class TestAutoBind extends LifecycleInjectorBuilderProvider @@ -190,24 +189,6 @@ public void configure(BootstrapBinder binder) Assert.assertEquals(instance.getF2().getParameter(), "f2"); } - @Test - public void testNormally() - { - Injector injector = Guice.createInjector - ( - new Module() - { - @Override - public void configure(Binder binder) - { - binder.bind(String.class).annotatedWith(AutoBinds.withValue("foo")).toInstance("we are the music makers"); - } - } - ); - - Assert.assertEquals(injector.getInstance(SimpleAutoBind.class).getString(), "we are the music makers"); - } - private static class CustomAutoBindProvider implements AutoBindProvider { @Override diff --git a/governator-legacy/src/test/java/com/netflix/governator/guice/TestPostInjectAction.java b/governator-legacy/src/test/java/com/netflix/governator/guice/TestPostInjectAction.java deleted file mode 100644 index f94962c6..00000000 --- a/governator-legacy/src/test/java/com/netflix/governator/guice/TestPostInjectAction.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.netflix.governator.guice; - -import java.lang.reflect.Method; -import java.util.concurrent.atomic.AtomicInteger; - -import javax.inject.Inject; -import javax.inject.Provider; - -import junit.framework.Assert; - -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Scopes; -import com.google.inject.Singleton; -import com.google.inject.Stage; -import com.netflix.governator.guice.actions.BindingReport; -import com.netflix.governator.guice.actions.CreateAllBoundSingletons; -import com.netflix.governator.guice.actions.GrapherAction; - -public class TestPostInjectAction { - @Test - public void testPostInjectReport() { - GrapherAction action = new GrapherAction(); - LifecycleInjector.builder() - .withPostInjectorAction(action) - .build() - .createInjector(); - - Assert.assertNotNull(action.getText()); - } - - public static interface Foo { - - } - - private String testName; - - @BeforeMethod - public void handleTestMethodName(Method method) - { - testName = method.getName(); - } - - @Singleton - public static class Transitive { - private static AtomicInteger counter = new AtomicInteger(); - - public Transitive() { - counter.incrementAndGet(); - } - } - - @Singleton - public static class FooImpl implements Foo { - private static AtomicInteger counter = new AtomicInteger(); - - @Inject - public FooImpl(Provider transitive) { - counter.incrementAndGet(); - } - } - - public static class FooNotAnnotated implements Foo { - private static AtomicInteger counter = new AtomicInteger(); - - @Inject - public FooNotAnnotated(Provider transitive) { - counter.incrementAndGet(); - } - } - - @BeforeMethod - public void before() { - FooImpl.counter.set(0); - FooNotAnnotated.counter.set(0); - Transitive.counter.set(0); - } - - @Test - public void testClassSingleton() { - LifecycleInjector.builder() - .inStage(Stage.DEVELOPMENT) - .withMode(LifecycleInjectorMode.SIMULATED_CHILD_INJECTORS) - .withPostInjectorAction(new BindingReport(testName)) - .withPostInjectorAction(new CreateAllBoundSingletons()) - .withModules(new AbstractModule() { - @Override - protected void configure() { - bind(FooImpl.class); - } - }) - .build() - .createInjector(); - - Assert.assertEquals(1, FooImpl.counter.get()); - Assert.assertEquals(0, Transitive.counter.get()); - } - - @Test - public void testInterfaceSingleton() { - LifecycleInjector.builder() - .withPostInjectorAction(new BindingReport(testName)) - .withPostInjectorAction(new CreateAllBoundSingletons()) - .inStage(Stage.DEVELOPMENT) - .withMode(LifecycleInjectorMode.SIMULATED_CHILD_INJECTORS) - .withModules(new AbstractModule() { - @Override - protected void configure() { - bind(Foo.class).to(FooImpl.class); - } - }) - .build() - .createInjector(); - - Assert.assertEquals(1, FooImpl.counter.get()); - Assert.assertEquals(0, Transitive.counter.get()); - } - - @Test - public void testInterfaceSingletonProductionStage() { - LifecycleInjector.builder() - .withPostInjectorAction(new BindingReport(testName)) - .withPostInjectorAction(new CreateAllBoundSingletons()) - .withModules(new AbstractModule() { - @Override - protected void configure() { - bind(Foo.class).to(FooImpl.class); - } - }) - .build() - .createInjector(); - - Assert.assertEquals(1, FooImpl.counter.get()); - Assert.assertEquals(0, Transitive.counter.get()); - } - - @Test - public void testScopedSingleton() { - LifecycleInjector.builder() - .withPostInjectorAction(new BindingReport(testName)) - .withPostInjectorAction(new CreateAllBoundSingletons()) - .inStage(Stage.DEVELOPMENT) - .withMode(LifecycleInjectorMode.SIMULATED_CHILD_INJECTORS) - .withModules(new AbstractModule() { - @Override - protected void configure() { - bind(Foo.class).to(FooNotAnnotated.class).in(Scopes.SINGLETON); - } - }) - .build() - .createInjector(); - - Assert.assertEquals(1, FooNotAnnotated.counter.get()); - Assert.assertEquals(0, Transitive.counter.get()); - } - - - -} diff --git a/governator-legacy/src/test/java/com/netflix/governator/guice/TestStandaloneApplication.java b/governator-legacy/src/test/java/com/netflix/governator/guice/TestStandaloneApplication.java deleted file mode 100644 index 958d4d76..00000000 --- a/governator-legacy/src/test/java/com/netflix/governator/guice/TestStandaloneApplication.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.netflix.governator.guice; - -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; - -import junit.framework.Assert; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.base.Stopwatch; -import com.google.inject.AbstractModule; -import com.netflix.governator.guice.runner.TerminationEvent; -import com.netflix.governator.guice.runner.events.SelfDestructingTerminationEvent; -import com.netflix.governator.guice.runner.standalone.StandaloneRunnerModule; - -public class TestStandaloneApplication { - private static Logger LOG = LoggerFactory.getLogger(TestStandaloneApplication.class); - - private final static AtomicBoolean initCalled = new AtomicBoolean(); - private final static AtomicBoolean shutdownCalled = new AtomicBoolean(); - - public static class SomeSingleton { - @PostConstruct - public void init() { - LOG.info("Init SomeSingleton()"); - initCalled.set(true); - } - - @PreDestroy - public void shutdown() { - LOG.info("Shutdown SomeSingleton()"); - shutdownCalled.set(true); - } - } - - @BeforeTest - public static void before() { - initCalled.set(false); - shutdownCalled.set(false); - } - - @Test(enabled=false) - public void shouldCreateSingletonAndExitAfter1Second() throws Exception { - Stopwatch sw = new Stopwatch().start(); - - final TerminationEvent event = new SelfDestructingTerminationEvent(1, TimeUnit.SECONDS); - LifecycleInjector.builder() - // Example of a singleton that will be created - .withAdditionalModules(new AbstractModule() { - @Override - protected void configure() { - bind(SomeSingleton.class).asEagerSingleton(); - } - }) - .withAdditionalBootstrapModules( - StandaloneRunnerModule.builder() - .withTerminateEvent(event) - .build()) - .build() - .createInjector(); - - event.await(); - long elapsed = sw.elapsed(TimeUnit.MILLISECONDS); - LOG.info("Elapsed: " + elapsed); - Assert.assertTrue(initCalled.get()); - Assert.assertTrue(shutdownCalled.get()); - Assert.assertTrue(elapsed > 1000); - - LOG.info("Exit main"); - - } - - public static void main(String args[]) { - final TerminationEvent event = new SelfDestructingTerminationEvent(1, TimeUnit.SECONDS); - LifecycleInjector.builder() - // Example of a singleton that will be created - .withAdditionalModules(new AbstractModule() { - @Override - protected void configure() { - bind(SomeSingleton.class).asEagerSingleton(); - } - }) - .withAdditionalBootstrapModules( - StandaloneRunnerModule.builder() - .withTerminateEvent(event) - .build()) - .build() - .createInjector(); - - } -} diff --git a/governator-legacy/src/test/java/com/netflix/governator/guice/transformer/OverrideAllDuplicateBindingsTest.java b/governator-legacy/src/test/java/com/netflix/governator/guice/transformer/OverrideAllDuplicateBindingsTest.java deleted file mode 100644 index 11bf27a8..00000000 --- a/governator-legacy/src/test/java/com/netflix/governator/guice/transformer/OverrideAllDuplicateBindingsTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.netflix.governator.guice.transformer; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Injector; -import com.netflix.governator.guice.LifecycleInjector; - -public class OverrideAllDuplicateBindingsTest { - public static interface Foo { - - } - public static class Foo1 implements Foo { - - } - public static class Foo2 implements Foo { - - } - - public static class MyModule extends AbstractModule { - @Override - protected void configure() { - bind(Foo.class).to(Foo1.class); - } - } - - public static class MyOverrideModule extends AbstractModule { - @Override - protected void configure() { - bind(Foo.class).to(Foo2.class); - } - } - - @Test - public void testShouldFailOnDuplicate() { - try { - LifecycleInjector.builder() - .withModuleClasses(MyModule.class, MyOverrideModule.class) - .build() - .createInjector(); - Assert.fail("Should have failed with duplicate binding"); - } - catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testShouldInstallDuplicate() { - Injector injector = LifecycleInjector.builder() - .withModuleTransformer(new OverrideAllDuplicateBindings()) - .withModuleClasses(MyModule.class, MyOverrideModule.class) - .build() - .createInjector(); - - Foo foo = injector.getInstance(Foo.class); - Assert.assertTrue(foo.getClass().equals(Foo2.class)); - } -}