好,到目前爲止,一切都很順利,以前的代碼都所有解析完畢,下面開始解析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));
鑑於時間緊急,暫時先不研究如何擴充插件,後續有精力再嘗試本身寫一個插件。