ServicesClientAPIBootstrapGuiceModuleBase.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:r01fb 作者:
/**
 * Binds the {@link ServiceProxiesAggregator} that MUST contain fields of types implementing {@link ServiceInterface} which are 
 * the concrete proxy implementation to the services
 * 
 * The {@link ServiceInterface} fields of {@link ServiceProxiesAggregator} implementing type are LAZY loaded by 
 * {@link ServicesClientProxyLazyLoaderGuiceMethodInterceptor} which guesses what proxy implementation assign to the field:
 * <ul>
 *      <li>If the {@link ServiceProxiesAggregator} extends {@link ServiceProxiesAggregatorForDefaultImpls}, the concrete {@link ServiceInterface}-implementing 
 *          proxy instance is taken from the client properties XML file, so some service impls might be accessed using a BEAN proxy while others might be accessed
 *          using a REST proxy -depending on the properties file-</li>
 *      <li>If the {@link ServiceInterface} field's BEAN implementation is available this one will be assigned to the field no matter what type the aggregator is</li>
 * </ul>
 * @param binder
 */
private void _bindServiceProxiesAggregators(final Binder binder) {
    // Inject all Map fields that matches the service interface types with the bean impl or proxy to be used
    // (this Map fields are injected by MapBinders created at ServicesForAppModulePrivateGuiceModule)                                   
    binder.requestInjection(_serviceInterfaceTypesToImplOrProxyMappings);

    // Create a private binder to be used to inject the MethodInterceptor that will intercept all fine-grained
    // proxy accessor method calls at ServicesAggregatorClientProxy 
    // The interceptor lazily loads the fine-grained proxy instances and makes the aggregator creation simpler
    PrivateBinder privateBinder = binder.newPrivateBinder();
    privateBinder.bind(ServiceInterfaceTypesToImplOrProxyMappings.class)
                 .toInstance(_serviceInterfaceTypesToImplOrProxyMappings);
    MethodInterceptor serviceProxyGetterInterceptor = new ServicesClientProxyLazyLoaderGuiceMethodInterceptor(_apiAppAndModule,
                                                                                                              _coreAppAndModules);
    privateBinder.requestInjection(serviceProxyGetterInterceptor);      // the method interceptor is feeded with a map of service interfaces to bean impl or proxy created below

    // Bind the interceptor to ServiceProxiesAggregator type's fine-grained method calls
    binder.bindInterceptor(Matchers.subclassesOf(ServiceProxiesAggregator.class),
                           Matchers.any(),
                           serviceProxyGetterInterceptor);

    // Bind every services proxy aggregator implementation
    log.info("[ServiceProxyAggregator] > {}",_servicesProxiesAggregatorType);
    binder.bind(_servicesProxiesAggregatorType)
          .in(Singleton.class);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号