com.netflix.karyon.KaryonBootstrapSuite Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of karyon-governator Show documentation
Show all versions of karyon-governator Show documentation
karyon-governator developed by Netflix
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());
}
}