上述方法主要是调用了 MySQLDetector#heartbeat
方法,调用链真的挺深的……:public void heartbeat() {
if (con == null || con.isClosed()) {
heartbeat.setResult(MySQLHeartbeat.ERROR_STATUS);
return;
}
//设置了发送心跳检测的时间
lastSendQryTime = System.currentTimeMillis();
String[] fetchCols = {};
if (heartbeat.getSource().getHostConfig().isShowSlaveSql()) {
fetchCols = MYSQL_SLAVE_STATUS_COLS;
} else if (heartbeat.getSource().getHostConfig().isShowClusterSql()) {
fetchCols = MYSQL_CLUSTER_STATUS_COLS;
} else if (heartbeat.getSource().getHostConfig().isSelectReadOnlySql()) {
fetchCols = MYSQL_READ_ONLY_COLS;
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("do heartbeat,conn is " + con);
}
OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(fetchCols, this);
sqlJob = new HeartbeatSQLJob(heartbeat.getHeartbeatSQL(), con, resultHandler);
//执行心跳检测任务
sqlJob.execute();
}