企业搜索引擎开发之连接器connector(十三)

本文深入分析了ConnectorInterfaces类的源代码,该类为ConnectorCoordinatorImpl提供访问连接器所需的依赖类,如AuthenticationManager、AuthorizationManager及TraversalManager等。文章详细解释了这些依赖类的构造过程及其异常处理方式。

本文分析一下ConnectorInterfaces类的代码,该类主要提供了访问连接器的相关依赖类的一下方法,供ConnectorCoordinatorImpl类调用,其源码如下:

/**
 * Access to the AuthenticationManager, AuthorizationManager, and
 * TraversalManagager for a Connector instance.
 */
public class ConnectorInterfaces {

  private final String connectorName;
  private final Connector connector;

  // these are lazily constructed
  private TraversalManager traversalManager;
  private AuthenticationManager authenticationManager;
  private AuthorizationManager authorizationManager;

  ConnectorInterfaces(String connectorName, Connector connector) {
    this.connectorName = connectorName;
    this.connector = connector;
  }

  /**
   * Constructs a ConnectorIntefaces with Managers supplied by the caller
   * rather than the connector. This is for testing only.
   */
  ConnectorInterfaces(String connectorName, TraversalManager traversalManager,
                      AuthenticationManager authenticationManager,
                      AuthorizationManager authorizationManager) {
    this.connectorName = connectorName;
    this.connector = null;
    this.traversalManager = traversalManager;
    this.authenticationManager = authenticationManager;
    this.authorizationManager = authorizationManager;
  }

  /**
   * @return the authenticationManager
   * @throws InstantiatorException
   */
  AuthenticationManager getAuthenticationManager() throws InstantiatorException {
    if (authenticationManager == null) {
      Session s = getSession();
      try {
        authenticationManager = s.getAuthenticationManager();
      } catch (RepositoryException e) {
        // TODO(ziff): think about how this could be re-tried
        throw new InstantiatorException(e);
      } catch (Exception e) {
        throw new InstantiatorException(e);
      }
    }
    return authenticationManager;
  }

  /**
   * @return the authorizationManager
   * @throws InstantiatorException
   */
  AuthorizationManager getAuthorizationManager() throws InstantiatorException {
    if (authorizationManager == null) {
      Session s = getSession();
      try {
        authorizationManager = s.getAuthorizationManager();
      } catch (RepositoryException e) {
        // TODO(ziff): think about how this could be re-tried
        throw new InstantiatorException(e);
      } catch (Exception e) {
        throw new InstantiatorException(e);
      }
    }
    return authorizationManager;
  }

  /**
   * @return the connector
   */
  // TODO(strellis) Remove this method or make it private so all connector
  // access is through InstanceInfo.
  Connector getConnector() {
    return connector;
  }

  /**
   * @return the connectorName
   */
  String getConnectorName() {
    return connectorName;
  }

  /**
   * @return the traverser
   * @throws InstantiatorException
   */
  TraversalManager getTraversalManager() throws InstantiatorException {
    if (traversalManager == null) {
      Session s = getSession();
      try {
        traversalManager = s.getTraversalManager();
      } catch (RepositoryException ie) {
        throw new InstantiatorException(ie);
      } catch (Exception e) {
        throw new InstantiatorException(e);
      }
    }
    return traversalManager;
  }

  private Session getSession() throws InstantiatorException {
    Session s = null;
    try {
      s = connector.login();
    } catch (RepositoryLoginException e) {
      // this is un-recoverable
      throw new InstantiatorException(e);
    } catch (RepositoryException e) {
      // for this one, we could try again later
      // TODO(ziff): think about how this could be re-tried
      throw new InstantiatorException(e);
    } catch (Exception e) {
      throw new InstantiatorException(e);
    }
    return s;
  }

}

 可以看到,连接器的相关TraversalManager对象是通过这里获取的,该类源码容易读懂,我不解释了

本系列企业搜索引擎开发之连接器connector系本人原创

转载请注明出处 博客园 刺猬的温驯

本文链接http://www.cnblogs.com/chenying99/archive/2013/03/20/2970354.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值