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


Java Matchers类代码示例

本文整理汇总了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);
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:22,代码来源:TestHandlerInterception.java

示例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);
}
 
开发者ID:dvsa,项目名称:mot-public-api,代码行数:19,代码来源:DependencyResolver.java

示例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);
      }
    }
  });
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:20,代码来源:SingularityHistoryModule.java

示例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);
          }
        }
      });
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:28,代码来源:GuiceUtils.java

示例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;
          }
        }
      });
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:34,代码来源:GuiceUtils.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:22,代码来源:ShiroAuthorizingParamInterceptorTest.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:17,代码来源:ThriftStatsExporterInterceptorTest.java

示例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);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:18,代码来源:ServerInfoInterceptorTest.java

示例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);

}
 
开发者ID:Cognifide,项目名称:bobcat,代码行数:20,代码来源:ReporterModule.java

示例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.");
}
 
开发者ID:FendlerConsulting,项目名称:ninja-quartz,代码行数:23,代码来源:NinjaQuartzModule.java

示例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)
    );

}
 
开发者ID:sproutsocial,项目名称:instrumentor,代码行数:21,代码来源:InstrumentedAnnotations.java

示例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);
}
 
开发者ID:flipkart-incubator,项目名称:flux,代码行数:20,代码来源:HibernateModule.java

示例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();
        }
    });
}
 
开发者ID:advantageous,项目名称:qbit-extensions,代码行数:25,代码来源:AuthorizedGuiceModule.java

示例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);
}
 
开发者ID:ruediste,项目名称:salta,代码行数:20,代码来源:ProvisionListenerTest.java

示例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;
    }
}
 
开发者ID:ruediste,项目名称:salta,代码行数:19,代码来源:ProvisionListenerTest.java


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