Azkaban的Web Server源码探究系列6: alerters及插件机制分析

好,到目前为止,一切都很顺利,以前的代码都所有解析完毕,下面开始解析alerters及插件机制!ui

---------------------------------------------------------------------------------------------------------未完待续!this

alerters = loadAlerters(props);spa

 private Map<String, Alerter> loadAlerters(Props props) {//看到这里了插件

    Map<String, Alerter> allAlerters = new HashMap<String, Alerter>();server

    // load built-in alerters对象

    Emailer mailAlerter = new Emailer(props);//构造emailer对象ssl

    allAlerters.put("email", mailAlerter);//归入get

    // load all plugin alerters域名

    // 尝试加载全部的插件aleterssio

    String pluginDir = props.getString("alerter.plugin.dir", "plugins/alerter");

    allAlerters.putAll(loadPluginAlerters(pluginDir));

    return allAlerters;//返回

  }

主要就是Emailer的构造过程

public class Emailer extends AbstractMailer implements Alerter {

先看AbstractMailer 

public AbstractMailer(Props props) {

    this.azkabanName = props.getString("azkaban.name", "azkaban");//获取name

    this.mailHost = props.getString("mail.host", "localhost");//邮箱的IP/域名

    this.mailUser = props.getString("mail.user", "");//用户

    this.mailPassword = props.getString("mail.password", "");//密码

    long maxAttachmentSizeInMB =

        props.getInt("mail.max.attachment.size.mb", 100);

 

    attachmentMazSizeInByte = maxAttachmentSizeInMB * MB_IN_BYTES;//默认100M

 

    this.mailSender = props.getString("mail.sender", "");

    this.usesAuth = props.getBoolean("mail.useAuth", true);

 

    this.clientHostname = props.get("server.hostname");

    this.clientPort = props.getInt("server.port");

    this.usesSSL = props.getBoolean("server.useSSL");

 

    if (usesSSL) {

      referenceURL =

          "https://" + clientHostname

              + (clientPort == 443 ? "/" : ":" + clientPort + "/");

    } else {//构造referenceURL

      referenceURL =

          "http://" + clientHostname

              + (clientPort == 80 ? "/" : ":" + clientPort + "/");

    }

  }

再看Emailer 

public Emailer(Props props) {

    super(props);

    this.azkabanName = props.getString("azkaban.name", "azkaban");

    this.mailHost = props.getString("mail.host", "localhost");

    this.mailUser = props.getString("mail.user", "");

    this.mailPassword = props.getString("mail.password", "");

    this.mailSender = props.getString("mail.sender", "");

    this.tls = props.getString("mail.tls", "false");

 

    int mailTimeout = props.getInt("mail.timeout.millis", 10000);//设置超时时间

    EmailMessage.setTimeout(mailTimeout);//保留到静态变量

    int connectionTimeout =

        props.getInt("mail.connection.timeout.millis", 10000);

    EmailMessage.setConnectionTimeout(connectionTimeout);//保留到静态变量

 

    EmailMessage.setTotalAttachmentMaxSize(getAttachmentMaxSize());//设置附件大小

 

    this.clientHostname = props.getString("jetty.hostname", "localhost");

 

    if (props.getBoolean("jetty.use.ssl", true)) {

      this.scheme = HTTPS;

      this.clientPortNumber = props.getString("jetty.ssl.port");

    } else {

      this.scheme = HTTP;

      this.clientPortNumber = props.getString("jetty.port");

    }

 

    testMode = props.getBoolean("test.mode", false);

  }

而后关于插件机制

 // 尝试加载全部的插件aleterss

    String pluginDir = props.getString("alerter.plugin.dir", "plugins/alerter");

    allAlerters.putAll(loadPluginAlerters(pluginDir));

鉴于时间紧急,暂时先不研究如何扩充插件,后续有精力再尝试本身写一个插件。

相关文章
相关标签/搜索