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


    本文分析一下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

  • 相关阅读:
    hdu find the most comfortable road(贪心+并查集)
    hdu 迷瘴(贪心)
    Excel中指定的sheet名称或索引读取数据到DataTable
    SQLServer 批量插入数据的两种方法
    javascript基础教程3
    Enterprise Library 4.1学习笔记 配置应用程序块(c/s和b/s均适用)
    关于同一用户不能同时在两台电脑上登录问题的解决方案
    获取当天为一年中的第几周
    javascript基础教程4
    Excel导出方法选择(转自gwf25sz)
  • 原文地址:https://www.cnblogs.com/chenying99/p/2970354.html
Copyright © 2020-2023  润新知