本文整理汇总了Java中com.google.inject.matcher.Matchers类的典型用法代码示例。如果您正苦于以下问题:Java Matchers类的具体用法?Java Matchers怎么用?Java Matchers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Matchers类属于com.google.inject.matcher包,在下文中一共展示了Matchers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_interceptor
import com.google.inject.matcher.Matchers; //导入依赖的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);
}
示例2: configure
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
@Override
protected void configure() {
bind(MotTestReadService.class).to(MotTestReadServiceDatabase.class);
bind(VehicleReadService.class).to(VehicleReadServiceDatabase.class);
bind(TradeReadService.class).to(TradeReadServiceDatabase.class);
bind(MotrReadService.class).to(MotrReadServiceDatabase.class);
bind(TradeReadDao.class).to(TradeReadDaoJdbc.class);
bind(MotTestReadDao.class).to(MotTestReadDaoJdbc.class);
bind(VehicleReadDao.class).to(VehicleReadDaoJdbc.class);
bind(ConnectionManager.class).in(Singleton.class);
DbConnectionInterceptor dbConnectionInterceptor = new DbConnectionInterceptor();
requestInjection(dbConnectionInterceptor);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(ProvideDbConnection.class),
dbConnectionInterceptor);
}
示例3: bindMethodInterceptorForStringTemplateClassLoaderWorkaround
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
private void bindMethodInterceptorForStringTemplateClassLoaderWorkaround() {
bindInterceptor(Matchers.subclassesOf(JDBIHistoryManager.class), Matchers.any(), new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
}
try {
return invocation.proceed();
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
});
}
示例4: bindJNIContextClassLoader
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
/**
* Binds an interceptor that ensures the main ClassLoader is bound as the thread context
* {@link ClassLoader} during JNI callbacks from mesos. Some libraries require a thread
* context ClassLoader be set and this ensures those libraries work properly.
*
* @param binder The binder to use to register an interceptor with.
* @param wrapInterface Interface whose methods should wrapped.
*/
public static void bindJNIContextClassLoader(Binder binder, Class<?> wrapInterface) {
final ClassLoader mainClassLoader = GuiceUtils.class.getClassLoader();
binder.bindInterceptor(
Matchers.subclassesOf(wrapInterface),
interfaceMatcher(wrapInterface, false),
new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
Thread currentThread = Thread.currentThread();
ClassLoader prior = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(mainClassLoader);
return invocation.proceed();
} finally {
currentThread.setContextClassLoader(prior);
}
}
});
}
示例5: bindExceptionTrap
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
/**
* Binds an exception trap on all interface methods of all classes bound against an interface.
* Individual methods may opt out of trapping by annotating with {@link AllowUnchecked}.
* Only void methods are allowed, any non-void interface methods must explicitly opt out.
*
* @param binder The binder to register an interceptor with.
* @param wrapInterface Interface whose methods should be wrapped.
* @throws IllegalArgumentException If any of the non-whitelisted interface methods are non-void.
*/
public static void bindExceptionTrap(Binder binder, Class<?> wrapInterface)
throws IllegalArgumentException {
Set<Method> disallowed = ImmutableSet.copyOf(Iterables.filter(
ImmutableList.copyOf(wrapInterface.getMethods()),
Predicates.and(Predicates.not(IS_WHITELISTED), Predicates.not(VOID_METHOD))));
Preconditions.checkArgument(disallowed.isEmpty(),
"Non-void methods must be explicitly whitelisted with @AllowUnchecked: " + disallowed);
Matcher<Method> matcher =
Matchers.not(WHITELIST_MATCHER).and(interfaceMatcher(wrapInterface, false));
binder.bindInterceptor(Matchers.subclassesOf(wrapInterface), matcher,
new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
try {
return invocation.proceed();
} catch (RuntimeException e) {
LOG.warn("Trapped uncaught exception: " + e, e);
return null;
}
}
});
}
示例6: replayAndInitialize
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
private void replayAndInitialize() {
expect(statsProvider.makeCounter(SHIRO_AUTHORIZATION_FAILURES))
.andReturn(new AtomicLong());
expect(statsProvider.makeCounter(SHIRO_BAD_REQUESTS))
.andReturn(new AtomicLong());
control.replay();
decoratedThrift = Guice
.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Subject.class).toInstance(subject);
MockDecoratedThrift.bindForwardedMock(binder(), thrift);
bindInterceptor(
Matchers.subclassesOf(AnnotatedAuroraAdmin.class),
HttpSecurityModule.AURORA_SCHEDULER_MANAGER_SERVICE,
interceptor);
bind(StatsProvider.class).toInstance(statsProvider);
requestInjection(interceptor);
}
}).getInstance(AnnotatedAuroraAdmin.class);
}
示例7: setUp
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
@Before
public void setUp() {
statsInterceptor = new ThriftStatsExporterInterceptor();
realThrift = createMock(AnnotatedAuroraAdmin.class);
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
MockDecoratedThrift.bindForwardedMock(binder(), realThrift);
AopModule.bindThriftDecorator(
binder(),
Matchers.annotatedWith(DecoratedThrift.class),
statsInterceptor);
}
});
decoratedThrift = injector.getInstance(AnnotatedAuroraAdmin.class);
}
示例8: setUp
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
@Before
public void setUp() {
interceptor = new ServerInfoInterceptor();
realThrift = createMock(AnnotatedAuroraAdmin.class);
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
MockDecoratedThrift.bindForwardedMock(binder(), realThrift);
bind(IServerInfo.class).toInstance(SERVER_INFO);
AopModule.bindThriftDecorator(
binder(),
Matchers.annotatedWith(DecoratedThrift.class),
interceptor);
}
});
decoratedThrift = injector.getInstance(AnnotatedAuroraAdmin.class);
}
示例9: configure
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
@Override
protected void configure() {
bind(ReportEntryLogger.class).to(ReportEntryLoggerImpl.class);
bind(TestEventCollector.class).to(TestEventCollectorImpl.class);
bind(ReportingHandler.ACTIVE_REPORTERS).toProvider(ReporterProvider.class).in(Singleton.class);
SubreportInterceptor subreportInterceptor = new SubreportInterceptor();
requestInjection(subreportInterceptor);
bindInterceptor(Matchers.any(), Matchers.annotatedWith(Subreport.class), subreportInterceptor);
Multibinder<WebDriverEventListener> webDriverListenerBinder = Multibinder.newSetBinder(binder(),
WebDriverEventListener.class);
webDriverListenerBinder.addBinding().to(WebDriverLogger.class);
Multibinder<ProxyEventListener> proxyListenerBinder = Multibinder.newSetBinder(binder(),
ProxyEventListener.class);
proxyListenerBinder.addBinding().to(ProxyLogger.class);
}
示例10: configure
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
/**
* @see com.google.inject.AbstractModule#configure()
*/
@Override
protected void configure() {
logger.info("NinjaQuartz Module initialising.");
// disable Quartz' checking for updates
System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true");
bind(SchedulerFactory.class).toProvider(QuartzSchedulerFactoryProvider.class).in(Singleton.class);
NinjaQuartzScheduleHelper scheduleHelper = new NinjaQuartzScheduleHelper();
requestInjection(scheduleHelper);
bindListener(Matchers.any(), new NinjaQuartzTypeListener(scheduleHelper));
bind(NinjaQuartzScheduleHelper.class).toInstance(scheduleHelper);
bind(NinjaQuartzUtil.class).to(NinjaQuartzUtilImpl.class);
logger.info("NinjaQuartz Module initialisation completed.");
}
示例11: bindInterceptors
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
private void bindInterceptors() {
Instrumentor instrumentor = new Instrumentor(
metricRegistry,
healthCheckRegistry,
exceptionFilter
);
bindInterceptor(
Matchers.annotatedWith(Instrumented.class),
Matchers.not(Matchers.annotatedWith(Instrumented.class)), // in case of both, defer to method annotation
InstrumentingInterceptor.ofClasses(instrumentor)
);
bindInterceptor(
Matchers.any(),
Matchers.annotatedWith(Instrumented.class),
InstrumentingInterceptor.ofMethods(instrumentor)
);
}
示例12: configure
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
/**
* Performs concrete bindings for interfaces
* @see com.google.inject.AbstractModule#configure()
*/
@Override
protected void configure() {
//bind entity classes
bind(AuditDAO.class).to(AuditDAOImpl.class).in(Singleton.class);
bind(EventsDAO.class).to(EventsDAOImpl.class).in(Singleton.class);
bind(StateMachinesDAO.class).to(StateMachinesDAOImpl.class).in(Singleton.class);
bind(StatesDAO.class).to(StatesDAOImpl.class).in(Singleton.class);
//bind Transactional Interceptor to intercept methods which are annotated with javax.transaction.Transactional
Provider<SessionFactoryContext> provider = getProvider(Key.get(SessionFactoryContext.class, Names.named("fluxSessionFactoryContext")));
final TransactionInterceptor transactionInterceptor = new TransactionInterceptor(provider);
bindInterceptor(Matchers.not(Matchers.inPackage(MessageDao.class.getPackage())), Matchers.annotatedWith(Transactional.class), transactionInterceptor);
bindInterceptor(Matchers.not(Matchers.inPackage(EventSchedulerDao.class.getPackage())), Matchers.annotatedWith(Transactional.class), transactionInterceptor);
}
示例13: configure
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
@Override
protected void configure() {
bindInterceptor(Matchers.any(), new AbstractMatcher<Method>() {
@Override
public boolean matches(Method method) {
return getAuthAnnotations(method.getAnnotations()).isPresent();
}
}, new MethodInterceptor() {
@Override
public Object invoke(MethodInvocation ctx) throws Throwable {
Optional<Auth> methodAnnotation = getAuthAnnotations(ctx.getMethod().getAnnotations());
boolean allowAnon = methodAnnotation.map(Auth::pass).orElse(true);
if (!allowAnon) {
throw new Exception("Access denied");
}
return ctx.proceed();
}
});
}
示例14: testCachedInScopePreventsProvisionNotify
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
public void testCachedInScopePreventsProvisionNotify() {
final Counter count1 = new Counter();
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindListener(Matchers.any(), count1);
bind(Foo.class).in(Scopes.SINGLETON);
}
});
Foo foo = injector.getInstance(Foo.class);
assertNotNull(foo);
assertEquals(1, count1.count);
// not notified the second time because nothing is provisioned
// (it's cached in the scope)
count1.count = 0;
assertSame(foo, injector.getInstance(Foo.class));
assertEquals(1, count1.count);
}
示例15: testNotifyEarlyListenersIfFailBeforeProvision
import com.google.inject.matcher.Matchers; //导入依赖的package包/类
public void testNotifyEarlyListenersIfFailBeforeProvision() {
final Counter count1 = new Counter();
final Counter count2 = new Counter();
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bindListener(Matchers.any(), count1, new FailBeforeProvision(),
count2);
}
});
try {
injector.getInstance(Foo.class);
fail();
} catch (SaltaException e) {
if (!e.getMessage().contains("boo"))
throw e;
}
}