当前位置: 首页>>代码示例>>Java>>正文


Java Module类代码示例

本文整理汇总了Java中com.google.inject.Module的典型用法代码示例。如果您正苦于以下问题:Java Module类的具体用法?Java Module怎么用?Java Module使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Module类属于com.google.inject包,在下文中一共展示了Module类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import com.google.inject.Module; //导入依赖的package包/类
/**
 * @see org.junit.rules.MethodRule#apply(org.junit.runners.model.Statement, org.junit.runners.model.FrameworkMethod, java.lang.Object)
 */
@Override
public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      final List<Module> moduleWithTarget = new ArrayList<>(Arrays.asList(modules));
      if (target instanceof Module) {
        moduleWithTarget.add((Module) target);
      }
      Guice.createInjector(moduleWithTarget).injectMembers(target);
      try {
        base.evaluate();
      } finally {
        new ThreadSafeMockingProgress().reset();
      }
    }
  };
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:22,代码来源:InjectMembersRule.java

示例2: doWork

import com.google.inject.Module; //导入依赖的package包/类
@Override
protected Injector doWork() throws Exception
{
	long start = System.currentTimeMillis();
	Iterable<URL> localClassPath = privatePluginService.getLocalClassPath(pluginId);
	final ClassLoader classLoader = privatePluginService.getClassLoader(pluginId);
	Collection<Parameter> params = extension.getParameters("class");
	List<Module> modules = new ArrayList<Module>();
	for( Parameter param : params )
	{
		Module module = (Module) privatePluginService.getBean(pluginId, param.valueAsString());
		modules.add(module);
	}

	modules.add(new ScannerModule(privatePluginService, classLoader, localClassPath, getBeanCheckers()));
	modules.add(new Jsr250Module());
	injector = Guice.createInjector(new ExternalProviders(getDependents(), modules));
	long end = System.currentTimeMillis();
	LOGGER.info("Guice module for " + pluginId + " took:" + (end - start));
	return injector;
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:GuicePlugin.java

示例3: withCompute

import com.google.inject.Module; //导入依赖的package包/类
private <T> T withCompute(ComputeTask<T> task) throws HekateException {
    ContextBuilder builder = ContextBuilder.newBuilder(provider)
        .credentialsSupplier(credentials::get)
        .modules(ImmutableSet.<Module>of(new SLF4JLoggingModule()));

    if (!properties.isEmpty()) {
        builder.overrides(properties);
    }

    if (endpoint != null && !endpoint.trim().isEmpty()) {
        builder.endpoint(endpoint.trim());
    }

    try (ComputeServiceContext ctx = builder.buildView(ComputeServiceContext.class)) {
        return task.execute(ctx);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:18,代码来源:CloudSeedNodeProvider.java

示例4: ifCommmandIsInvalidResponseExceptionIsThrown

import com.google.inject.Module; //导入依赖的package包/类
@Test
public void ifCommmandIsInvalidResponseExceptionIsThrown() throws IOException, URISyntaxException {
    String command = "invalid";
    Map<String, Object> opts = new HashMap<>();
    opts.put(BROWSER, CHROME);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(CASE, caseFile.getAbsolutePath());
    opts.put(SCREEN, screenString);
    opts.put(TIMEOUT, timeoutString);
    opts.put(PRECISION, precisionString);
    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);

    try {
        IOProvider<ResponseFilter> instance = injector.getInstance(new Key<IOProvider<ResponseFilter>>() {});
        instance.get();
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof NoSuchCommandException);
    }
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:23,代码来源:DefaultModuleTest.java

示例5: ifCommmandIsInvalidExceptionIsThrown

import com.google.inject.Module; //导入依赖的package包/类
@Test
public void ifCommmandIsInvalidExceptionIsThrown() throws IOException, URISyntaxException {
    String command = "invalid";
    Map<String, Object> opts = new HashMap<>();
    opts.put(BROWSER, CHROME);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(CASE, caseFile.getAbsolutePath());
    opts.put(SCREEN, screenString);
    opts.put(TIMEOUT, timeoutString);
    opts.put(PRECISION, precisionString);
    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);

    try {
        RequestFilter instance = injector.getInstance(
                Key.get(new TypeLiteral<IOProvider<RequestFilter>>() {})).get();
    } catch (ProvisionException e) {
        assertTrue(e.getCause() instanceof NoSuchCommandException);
    }
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:23,代码来源:DefaultModuleTest.java

示例6: createModule

import com.google.inject.Module; //导入依赖的package包/类
@Override
public Module createModule(ITestContext context, Class<?> testClass){

	Module globalModule = new AbstractModule(){

		@Override
		protected void configure(){
			for(Module module : modules){
				install(module);
			}
		}

	};
	Iterable<? extends Module> overriders = getOverriders();
	return Modules.override(globalModule).with(overriders);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:17,代码来源:ModuleFactory.java

示例7: newApplication

import com.google.inject.Module; //导入依赖的package包/类
@Override public Application<ServerConfiguration> newApplication() {

              return new ServerMain("outland.feature.server") {

                @Override
                protected List<Module> addModules(
                    ServerConfiguration configuration, Environment environment) {
                  return Lists.newArrayList(
                      new ServerModule(configuration),
                      new HystrixModule(),
                      new RedisModule(configuration.redis),
                      new DynamoDbModule(configuration.aws),
                      new AuthModule(configuration.auth),
                      new TestFeatureServiceModule(),
                      new TestGroupModule()
                  );
                }
              };
            }
 
开发者ID:dehora,项目名称:outland,代码行数:20,代码来源:ServerSuite.java

示例8: canCreateReplayBrowserProvider

import com.google.inject.Module; //导入依赖的package包/类
@Test
public void canCreateReplayBrowserProvider() throws IOException, URISyntaxException {
    String command = REPLAY;
    Map<String, Object> opts = new HashMap<>();
    opts.put(BROWSER, CHROME);
    opts.put(DRIVER, chromedriverFile.getAbsolutePath());
    opts.put(APPLICATION, configurationFile.getAbsolutePath());
    opts.put(URL, localhostUrl);
    opts.put(CASE, caseFile.getAbsolutePath());
    opts.put(SCREEN, screenString);
    opts.put(TIMEOUT, timeoutString);
    opts.put(PRECISION, precisionString);

    Module module = new DefaultModule(command, opts);
    Injector injector = Guice.createInjector(module);
    IOURIProvider<ReplayBrowser> instance = injector.getInstance(new Key<IOURIProvider<ReplayBrowser>>() {});

    ReplayBrowser replayBrowser = instance.get();
    replayBrowser.forceCleanUp();
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:21,代码来源:DefaultModuleTest.java

示例9: initializeGuice_ProvideNullListViaExtendingService_NoProblem

import com.google.inject.Module; //导入依赖的package包/类
@Test
public void initializeGuice_ProvideNullListViaExtendingService_NoProblem() throws Exception {
    // given
    final AbstractService service = new AbstractService() {
        @Override
        public void displayHelp(PrintStream out) {

        }

        @Override
        protected List<Module> getGuiceModules() {
            return null;
        }
    };

    // when
    service.initializeGuice();

    // then
    // no exception should be raised
    assertThat(service.injector).isNotNull();
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:23,代码来源:AbstractServiceTest_initializeGuice.java

示例10: test_interceptor

import com.google.inject.Module; //导入依赖的package包/类
@Test
public void test_interceptor() throws ClassNotFoundException {
    Injector injector = Guice.createInjector((Module) binder -> binder.bindInterceptor(
        Matchers.identicalTo(TestedRpcHandler.class),
        Matchers.any(),
        new RpcHandlerMethodInterceptor()
    ));

    TestedRpcHandler methodHandler
        = injector.getInstance(TestedRpcHandler.class);
    methodHandler.handleRequest(RpcEnvelope.Request.newBuilder().build(), new OrangeContext());

    SameGuiceModuleAssertionOnInterceptorInvokation sameGuiceModuleAssertionOnInterceptorInvokation
        = injector.getInstance(SameGuiceModuleAssertionOnInterceptorInvokation.class);
    sameGuiceModuleAssertionOnInterceptorInvokation.test_that_intercepted_rpc_handler_still_verified();

    assertThat(ReflectionUtil.findSubClassParameterType(methodHandler, 0)).
        isEqualTo(RpcEnvelope.Request.class);
    assertThat(ReflectionUtil.findSubClassParameterType(methodHandler, 1)).
        isEqualTo(RpcEnvelope.Response.class);
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:22,代码来源:TestHandlerInterception.java

示例11: setUp

import com.google.inject.Module; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  final RMContext mockRMContext =
      TestRMWebApp.mockRMContext(3, numberOfRacks, numberOfNodesPerRack,
        8 * TestRMWebApp.GiB);
  injector =
      WebAppTests.createMockInjector(RMContext.class, mockRMContext,
        new Module() {
          @Override
          public void configure(Binder binder) {
            try {
              binder.bind(ResourceManager.class).toInstance(
                TestRMWebApp.mockRm(mockRMContext));
            } catch (IOException e) {
              throw new IllegalStateException(e);
            }
          }
        });
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestNodesPage.java

示例12: bindingModule

import com.google.inject.Module; //导入依赖的package包/类
public Module bindingModule() {
    return new KeyedManifest.Impl(method) {
        @Override
        public void configure() {
            final Binder binder = binder().withSource(method);
            if(!hasReturnValue()) {
                binder.addError("Cannot bind this method as a provider because it does not return a value");
                return;
            }

            install(InjectableMethod.this);

            final ScopedBindingBuilder builder = binder.bind(providedKey).toProvider(asProvider());
            if(scope != null) builder.in(scope);
        }
    };
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:18,代码来源:InjectableMethod.java

示例13: createInjector

import com.google.inject.Module; //导入依赖的package包/类
protected Injector createInjector(String language) {
	try {
		Module runtimeModule = getRuntimeModule(language);
		Module sharedStateModule = getSharedStateModule();
		Module uiModule = getUiModule(language);
		Module mergedModule = Modules2.mixin(runtimeModule, sharedStateModule, uiModule);
		return Guice.createInjector(mergedModule);
	} catch (Exception e) {
		logger.error("Failed to create injector for " + language);
		logger.error(e.getMessage(), e);
		throw new RuntimeException("Failed to create injector for " + language, e);
	}
}
 
开发者ID:rehne93,项目名称:pokemon-tcgo-deck-generator,代码行数:14,代码来源:PkmntcgoActivator.java

示例14: testFairSchedulerWebAppPage

import com.google.inject.Module; //导入依赖的package包/类
@Test
public void testFairSchedulerWebAppPage() {
  List<RMAppState> appStates = Arrays.asList(RMAppState.NEW,
      RMAppState.NEW_SAVING, RMAppState.SUBMITTED);
  final RMContext rmContext = mockRMContext(appStates);
  Injector injector = WebAppTests.createMockInjector(RMContext.class,
      rmContext,
      new Module() {
        @Override
        public void configure(Binder binder) {
          try {
            ResourceManager mockRmWithFairScheduler =
                mockRm(rmContext);
            binder.bind(ResourceManager.class).toInstance
                (mockRmWithFairScheduler);
            binder.bind(ApplicationBaseProtocol.class).toInstance(
              mockRmWithFairScheduler.getClientRMService());
          } catch (IOException e) {
            throw new IllegalStateException(e);
          }
        }
      });
  FairSchedulerPage fsViewInstance = injector.getInstance(FairSchedulerPage
      .class);
  fsViewInstance.render();
  WebAppTests.flushOutput(injector);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:TestRMWebAppFairScheduler.java

示例15: testThreadingModule

import com.google.inject.Module; //导入依赖的package包/类
private Module testThreadingModule( ) {
    return new AbstractModule( ) {
        @Override
        protected void configure( ) {
            bind( ExecutorService.class ).toInstance( MoreExecutors.sameThreadExecutor( ) );
            bind( ScheduledExecutorService.class ).toInstance( newScheduledThreadPool( Runtime.getRuntime( ).availableProcessors( ) ) );
        }
    };
}
 
开发者ID:u2032,项目名称:wall-t,代码行数:10,代码来源:ApiControllerTest.java


注:本文中的com.google.inject.Module类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。