本文整理了Java中com.google.inject.Binding.getProvider()
方法的一些代码示例,展示了Binding.getProvider()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binding.getProvider()
方法的具体详情如下:
包路径:com.google.inject.Binding
类名称:Binding
方法名:getProvider
[英]Returns the scoped provider guice uses to fulfill requests for this binding.
[中]返回guice用于满足此绑定请求的作用域提供程序。
代码示例来源:origin: com.google.inject/guice
static <T> InternalFactory<Provider<T>> createInternalFactory(Binding<T> providedBinding) {
final Provider<T> provider = providedBinding.getProvider();
return new InternalFactory<Provider<T>>() {
@Override
public Provider<T> get(InternalContext context, Dependency<?> dependency, boolean linked) {
return provider;
}
};
}
代码示例来源:origin: jenkinsci/jenkins
private <U> void _find(Class<U> type, List<ExtensionComponent<U>> result, Injector container) {
for (Entry<Key<?>, Binding<?>> e : container.getBindings().entrySet()) {
if (type.isAssignableFrom(e.getKey().getTypeLiteral().getRawType())) {
Annotation a = annotations.get(e.getKey());
Object o = e.getValue().getProvider().get();
if (o!=null) {
GuiceExtensionAnnotation gea = a!=null ? extensionAnnotations.get(a.annotationType()) : null;
result.add(new ExtensionComponent<>(type.cast(o), gea != null ? gea.getOrdinal(a) : 0));
}
}
}
}
代码示例来源:origin: apache/incubator-druid
private Emitter findEmitter(String emitterType, List<Binding<Emitter>> emitterBindings)
{
for (Binding<Emitter> binding : emitterBindings) {
if (Names.named(emitterType).equals(binding.getKey().getAnnotation())) {
return binding.getProvider().get();
}
}
return null;
}
代码示例来源:origin: com.google.inject/guice
@Override
void initialize(InjectorImpl injector, Errors errors) {
Binding<V> valueBinding = injector.getExistingBinding(valueKey);
entry = Maps.immutableEntry(key, valueBinding.getProvider());
}
代码示例来源:origin: apache/incubator-druid
private TLSCertificateChecker findChecker(
String checkerType,
List<Binding<TLSCertificateChecker>> checkerBindings
)
{
for (Binding<TLSCertificateChecker> binding : checkerBindings) {
if (Names.named(checkerType).equals(binding.getKey().getAnnotation())) {
return binding.getProvider().get();
}
}
return null;
}
}
代码示例来源:origin: bootique/bootique
private static Optional<Command> defaultCommand(Injector injector) {
// default is optional, so check via injector whether it is bound...
Binding<Command> binding = injector.getExistingBinding(Key.get(Command.class, DefaultCommand.class));
return binding != null ? Optional.of(binding.getProvider().get()) : Optional.empty();
}
代码示例来源:origin: com.google.inject/guice
@Override
protected void doInitialize(InjectorImpl injector, Errors errors) {
ImmutableMap.Builder<K, Provider<V>> mapOfProvidersBuilder = ImmutableMap.builder();
ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder();
for (Map.Entry<K, Binding<V>> entry : bindingSelection.getMapBindings().entrySet()) {
mapOfProvidersBuilder.put(entry.getKey(), entry.getValue().getProvider());
dependenciesBuilder.add(Dependency.get(getKeyOfProvider(entry.getValue().getKey())));
}
mapOfProviders = mapOfProvidersBuilder.build();
dependencies = dependenciesBuilder.build();
}
代码示例来源:origin: bootique/bootique
private static Optional<Command> defaultCommand(Injector injector) {
// default is optional, so check via injector whether it is bound...
Binding<Command> binding = injector.getExistingBinding(Key.get(Command.class, DefaultCommand.class));
return binding != null ? Optional.of(binding.getProvider().get()) : Optional.empty();
}
代码示例来源:origin: com.google.inject/guice
@Override
void initialize(InjectorImpl injector, Errors errors) throws ErrorsException {
bindingSelection.initialize(injector, errors);
ImmutableList.Builder<Provider<T>> providers = ImmutableList.builder();
for (Binding<T> binding : bindingSelection.getBindings()) {
providers.add(binding.getProvider());
}
this.collectionOfProviders = providers.build();
}
代码示例来源:origin: apache/incubator-druid
@BeforeClass
public static void populateStatics()
{
injector = GuiceInjectors.makeStartupInjectorWithModules(ImmutableList.<com.google.inject.Module>of(new CacheConfigTestModule()));
configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
}
代码示例来源:origin: apache/incubator-druid
@Test(expected = NullPointerException.class)
public void testFailsOnEmptyTier()
{
final JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
properties.put(propertyBase + ".lookupTier", "");
final JsonConfigProvider<LookupListeningAnnouncerConfig> configProvider = JsonConfigProvider.of(
propertyBase,
LookupListeningAnnouncerConfig.class
);
configProvider.inject(properties, configurator);
final LookupListeningAnnouncerConfig config = configProvider.get().get();
config.getLookupTier();
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testDatasourceInjection()
{
final JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
properties.put(propertyBase + ".lookupTierIsDatasource", "true");
final JsonConfigProvider<LookupListeningAnnouncerConfig> configProvider = JsonConfigProvider.of(
propertyBase,
LookupListeningAnnouncerConfig.class
);
configProvider.inject(properties, configurator);
final LookupListeningAnnouncerConfig config = configProvider.get().get();
Assert.assertEquals("some_datasource", config.getLookupTier());
}
代码示例来源:origin: apache/incubator-druid
@Test(expected = IllegalArgumentException.class)
public void testFailsInjection()
{
final String lookupTier = "some_tier";
final JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
properties.put(propertyBase + ".lookupTier", lookupTier);
properties.put(propertyBase + ".lookupTierIsDatasource", "true");
final JsonConfigProvider<LookupListeningAnnouncerConfig> configProvider = JsonConfigProvider.of(
propertyBase,
LookupListeningAnnouncerConfig.class
);
configProvider.inject(properties, configurator);
final LookupListeningAnnouncerConfig config = configProvider.get().get();
Assert.assertEquals(lookupTier, config.getLookupTier());
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testSimpleInjection()
{
final String lookupTier = "some_tier";
final JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
properties.put(propertyBase + ".lookupTier", lookupTier);
final JsonConfigProvider<LookupListeningAnnouncerConfig> configProvider = JsonConfigProvider.of(
propertyBase,
LookupListeningAnnouncerConfig.class
);
configProvider.inject(properties, configurator);
final LookupListeningAnnouncerConfig config = configProvider.get().get();
Assert.assertEquals(lookupTier, config.getLookupTier());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testDefaultInjection()
{
final JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
final JsonConfigProvider<LookupListeningAnnouncerConfig> configProvider = JsonConfigProvider.of(
propertyBase,
LookupListeningAnnouncerConfig.class
);
configProvider.inject(properties, configurator);
final LookupListeningAnnouncerConfig config = configProvider.get().get();
Assert.assertEquals(LookupListeningAnnouncerConfig.DEFAULT_TIER, config.getLookupTier());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testIndexerBaseOverride()
{
final String overrideValue = "/foo/bar/baz";
final String indexerPropertyKey = indexerPropertyString + ".base";
final String priorValue = System.getProperty(indexerPropertyKey);
System.setProperty(indexerPropertyKey, overrideValue); // Set it here so that the binding picks it up
final Injector injector = Initialization.makeInjectorWithModules(
GuiceInjectors.makeStartupInjector(),
ImmutableList.of(simpleZkConfigModule)
);
propertyValues.clear();
propertyValues.setProperty(indexerPropertyKey, overrideValue); // Have to set it here as well annoyingly enough
JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
JsonConfigProvider<IndexerZkConfig> indexerPathsConfig = JsonConfigProvider.of(
indexerPropertyString,
IndexerZkConfig.class
);
indexerPathsConfig.inject(propertyValues, configurator);
IndexerZkConfig indexerZkConfig = indexerPathsConfig.get().get();
// Rewind value before we potentially fail
if (priorValue == null) {
System.clearProperty(indexerPropertyKey);
} else {
System.setProperty(indexerPropertyKey, priorValue);
}
Assert.assertEquals(overrideValue, indexerZkConfig.getBase());
Assert.assertEquals(overrideValue + "/announcements", indexerZkConfig.getAnnouncementsPath());
}
代码示例来源:origin: apache/incubator-druid
@Override
public HttpClient get()
{
final DruidHttpClientConfig config = getConfigProvider().get().get();
final HttpClientConfig.Builder builder = HttpClientConfig
.builder()
.withNumConnections(config.getNumConnections())
.withReadTimeout(config.getReadTimeout())
.withWorkerCount(config.getNumMaxThreads())
.withCompressionCodec(
HttpClientConfig.CompressionCodec.valueOf(StringUtils.toUpperCase(config.getCompressionCodec()))
)
.withUnusedConnectionTimeoutDuration(config.getUnusedConnectionTimeout());
if (getSslContextBinding() != null) {
builder.withSslContext(getSslContextBinding().getProvider().get());
}
HttpClient client = HttpClientInit.createClient(
builder.build(),
LifecycleUtils.asMmxLifecycle(getLifecycleProvider().get())
);
if (isEscalated) {
return escalator.createEscalatedClient(client);
} else {
return client;
}
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testNullConfig()
{
propertyValues.clear();
final Injector injector = Initialization.makeInjectorWithModules(
GuiceInjectors.makeStartupInjector(),
ImmutableList.of(simpleZkConfigModule)
);
JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class);
zkPathsConfig.inject(propertyValues, configurator);
JsonConfigProvider<IndexerZkConfig> indexerZkConfig = JsonConfigProvider.of(
indexerPropertyString,
IndexerZkConfig.class
);
indexerZkConfig.inject(propertyValues, configurator);
Assert.assertEquals("/druid/indexer/tasks", indexerZkConfig.get().get().getTasksPath());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testExactConfig()
{
final Injector injector = Initialization.makeInjectorWithModules(
GuiceInjectors.makeStartupInjector(),
ImmutableList.of(simpleZkConfigModule)
);
propertyValues.setProperty(zkServiceConfigString + ".base", "/druid/metrics");
JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(
zkServiceConfigString,
ZkPathsConfig.class
);
zkPathsConfig.inject(propertyValues, configurator);
ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get();
IndexerZkConfig indexerZkConfig = new IndexerZkConfig(zkPathsConfig1, null, null, null, null);
Assert.assertEquals("/druid/metrics/indexer", indexerZkConfig.getBase());
Assert.assertEquals("/druid/metrics/indexer/announcements", indexerZkConfig.getAnnouncementsPath());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testSimpleConfig() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException
{
final Injector injector = Initialization.makeInjectorWithModules(
GuiceInjectors.makeStartupInjector(),
ImmutableList.of(simpleZkConfigModule)
);
JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(zkServiceConfigString, ZkPathsConfig.class);
zkPathsConfig.inject(propertyValues, configurator);
JsonConfigProvider<IndexerZkConfig> indexerZkConfig = JsonConfigProvider.of(
indexerPropertyString,
IndexerZkConfig.class
);
indexerZkConfig.inject(propertyValues, configurator);
IndexerZkConfig zkConfig = indexerZkConfig.get().get();
ZkPathsConfig zkPathsConfig1 = zkPathsConfig.get().get();
validateEntries(zkConfig);
validateEntries(zkPathsConfig1);
Assert.assertEquals(clobberableProperties.size(), assertions);
}
内容来源于网络,如有侵权,请联系作者删除!