![JAR search and dependency download from the Maven repository](/logo.png)
apollo.internals.DefaultInjector Maven / Gradle / Ivy
The newest version!
package apollo.internals;
import apollo.exceptions.ApolloConfigException;
import apollo.spi.*;
import apollo.util.ConfigUtil;
import apollo.util.http.HttpUtil;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Singleton;
import framework.apollo.tracer.Tracer;
/**
* Guice injector
* @author Jason Song([email protected])
*/
public class DefaultInjector implements Injector {
private com.google.inject.Injector m_injector;
public DefaultInjector() {
try {
m_injector = Guice.createInjector(new ApolloModule());
} catch (Throwable ex) {
ApolloConfigException exception = new ApolloConfigException("Unable to initialize Guice Injector!", ex);
Tracer.logError(exception);
throw exception;
}
}
@Override
public T getInstance(Class clazz) {
try {
return m_injector.getInstance(clazz);
} catch (Throwable ex) {
Tracer.logError(ex);
throw new ApolloConfigException(
String.format("Unable to load instance for %s!", clazz.getName()), ex);
}
}
@Override
public T getInstance(Class clazz, String name) {
//Guice does not support get instance by type and name
return null;
}
private static class ApolloModule extends AbstractModule {
@Override
protected void configure() {
bind(ConfigManager.class).to(DefaultConfigManager.class).in(Singleton.class);
bind(ConfigFactoryManager.class).to(DefaultConfigFactoryManager.class).in(Singleton.class);
bind(ConfigRegistry.class).to(DefaultConfigRegistry.class).in(Singleton.class);
bind(ConfigFactory.class).to(DefaultConfigFactory.class).in(Singleton.class);
bind(ConfigUtil.class).in(Singleton.class);
bind(HttpUtil.class).in(Singleton.class);
bind(ConfigServiceLocator.class).in(Singleton.class);
bind(RemoteConfigLongPollService.class).in(Singleton.class);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy