當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。