Azkaban的Web Server源码探究系列4: Azkaban Server初始化

上一节做了准备工作,现在开始初始化Azkaban的Web Server.

---------------------------------------------------------------------------------------------------------

第一步就是初始化Velocity的实例

velocityEngine =

        configureVelocityEngine(props

            .getBoolean(VELOCITY_DEV_MODE_PARAM, false));//

 

具体的初始化代码如下:

 

/**

   * Creates and configures the velocity engine.

   *

   * @param  devMode

   * @return

   */

  private VelocityEngine configureVelocityEngine(final boolean devMode) {//

    VelocityEngine engine = new VelocityEngine();//org.apache.velocity.app.VelocityEngine

    engine.setProperty("resource.loader", "classpath, jar");

    engine.setProperty("classpath.resource.loader.class",

        ClasspathResourceLoader.class.getName());

    engine.setProperty("classpath.resource.loader.cache", !devMode);

    engine.setProperty("classpath.resource.loader.modificationCheckInterval",

        5L);//

    engine.setProperty("jar.resource.loader.class",

        JarResourceLoader.class.getName());

    engine.setProperty("jar.resource.loader.cache", !devMode);

    engine.setProperty("resource.manager.logwhenfound", false);

    engine.setProperty("input.encoding", "UTF-8");

    engine.setProperty("output.encoding", "UTF-8");

    engine.setProperty("directive.set.null.allowed", true);

    engine.setProperty("resource.manager.logwhenfound", false);

    engine.setProperty("velocimacro.permissions.allow.inline", true);

    engine.setProperty("velocimacro.library.autoreload", devMode);

    engine.setProperty("velocimacro.library",

        "/azkaban/webapp/servlet/velocity/macros.vm");//

    engine.setProperty(

        "velocimacro.permissions.allow.inline.to.replace.global", true);

    engine.setProperty("velocimacro.arguments.strict", true);

    engine.setProperty("runtime.log.invalid.references", devMode);

    engine.setProperty("runtime.log.logsystem.class", Log4JLogChute.class);

    engine.setProperty("runtime.log.logsystem.log4j.logger",

        Logger.getLogger("org.apache.velocity.Logger"));

    engine.setProperty("parser.pool.size", 3);

    return engine;

  }

-----------------------------------------------------------------------------------------------------------------

接下来是初始化SessionCache

  /**

   * Constructor taking global props.

   *

   * @param props

   */

  public SessionCache(Props props) {//直接调用googlejar

    cache = CacheBuilder.newBuilder()

        .maximumSize(props.getInt("max.num.sessions", MAX_NUM_SESSIONS))

        .expireAfterAccess(

            props.getLong("session.time.to.live", SESSION_TIME_TO_LIVE),

            TimeUnit.MILLISECONDS)

        .build();//

  }

---接下来是创建    XmlUserManager

代码如下:

 

 private UserManager loadUserManager(Props props) {//开始初始化

    Class<?> userManagerClass = props.getClass(USER_MANAGER_CLASS_PARAM, null);//"user.manager.class"

    logger.info("Loading user manager class " + userManagerClass.getName());

    UserManager manager = null;

    if (userManagerClass != null

        && userManagerClass.getConstructors().length > 0) {

      try {//获取构造函数

        Constructor<?> userManagerConstructor =

            userManagerClass.getConstructor(Props.class);

        manager = (UserManager) userManagerConstructor.newInstance(props);//基于构造函数来生成实例

      } catch (Exception e) {

        logger.error("Could not instantiate UserManager "

            + userManagerClass.getName());

        throw new RuntimeException(e);

      }

    } else {

      manager = new XmlUserManager(props);

    }

    return manager;

  }

构造函数的实例化如下:

 

public XmlUserManager(Props props) {//看到这里了

    xmlPath = props.getString(XML_FILE_PARAM);//"user.manager.xml.file";

 

    parseXMLFile();

  }

而parseXMLFile的代码,放到下一节讲解!

 

 

 

 

你可能感兴趣的:(azkaban)