Java 类com.google.inject.Exposed 实例源码

项目:LanternServer    文件:LanternModule.java   
@Exposed
@Provides
@Singleton
private LanternAssetManager provideAssetManager(@Option({ "asset-repository-config", "asset-repo-config" })
        @Nullable Path repoConfig, LanternPluginManager pluginManager) {
    final Gson gson = new GsonBuilder().registerTypeAdapter(AssetRepository.class,
            new AssetRepositoryJsonDeserializer(pluginManager)).create();
    try {
        URL url;
        if (repoConfig != null) {
            url = PathUtils.toURL(repoConfig);
        } else {
            url = getClass().getClassLoader().getResource("assets_repo.json");
            checkNotNull(url);
        }
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
            return new LanternAssetManager(gson.fromJson(reader, AssetRepository.class));
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:presto    文件:QueryStatsClientModuleProvider.java   
@Override
public Module getModule(Configuration configuration)
{
    return new PrivateModule()
    {
        @Override
        protected void configure()
        {
            bind(ObjectMapper.class).toProvider(ObjectMapperProvider.class);
            bind(HttpClient.class).toInstance(new JettyHttpClient());
        }

        @Inject
        @Provides
        @Exposed
        @Singleton
        QueryStatsClient getQueryStatsClient(HttpClient httpClient, ObjectMapper objectMapper, @Named("presto_rest.base_uri") String prestoRestInterfaceBaseUri)
        {
            return new HttpQueryStatsClient(httpClient, objectMapper, URI.create(prestoRestInterfaceBaseUri));
        }
    };
}
项目:guice    文件:CheckedProviderMethod.java   
CheckedProviderMethod(
    Key<T> key,
    Method method,
    Object instance,
    ImmutableSet<Dependency<?>> dependencies,
    List<Provider<?>> parameterProviders,
    Class<? extends Annotation> scopeAnnotation,
    Class<? extends CheckedProvider> checkedProvider,
    List<TypeLiteral<?>> exceptionTypes,
    boolean scopeExceptions) {
  this.key = key;
  this.scopeAnnotation = scopeAnnotation;
  this.instance = instance;
  this.dependencies = dependencies;
  this.method = method;
  this.parameterProviders = parameterProviders;
  this.exposed = method.isAnnotationPresent(Exposed.class);
  this.checkedProvider = checkedProvider;
  this.exceptionTypes = exceptionTypes;
  this.scopeExceptions = scopeExceptions;

  method.setAccessible(true);
}
项目:guice    文件:ProviderMethod.java   
/** @param method the method to invoke. It's return type must be the same type as {@code key}. */
private ProviderMethod(
    Key<T> key,
    Method method,
    Object instance,
    ImmutableSet<Dependency<?>> dependencies,
    Class<? extends Annotation> scopeAnnotation,
    Annotation annotation) {
  // We can be safely initialized eagerly since our bindings must exist statically and it is an
  // error for them not to.
  super(InitializationTiming.EAGER);
  this.key = key;
  this.scopeAnnotation = scopeAnnotation;
  this.instance = instance;
  this.dependencies = dependencies;
  this.method = method;
  this.exposed = method.isAnnotationPresent(Exposed.class);
  this.annotation = annotation;
}
项目:guice    文件:ModuleAnnotatedMethodScannerTest.java   
public void testPrivateModuleInheritScanner_usingPrivateModule() {
  Injector injector =
      Guice.createInjector(
          NamedMunger.module(),
          new PrivateModule() {
            @Override
            protected void configure() {}

            @Exposed
            @TestProvides
            @Named("foo")
            String foo() {
              return "foo";
            }
          });
  assertMungedBinding(injector, String.class, "foo", "foo");
}
项目:guice    文件:ModuleAnnotatedMethodScannerTest.java   
public void testPrivateModule_skipSourcesWithinPrivateModule() {
  Injector injector =
      Guice.createInjector(
          NamedMunger.module(),
          new PrivateModule() {
            @Override
            protected void configure() {
              binder()
                  .skipSources(getClass())
                  .install(
                      new AbstractModule() {

                        @Exposed
                        @TestProvides
                        @Named("foo")
                        String foo() {
                          return "foo";
                        }
                      });
            }
          });
  assertMungedBinding(injector, String.class, "foo", "foo");
}
项目:guice    文件:ModuleAnnotatedMethodScannerTest.java   
public void testPrivateModule_skipSourcesForPrivateModule() {
  Injector injector =
      Guice.createInjector(
          NamedMunger.module(),
          new AbstractModule() {
            @Override
            protected void configure() {
              binder()
                  .skipSources(getClass())
                  .install(
                      new PrivateModule() {
                        @Override
                        protected void configure() {}

                        @Exposed
                        @TestProvides
                        @Named("foo")
                        String foo() {
                          return "foo";
                        }
                      });
            }
          });
  assertMungedBinding(injector, String.class, "foo", "foo");
}
项目:guice    文件:ModuleAnnotatedMethodScannerTest.java   
public void testPrivateModuleInheritScanner_usingPrivateBinder() {
  Injector injector =
      Guice.createInjector(
          NamedMunger.module(),
          new AbstractModule() {
            @Override
            protected void configure() {
              binder()
                  .newPrivateBinder()
                  .install(
                      new AbstractModule() {

                        @Exposed
                        @TestProvides
                        @Named("foo")
                        String foo() {
                          return "foo";
                        }
                      });
            }
          });
  assertMungedBinding(injector, String.class, "foo", "foo");
}
项目:guice    文件:ModuleAnnotatedMethodScannerTest.java   
public void testPrivateModuleInheritScanner_skipSourcesFromPrivateBinder() {
  Injector injector =
      Guice.createInjector(
          NamedMunger.module(),
          new AbstractModule() {
            @Override
            protected void configure() {
              binder()
                  .newPrivateBinder()
                  .skipSources(getClass())
                  .install(
                      new AbstractModule() {

                        @Exposed
                        @TestProvides
                        @Named("foo")
                        String foo() {
                          return "foo";
                        }
                      });
            }
          });
  assertMungedBinding(injector, String.class, "foo", "foo");
}
项目:guice    文件:ModuleAnnotatedMethodScannerTest.java   
public void testPrivateModuleInheritScanner_skipSourcesFromPrivateBinder2() {
  Injector injector =
      Guice.createInjector(
          NamedMunger.module(),
          new AbstractModule() {
            @Override
            protected void configure() {
              binder()
                  .skipSources(getClass())
                  .newPrivateBinder()
                  .install(
                      new AbstractModule() {

                        @Exposed
                        @TestProvides
                        @Named("foo")
                        String foo() {
                          return "foo";
                        }
                      });
            }
          });
  assertMungedBinding(injector, String.class, "foo", "foo");
}
项目:guice    文件:ModuleAnnotatedMethodScannerTest.java   
public void testPrivateModuleWithinPrivateModule() {
  Injector injector =
      Guice.createInjector(
          NamedMunger.module(),
          new PrivateModule() {
            @Override
            protected void configure() {
              expose(Key.get(String.class, named("foo-munged")));
              install(
                  new PrivateModule() {
                    @Override
                    protected void configure() {}

                    @Exposed
                    @TestProvides
                    @Named("foo")
                    String foo() {
                      return "foo";
                    }
                  });
            }
          });
  assertMungedBinding(injector, String.class, "foo", "foo");
}
项目:guice-old    文件:CheckedProviderMethod.java   
CheckedProviderMethod(
    Key<T> key,
    Method method,
    Object instance,
    ImmutableSet<Dependency<?>> dependencies,
    List<Provider<?>> parameterProviders,
    Class<? extends Annotation> scopeAnnotation,
    Class<? extends CheckedProvider> checkedProvider,
    List<TypeLiteral<?>> exceptionTypes) {
  this.key = key;
  this.scopeAnnotation = scopeAnnotation;
  this.instance = instance;
  this.dependencies = dependencies;
  this.method = method;
  this.parameterProviders = parameterProviders;
  this.exposed = method.isAnnotationPresent(Exposed.class);
  this.checkedProvider = checkedProvider;
  this.exceptionTypes = exceptionTypes;

  method.setAccessible(true);
}
项目:google-guice    文件:CheckedProviderMethod.java   
CheckedProviderMethod(
    Key<T> key,
    Method method,
    Object instance,
    ImmutableSet<Dependency<?>> dependencies,
    List<Provider<?>> parameterProviders,
    Class<? extends Annotation> scopeAnnotation,
    Class<? extends CheckedProvider> checkedProvider,
    List<TypeLiteral<?>> exceptionTypes) {
  this.key = key;
  this.scopeAnnotation = scopeAnnotation;
  this.instance = instance;
  this.dependencies = dependencies;
  this.method = method;
  this.parameterProviders = parameterProviders;
  this.exposed = method.isAnnotationPresent(Exposed.class);
  this.checkedProvider = checkedProvider;
  this.exceptionTypes = exceptionTypes;

  method.setAccessible(true);
}
项目:Mastering-Mesos    文件:CuratorServiceDiscoveryModule.java   
@Provides
@Singleton
@Exposed
ServiceGroupMonitor provideServiceGroupMonitor(
    CuratorFramework client,
    Codec<ServiceInstance> codec) {

  PathChildrenCache groupCache =
      new PathChildrenCache(client, discoveryPath, true /* cacheData */);
  return new CuratorServiceGroupMonitor(groupCache, MEMBER_SELECTOR, codec);
}
项目:Mastering-Mesos    文件:CommonsServiceDiscoveryModule.java   
@Provides
@Singleton
@Exposed
SingletonService provideSingletonService(
    ZooKeeperClient client,
    ServerSetImpl serverSet,
    @ServiceDiscoveryBindings.ZooKeeper List<ACL> zookeeperAcls) {

  return new SingletonServiceImpl(
      serverSet,
      SingletonServiceImpl.createSingletonCandidate(client, discoveryPath, zookeeperAcls));
}
项目:emodb    文件:SecurityModule.java   
@Provides
@Singleton
@Exposed
@Named("AdminKey")
String provideAdminKey(AuthorizationConfiguration config, ApiKeyEncryption encryption) {
    return configurationKeyAsPlaintext(config.getAdminApiKey(), encryption, "admin");
}
项目:miscellaneous    文件:Providers.java   
private EventualProvider<?> providerFor(Invokable<T, ?> method, Errors methodErrors) {
  Annotation[] annotations = method.getAnnotations();

  verifyMethodAccessibility(methodErrors, method, source);

  @Nullable Annotation bindingAnnotation =
      Annotations.findBindingAnnotation(methodErrors, method, annotations);

  verifyAbsenseOfScopeAnnotation(methodErrors, annotations, source);

  List<Dependency<ListenableFuture<?>>> dependencies =
      Lists.newArrayListWithCapacity(method.getParameters().size());

  for (Parameter parameter : method.getParameters()) {
    dependencies.add(extractDependency(methodErrors, parameter));
  }

  Key<ListenableFuture<?>> bindingKey;
  boolean exposedBinding = method.isAnnotationPresent(Exposed.class);

  if (isVoid(method)) {
    bindingKey = futureKey(TypeToken.of(Boolean.class), new BlackholedAnnotation());
    exposedBinding = false;
  } else {
    bindingKey = futureKey(method.getReturnType(), bindingAnnotation);
  }

  return new EventualProvider<>(
      method,
      exposedBinding,
      dependencies,
      bindingKey,
      scopeAnnotation,
      source);
}
项目:miscellaneous    文件:SampleEventuality.java   
@Exposed
@Eventually.Provides
@Named("separator")
String separator() {
  tracker.add(0);
  return ":";
}
项目:miscellaneous    文件:SampleEventuality.java   
@Exposed
@Eventually.Provides
@Named("output")
String output(
    @Named("first") String first,
    @Named("second") String second,
    @Named("separator") String separator) {
  tracker.add(3);
  return first + separator + second;
}
项目:LanternServer    文件:LanternModule.java   
@Exposed
@Named(DirectoryKeys.CONFIG)
@Provides
@Singleton
private Path provideConfigDirectory(@Option({ "config-directory", "config-dir" }) @Nullable Path configDir) {
    return configDir == null ? DirectoryKeys.DefaultValues.CONFIG : configDir;
}
项目:LanternServer    文件:LanternModule.java   
@Exposed
@Named(DirectoryKeys.CONFIG)
@Provides
@Singleton
private File provideConfigDirectoryAsFile(@Named(DirectoryKeys.CONFIG) Path configDir) {
    return configDir.toFile();
}
项目:LanternServer    文件:LanternModule.java   
@Exposed
@Named(DirectoryKeys.PLUGINS)
@Provides
@Singleton
private Path providePluginsDirectory(@Option({ "plugins-directory", "plugins-dir" }) @Nullable Path pluginsDir) {
    return pluginsDir == null ? DirectoryKeys.DefaultValues.PLUGINS : pluginsDir;
}
项目:LanternServer    文件:LanternModule.java   
@Exposed
@Named(DirectoryKeys.PLUGINS)
@Provides
@Singleton
private File providePluginsDirectoryAsFile(@Named(DirectoryKeys.PLUGINS) Path pluginsDir) {
    return pluginsDir.toFile();
}
项目:LanternServer    文件:LanternModule.java   
@Exposed
@Named(DirectoryKeys.ROOT_WORLD)
@Provides
@Singleton
private Path provideRootWorldDirectory(@Named(DirectoryKeys.ROOT) Path rootDir, GlobalConfig globalConfig) {
    return rootDir.resolve(globalConfig.getRootWorldFolder());
}
项目:LanternServer    文件:LanternModule.java   
@Exposed
@Named(DirectoryKeys.ROOT_WORLD)
@Provides
@Singleton
private File provideRootWorldDirectoryAsFile(@Named(DirectoryKeys.ROOT_WORLD) Path rootWorldDir) {
    return rootWorldDir.toFile();
}
项目:google-gin    文件:PrivateBasicTest.java   
@Provides @Exposed
public Card provideCard(List<Card> cards) {
  if (cards.isEmpty()) {
    return null;
  }
  return cards.remove(0);
}
项目:guice    文件:ModuleAnnotatedMethodScannerTest.java   
public void testPrivateModuleScannersDontImpactSiblings_usingPrivateModule() {
  Injector injector =
      Guice.createInjector(
          new PrivateModule() {
            @Override
            protected void configure() {
              install(NamedMunger.module());
            }

            @Exposed
            @TestProvides
            @Named("foo")
            String foo() {
              return "foo";
            }
          },
          new PrivateModule() {
            @Override
            protected void configure() {}

            // ignored! (because the scanner doesn't run over this module)
            @Exposed
            @TestProvides
            @Named("foo")
            String foo() {
              return "foo";
            }
          });
  assertMungedBinding(injector, String.class, "foo", "foo");
}
项目:agathon    文件:Ec2SecurityGroupModule.java   
@Provides @Exposed @Singleton @Named(SecurityGroupModule.SECURITY_GROUP_DATACENTERS_PROPERTY)
Function<CassandraInstance, String> provideDataCenterTransform() {
  return new Function<CassandraInstance, String>() {
    @Override
    public String apply(CassandraInstance instance) {
      // Transform from Cassandra DataCenter/Rack to AWS Region
      // Assumes the {@link Ec2Snitch} or {@link Ec2MultiRegionSnitch}
      // For example, DC: "us-east", Rack: "1a" => Region: "us-east-1"
      return instance.getDataCenter() + "-" + instance.getRack().substring(0, 1);
    }
  };
}
项目:guice-old    文件:ProviderMethod.java   
/**
 * @param method the method to invoke. It's return type must be the same type as {@code key}.
 */
ProviderMethod(Key<T> key, Method method, Object instance,
    ImmutableSet<Dependency<?>> dependencies, List<Provider<?>> parameterProviders,
    Class<? extends Annotation> scopeAnnotation) {
  this.key = key;
  this.scopeAnnotation = scopeAnnotation;
  this.instance = instance;
  this.dependencies = dependencies;
  this.method = method;
  this.parameterProviders = parameterProviders;
  this.exposed = method.isAnnotationPresent(Exposed.class);

  method.setAccessible(true);
}
项目:google-guice    文件:ProviderMethod.java   
/**
 * @param method the method to invoke. It's return type must be the same type as {@code key}.
 */
ProviderMethod(Key<T> key, Method method, Object instance,
    ImmutableSet<Dependency<?>> dependencies, List<Provider<?>> parameterProviders,
    Class<? extends Annotation> scopeAnnotation) {
  this.key = key;
  this.scopeAnnotation = scopeAnnotation;
  this.instance = instance;
  this.dependencies = dependencies;
  this.method = method;
  this.parameterProviders = parameterProviders;
  this.exposed = method.isAnnotationPresent(Exposed.class);

  method.setAccessible(true);
}
项目:Mastering-Mesos    文件:CuratorServiceDiscoveryModule.java   
@Provides
@Singleton
@Exposed
SingletonService provideSingletonService(CuratorFramework client, Codec<ServiceInstance> codec) {
  return new CuratorSingletonService(client, discoveryPath, MEMBER_TOKEN, codec);
}
项目:emodb    文件:DataStoreModule.java   
@Provides @Singleton @Exposed @DatabusClusterInfo
Collection<ClusterInfo> provideCassandraClusterInfo(Collection<ClusterInfo> clusterInfos) {
    return clusterInfos;
}
项目:miscellaneous    文件:CompletedFutureModuleTest.java   
@Exposed
@Eventually.Provides
Integer integer() {
  return 1;
}
项目:miscellaneous    文件:CompletedFutureModuleTest.java   
@Exposed
@Eventually.Provides
String string() {
  return "a";
}
项目:miscellaneous    文件:SampleEventuality.java   
@Exposed
@Eventually.Provides
ListenableFuture<Boolean> getInput(@Named("input") String input) {
  tracker.add(1);
  return Futures.immediateFuture(Boolean.parseBoolean(input));
}
项目:LanternServer    文件:LanternModule.java   
@Exposed
@Provides
@Singleton
private org.apache.logging.log4j.Logger provideSlf4jAsLog4jLogger(Logger logger) {
    return LogManager.getLogger(logger.getName());
}
项目:LanternServer    文件:LanternModule.java   
@Exposed
@Provides
@Singleton
private LanternCommandManager provideCommandManager(Logger logger, LanternGame game) {
    return new LanternCommandManager(logger, new LanternCommandDisambiguator(game));
}
项目:google-gin    文件:PrivateFactoryTest.java   
@Provides @Named("orange") @Singleton @Exposed
Widget provideOrangeWidget(WidgetFactory factory) {
  return factory.createWidget("orange");
}
项目:google-gin    文件:PrivateFactoryTest.java   
@Provides @Exposed
WidgetPair provideWidgetPair(@Named("banana") Widget banana, @Named("orange") Widget orange) {
  return new WidgetPair(banana, orange);
}
项目:guice    文件:CheckedProviderMethodsModuleTest.java   
@CheckedProvides(RpcProvider.class)
@Named("fruit")
@Exposed
String provideApples() {
  return "apple";
}