Search in sources :

Example 1 with LifecycleInjector

use of com.netflix.governator.LifecycleInjector in project eureka by Netflix.

the class EurekaClientModuleConfigurationTest method testBindEurekaInstanceConfigFactory.

@Test
public void testBindEurekaInstanceConfigFactory() {
    final EurekaInstanceConfigFactory mockFactory = Mockito.mock(EurekaInstanceConfigFactory.class);
    final EurekaInstanceConfig mockConfig = Mockito.mock(EurekaInstanceConfig.class);
    final ApplicationInfoManager mockInfoManager = Mockito.mock(ApplicationInfoManager.class);
    Mockito.when(mockFactory.get()).thenReturn(mockConfig);
    LifecycleInjector injector = InjectorBuilder.fromModules(new ArchaiusModule(), new EurekaClientModule() {

        @Override
        protected void configureEureka() {
            bindEurekaInstanceConfigFactory().toInstance(mockFactory);
        }
    }).overrideWith(new AbstractModule() {

        @Override
        protected void configure() {
            // this is usually bound as an eager singleton that can trigger other parts to
            // initialize, so do an override to a mock here to prevent that.
            bind(ApplicationInfoManager.class).toInstance(mockInfoManager);
        }
    }).createInjector();
    EurekaInstanceConfig config = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(mockConfig, config);
}
Also used : EurekaInstanceConfigFactory(com.netflix.appinfo.providers.EurekaInstanceConfigFactory) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) ArchaiusModule(com.netflix.archaius.guice.ArchaiusModule) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) LifecycleInjector(com.netflix.governator.LifecycleInjector) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 2 with LifecycleInjector

use of com.netflix.governator.LifecycleInjector in project eureka by Netflix.

the class ExampleEurekaGovernatedService method init.

private static LifecycleInjector init() throws Exception {
    System.out.println("Creating injector for Example Service");
    LifecycleInjector injector = InjectorBuilder.fromModules(new EurekaModule(), new ExampleServiceModule()).overrideWith(new AbstractModule() {

        @Override
        protected void configure() {
            DynamicPropertyFactory configInstance = com.netflix.config.DynamicPropertyFactory.getInstance();
            bind(DynamicPropertyFactory.class).toInstance(configInstance);
            // the default impl of EurekaInstanceConfig is CloudInstanceConfig, which we only want in an AWS
            // environment. Here we override that by binding MyDataCenterInstanceConfig to EurekaInstanceConfig.
            bind(EurekaInstanceConfig.class).to(MyDataCenterInstanceConfig.class);
        // (DiscoveryClient optional bindings) bind the optional event bus
        // bind(EventBus.class).to(EventBusImpl.class).in(Scopes.SINGLETON);
        }
    }).createInjector();
    System.out.println("Done creating the injector");
    return injector;
}
Also used : EurekaModule(com.netflix.discovery.guice.EurekaModule) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) DynamicPropertyFactory(com.netflix.config.DynamicPropertyFactory) LifecycleInjector(com.netflix.governator.LifecycleInjector) AbstractModule(com.google.inject.AbstractModule)

Example 3 with LifecycleInjector

use of com.netflix.governator.LifecycleInjector in project eureka by Netflix.

the class ExampleEurekaGovernatedService method main.

public static void main(String[] args) throws Exception {
    LifecycleInjector injector = null;
    try {
        injector = init();
        injector.awaitTermination();
    } catch (Exception e) {
        System.out.println("Error starting the sample service: " + e);
        e.printStackTrace();
    } finally {
        if (injector != null) {
            injector.shutdown();
        }
    }
}
Also used : LifecycleInjector(com.netflix.governator.LifecycleInjector)

Example 4 with LifecycleInjector

use of com.netflix.governator.LifecycleInjector in project eureka by Netflix.

the class EurekaContextListener method createInjector.

@Override
protected LifecycleInjector createInjector() {
    // For backward compatibility
    JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
    XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
    LifecycleInjector injector = EurekaInjectorCreator.createInjector();
    serverContext = injector.getInstance(EurekaServerContext.class);
    return injector;
}
Also used : LifecycleInjector(com.netflix.governator.LifecycleInjector)

Aggregations

LifecycleInjector (com.netflix.governator.LifecycleInjector)4 AbstractModule (com.google.inject.AbstractModule)2 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)2 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1 EurekaInstanceConfigFactory (com.netflix.appinfo.providers.EurekaInstanceConfigFactory)1 ArchaiusModule (com.netflix.archaius.guice.ArchaiusModule)1 DynamicPropertyFactory (com.netflix.config.DynamicPropertyFactory)1 EurekaModule (com.netflix.discovery.guice.EurekaModule)1 Test (org.junit.Test)1