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