All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.karyon.KaryonBootstrapSuite Maven / Gradle / Ivy

There is a newer version: 2.1.00-RC6
Show newest version
package com.netflix.karyon;

import javax.inject.Inject;

import com.google.inject.AbstractModule;
import com.google.inject.binder.AnnotatedBindingBuilder;
import com.google.inject.binder.LinkedBindingBuilder;
import com.netflix.governator.guice.BootstrapBinder;
import com.netflix.governator.guice.BootstrapModule;
import com.netflix.governator.guice.LifecycleInjectorBuilder;
import com.netflix.governator.guice.LifecycleInjectorBuilderSuite;
import com.netflix.governator.guice.LifecycleInjectorMode;
import com.netflix.karyon.health.HealthCheckHandler;
import com.netflix.karyon.health.HealthCheckInvocationStrategy;
import com.netflix.karyon.health.SyncHealthCheckInvocationStrategy;

/**
 * A guice module that defines all bindings required by karyon. Applications must use this to bootstrap karyon.
 *
 * @author Nitesh Kant
 */
public class KaryonBootstrapSuite implements LifecycleInjectorBuilderSuite {

    private final KaryonBootstrap karyonBootstrap;

    @Inject
    public KaryonBootstrapSuite(KaryonBootstrap karyonBootstrap) {
        this.karyonBootstrap = karyonBootstrap;
    }

    @Override
    public void configure(LifecycleInjectorBuilder builder) {
        builder.withMode(LifecycleInjectorMode.SIMULATED_CHILD_INJECTORS);
        builder.withAdditionalBootstrapModules(new BootstrapModule() {
            @Override
            public void configure(BootstrapBinder bootstrapBinder) {
                bootstrapBinder.bind(KaryonBootstrap.class).toInstance(karyonBootstrap);
            }
        });
        builder.withAdditionalModules(new AbstractModule() {
            @Override
            protected void configure() {
                bindHealthCheck(bind(HealthCheckHandler.class));
                bindHealthCheckInvocationStrategy(bind(HealthCheckInvocationStrategy.class));
            }
        });
    }

    private static void bindHealthCheckInvocationStrategy(AnnotatedBindingBuilder bindingBuilder) {
        bindingBuilder.to(SyncHealthCheckInvocationStrategy.class);
    }

    protected void bindHealthCheck(LinkedBindingBuilder bindingBuilder) {
        bindingBuilder.to(karyonBootstrap.healthcheck());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy