com.google.inject.binder.LinkedBindingBuilder Java Examples

The following examples show how to use com.google.inject.binder.LinkedBindingBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceDiscoveryModule.java    From attic-aurora with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  LinkedBindingBuilder<Iterable<InetSocketAddress>> clusterBinder =
      bind(ServiceDiscoveryBindings.ZOO_KEEPER_CLUSTER_KEY);

  if (zooKeeperConfig.isInProcess()) {
    requireBinding(ShutdownRegistry.class);
    File tempDir = Files.createTempDir();
    bind(ZooKeeperTestServer.class).toInstance(new ZooKeeperTestServer(tempDir, tempDir));
    SchedulerServicesModule.addAppStartupServiceBinding(binder()).to(TestServerService.class);

    clusterBinder.toProvider(LocalZooKeeperClusterProvider.class).in(Singleton.class);
  } else {
    clusterBinder.toInstance(zooKeeperConfig.getServers());
  }

  install(new CuratorServiceDiscoveryModule(discoveryPath, zooKeeperConfig));
}
 
Example #2
Source File: JerseyBinder.java    From Singularity with Apache License 2.0 5 votes vote down vote up
public static LinkedBindingBuilder<ContainerRequestFilter> bindContainerRequestFilter(
  Binder binder
) {
  Multibinder<ContainerRequestFilter> requestFilterBinder = Multibinder.newSetBinder(
    binder,
    ContainerRequestFilter.class
  );
  return requestFilterBinder.addBinding();
}
 
Example #3
Source File: ConfigBindingModule.java    From dropwizard-guicey with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void bindValue(final LinkedBindingBuilder binding, final Object value) {
    if (value != null) {
        binding.toInstance(value);
    } else {
        binding.toProvider(Providers.of(null));
    }
}
 
Example #4
Source File: KaryonBootstrapModule.java    From karyon with Apache License 2.0 5 votes vote down vote up
protected void bindHealthCheck(LinkedBindingBuilder<HealthCheckHandler> bindingBuilder) {
    if (null != healthcheckHandlerClass) {
        bindingBuilder.to(healthcheckHandlerClass);
    } else {
        bindingBuilder.toInstance(healthcheckHandler);
    }
}
 
Example #5
Source File: ConfigModule.java    From flux with Apache License 2.0 5 votes vote down vote up
/**
 * Binds individual flattened key-value properties in the configuration yml
 * file. So one can directly inject something like this:
 *
 * @Named("Hibernate.hibernate.jdbcDriver") String jdbcDriver OR
 * @Named("Dashboard.service.port") int port
 */
@SuppressWarnings({"rawtypes", "unchecked"})
private void bindConfigProperties() {
    bind(YamlConfiguration.class).toInstance(yamlConfiguration);
    Iterator<String> propertyKeys = yamlConfiguration.getKeys();
    while (propertyKeys.hasNext()) {
        String propertyKey = propertyKeys.next();
        Object propertyValue = yamlConfiguration.getProperty(propertyKey);
        LinkedBindingBuilder annotatedWith = bind(propertyValue.getClass()).annotatedWith(Names.named(propertyKey));
        annotatedWith.toInstance(propertyValue);
    }
}
 
Example #6
Source File: SingularityClientModule.java    From Singularity with Apache License 2.0 5 votes vote down vote up
public static LinkedBindingBuilder<SingularityClientCredentials> bindCredentials(
  Binder binder
) {
  return binder
    .bind(SingularityClientCredentials.class)
    .annotatedWith(Names.named(CREDENTIALS_PROPERTY_NAME));
}
 
Example #7
Source File: MapBinders.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Bind the given key to an {@link ElementParser<T>}, which will be applied to
 * the root {@link Element} of the {@link Document} at parse-time, and the
 * result bound in {@link MapScoped}.
 */
default <T> LinkedBindingBuilder<ElementParser<T>> bindRootElementParser(Key<T> key) {
    install(new ProvisionAtParseTime<>(key));
    bind(key).toProvider(new ResolvableType<RootElementParsingProvider<T>>(){}
                             .with(new TypeArgument<T>(key.getTypeLiteral()){}))
             .in(MapScoped.class);
    return bindElementParser(key);
}
 
Example #8
Source File: AbstractListenersModule.java    From barge with Apache License 2.0 4 votes vote down vote up
protected final LinkedBindingBuilder<StateTransitionListener> bindTransitionListener() {
  return listenerBinder.addBinding();
}
 
Example #9
Source File: SettingCallbackBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public LinkedBindingBuilder<SettingCallback> changesIn(Setting setting) {
    return mapBinder.addBinding(setting);
}
 
Example #10
Source File: TaggerBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public LinkedBindingBuilder<Tagger> addBinding() {
    return taggers.addBinding();
}
 
Example #11
Source File: HealthModule.java    From runtime-health with Apache License 2.0 4 votes vote down vote up
final protected LinkedBindingBuilder<HealthIndicator> bindAdditionalHealthIndicator() {
    return Multibinder.newSetBinder(binder(), HealthIndicator.class).addBinding();
}
 
Example #12
Source File: ModelListenerBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public <M extends Model> LinkedBindingBuilder<ModelHandler<? super M>> bindHandler(TypeLiteral<M> model) {
    return (LinkedBindingBuilder) handlers.addBinding(model);
}
 
Example #13
Source File: KaryonEurekaModule.java    From karyon with Apache License 2.0 4 votes vote down vote up
protected LinkedBindingBuilder<EurekaClientConfig > bindEurekaClientConfig() {
    return bind(EurekaClientConfig.class);
}
 
Example #14
Source File: BaragonClientModule.java    From Baragon with Apache License 2.0 4 votes vote down vote up
public static LinkedBindingBuilder<List<String>> bindBaseUrlProvider(Binder binder) {
  return binder.bind(new TypeLiteral<List<String>>() {}).annotatedWith(Names.named(BASE_URL_PROVIDER_NAME));
}
 
Example #15
Source File: BaragonClientModule.java    From Baragon with Apache License 2.0 4 votes vote down vote up
public static LinkedBindingBuilder<Optional<String>> bindAuthkeyProvider(Binder binder) {
  return binder.bind(new TypeLiteral<Optional<String>>() {}).annotatedWith(Names.named(AUTHKEY_PROVIDER_PROPERTY_NAME));
}
 
Example #16
Source File: KaryonTcpModule.java    From karyon with Apache License 2.0 4 votes vote down vote up
public LinkedBindingBuilder<ConnectionHandler<I, O>> bindConnectionHandler() {
    return bind(connectionHandlerKey);
}
 
Example #17
Source File: KaryonHttpModule.java    From karyon with Apache License 2.0 4 votes vote down vote up
protected LinkedBindingBuilder<RequestHandler<I, O>> bindRouter() {
    return bind(routerKey);
}
 
Example #18
Source File: BaragonClientModule.java    From Baragon with Apache License 2.0 4 votes vote down vote up
public static LinkedBindingBuilder<String> bindContextPath(Binder binder) {
  return binder.bind(String.class).annotatedWith(Names.named(CONTEXT_PATH_PROPERTY_NAME));
}
 
Example #19
Source File: ModelListenerBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public LinkedBindingBuilder<ModelListener> bindListener() {
    return listeners.addBinding();
}
 
Example #20
Source File: CapabilityDispatcherModule.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
protected LinkedBindingBuilder<ArgumentResolverFactory<PlatformMessage, MessageBody>> addArgumentResolverBinding() {
	Preconditions.checkState(resolvers != null, "Must call super.configure() before calling addArgumentResolverBinding()");
	return resolvers.addBinding();
}
 
Example #21
Source File: ModelListenerBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public <M extends Model> LinkedBindingBuilder<ModelHandler<? super M>> bindHandler(Class<M> model) {
    return (LinkedBindingBuilder) handlers.addBinding(model);
}
 
Example #22
Source File: ModelBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public LinkedBindingBuilder<ModelService<M, P>> bindService() {
    queryService().setBinding().to(ModelService(M, P));
    updateService().setBinding().to(ModelService(M, P));
    return serviceBinder.setBinding();
}
 
Example #23
Source File: ModelBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public LinkedBindingBuilder<ModelService<M, P>> bindDefaultService() {
    queryService().setDefault().to(ModelService(M, P));
    updateService().setDefault().to(ModelService(M, P));
    return serviceBinder.setDefault();
}
 
Example #24
Source File: ModelBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public LinkedBindingBuilder<ModelStore<M>> bindStore() {
    binder.provisionEagerly(ModelStore(M));
    new SuspendableBinder(binder).addBinding().to(ModelStore(M));
    return storeBinder.setBinding();
}
 
Example #25
Source File: KaryonWebSocketsModule.java    From karyon with Apache License 2.0 4 votes vote down vote up
public LinkedBindingBuilder<ConnectionHandler<I, O>> bindConnectionHandler() {
    return bind(connectionHandlerKey);
}
 
Example #26
Source File: GsonBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public <T> LinkedBindingBuilder<JsonDeserializer<? extends T>> bindHiearchyDeserializer(Class<T> type) {
    return (LinkedBindingBuilder) hiearchyAdapters.addBinding(type);
}
 
Example #27
Source File: GsonBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public <T> LinkedBindingBuilder<JsonSerializer<? super T>> bindHiearchySerializer(Class<T> type) {
    return (LinkedBindingBuilder) hiearchyAdapters.addBinding(type);
}
 
Example #28
Source File: GsonBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public <T> LinkedBindingBuilder<TypeAdapter<T>> bindHiearchyAdapter(Class<T> type) {
    return (LinkedBindingBuilder) hiearchyAdapters.addBinding(type);
}
 
Example #29
Source File: GsonBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public <T> LinkedBindingBuilder<JsonDeserializer<? extends T>> bindDeserializer(TypeLiteral<T> type) {
    return (LinkedBindingBuilder) adapters.addBinding(type.getType());
}
 
Example #30
Source File: GsonBinder.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public <T> LinkedBindingBuilder<JsonDeserializer<? extends T>> bindDeserializer(Class<T> type) {
    return (LinkedBindingBuilder) adapters.addBinding(type);
}