本文整理匯總了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();
}
}
};
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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()
);
}
};
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
}
});
}
示例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);
}
};
}
示例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);
}
}
示例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);
}
示例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( ) ) );
}
};
}