|
@@ -11,6 +11,8 @@ import java.util.Map.Entry;
|
|
|
import org.zillion.util.log.LogUtil;
|
|
|
|
|
|
import com.saga.util.Constant;
|
|
|
+import com.saga.util.HBaseUtil;
|
|
|
+import com.zillion.database.agent.ZillionAgent;
|
|
|
|
|
|
public class CheckThread extends Thread {
|
|
|
// ZillionAgent agent;
|
|
@@ -22,6 +24,11 @@ public class CheckThread extends Thread {
|
|
|
private Map<String, String> projectStatus = new HashMap<String, String>();
|
|
|
private Map<String, String> physicalStatus = new HashMap<String, String>();
|
|
|
|
|
|
+ private Map<String, String> dbPointStatus = new HashMap<String, String>();
|
|
|
+ private Map<String, String> dbMeterStatus = new HashMap<String, String>();
|
|
|
+ private Map<String, String> dbProjectStatus = new HashMap<String, String>();
|
|
|
+ private Map<String, String> dbPhysicalStatus = new HashMap<String, String>();
|
|
|
+
|
|
|
public CheckThread() {
|
|
|
try {
|
|
|
// this.agent = agent;
|
|
@@ -40,14 +47,18 @@ public class CheckThread extends Thread {
|
|
|
LogUtil.info("CheckThread-" + this.getName() + " Starting ...");
|
|
|
// 初次加载生成当前状态
|
|
|
this.excuteDBStatus();
|
|
|
+ // 获取DB当前状态
|
|
|
+ this.loadDBStatus();
|
|
|
|
|
|
while (true) {
|
|
|
try {
|
|
|
+
|
|
|
// // V1.0点位日志结构
|
|
|
// this.realCheck();
|
|
|
// V2.0点位日志结构
|
|
|
this.realCheck2();
|
|
|
// Constant.showStatus();
|
|
|
+ this.DBStatus();
|
|
|
Thread.sleep(Constant.Millisecond.SECOND_1);
|
|
|
} catch (Exception e) {
|
|
|
// TODO Auto-generated catch block
|
|
@@ -56,6 +67,50 @@ public class CheckThread extends Thread {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void loadDBStatus() {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+ // 重新启动加载节点、点位状态
|
|
|
+ this.dbPointStatus = new HashMap<String, String>();
|
|
|
+ this.dbMeterStatus = new HashMap<String, String>();
|
|
|
+ this.dbProjectStatus = new HashMap<String, String>();
|
|
|
+ this.dbPhysicalStatus = new HashMap<String, String>();
|
|
|
+ for (ZillionAgent agent : Constant.agents) {
|
|
|
+ for (Entry<String, String> bd : Constant.BuildingDB.entrySet()) {
|
|
|
+ try {
|
|
|
+ String project = bd.getKey();
|
|
|
+ String db = bd.getValue();
|
|
|
+ this.dbPhysicalStatus
|
|
|
+ .putAll(HBaseUtil.ps_physical_status(agent, db, "ps_physical_status", project));
|
|
|
+ this.dbMeterStatus
|
|
|
+ .putAll(HBaseUtil.ps_virtual_meter_status(agent, db, "ps_virtual_meter_status", project));
|
|
|
+ this.dbPointStatus
|
|
|
+ .putAll(HBaseUtil.ps_virtual_point_status(agent, db, "ps_virtual_point_status", project));
|
|
|
+ this.dbProjectStatus.putAll(
|
|
|
+ HBaseUtil.ps_virtual_project_status(agent, db, "ps_virtual_project_status", project));
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ LogUtil.error("CheckThread.loadDBStatus: " + e.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void DBStatus() {
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+
|
|
|
+ this.dbPhysicalStatus = this.physicalStatus;
|
|
|
+
|
|
|
+ this.dbMeterStatus = this.meterStatus;
|
|
|
+
|
|
|
+ this.dbPointStatus = this.pointStatus;
|
|
|
+
|
|
|
+ this.dbProjectStatus = this.projectStatus;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void excuteDBStatus() {
|
|
|
// TODO Auto-generated method stub
|
|
|
// for (Entry<String, Long> pns : Constant.ps_NodeStatus.entrySet()) {
|
|
@@ -68,7 +123,7 @@ public class CheckThread extends Thread {
|
|
|
// }
|
|
|
for (Entry<String, Long> ppsu : Constant.ps_PointStatusUp.entrySet()) {
|
|
|
if (ppsu.getValue() != null) {
|
|
|
- if (System.currentTimeMillis() - ppsu.getValue() < Constant.Millisecond.MINUTE_10) {
|
|
|
+ if (System.currentTimeMillis() - ppsu.getValue() < Constant.Millisecond.MINUTE_15) {
|
|
|
this.pointStatus.put(ppsu.getKey(), "conn");
|
|
|
} else {
|
|
|
this.pointStatus.put(ppsu.getKey(), "disconn");
|
|
@@ -81,7 +136,7 @@ public class CheckThread extends Thread {
|
|
|
for (Entry<String, Long> pps : Constant.ps_PhysicalStatus.entrySet()) {
|
|
|
// if (!pps.getKey().endsWith(";;;")) {
|
|
|
if (pps.getValue() != null) {
|
|
|
- if (System.currentTimeMillis() - pps.getValue() < Constant.Millisecond.MINUTE_10) {
|
|
|
+ if (System.currentTimeMillis() - pps.getValue() < Constant.Millisecond.MINUTE_15) {
|
|
|
this.physicalStatus.put(pps.getKey(), "conn");
|
|
|
} else {
|
|
|
this.physicalStatus.put(pps.getKey(), "disconn");
|
|
@@ -94,7 +149,7 @@ public class CheckThread extends Thread {
|
|
|
}
|
|
|
for (Entry<String, Long> pps : Constant.ps_ProjectStatus.entrySet()) {
|
|
|
if (pps.getValue() != null) {
|
|
|
- if (System.currentTimeMillis() - pps.getValue() < Constant.Millisecond.MINUTE_10) {
|
|
|
+ if (System.currentTimeMillis() - pps.getValue() < Constant.Millisecond.MINUTE_15) {
|
|
|
this.projectStatus.put(pps.getKey(), "conn");
|
|
|
} else {
|
|
|
this.projectStatus.put(pps.getKey(), "disconn");
|
|
@@ -106,7 +161,7 @@ public class CheckThread extends Thread {
|
|
|
}
|
|
|
for (Entry<String, Long> pmsu : Constant.ps_MeterStatusUp.entrySet()) {
|
|
|
if (pmsu.getValue() != null) {
|
|
|
- if (System.currentTimeMillis() - pmsu.getValue() < Constant.Millisecond.MINUTE_10) {
|
|
|
+ if (System.currentTimeMillis() - pmsu.getValue() < Constant.Millisecond.MINUTE_15) {
|
|
|
this.meterStatus.put(pmsu.getKey(), "conn");
|
|
|
} else {
|
|
|
this.meterStatus.put(pmsu.getKey(), "disconn");
|
|
@@ -156,7 +211,9 @@ public class CheckThread extends Thread {
|
|
|
// 首次
|
|
|
!this.projectStatus.containsKey(project) || null == this.projectStatus.get(project) ||
|
|
|
// 已有记录且状态发生变化
|
|
|
- !status.equalsIgnoreCase(this.projectStatus.get(project))) {
|
|
|
+ !status.equalsIgnoreCase(this.projectStatus.get(project)) ||
|
|
|
+ // DB同步
|
|
|
+ !status.equalsIgnoreCase(this.dbProjectStatus.get(project))) {
|
|
|
Constant.Insert_agents_ps_virtual_project_log(project, Constant.format(new Date()), status);
|
|
|
if ("disconn".equalsIgnoreCase(status)) {
|
|
|
Constant.Insert_agents_ps_virtual_project_status(project, status,
|
|
@@ -192,7 +249,9 @@ public class CheckThread extends Thread {
|
|
|
// 首次
|
|
|
!this.meterStatus.containsKey(pm) || null == this.meterStatus.get(pm) ||
|
|
|
// 已有记录且状态发生变化
|
|
|
- !status.equalsIgnoreCase(this.meterStatus.get(pm))) {
|
|
|
+ !status.equalsIgnoreCase(this.meterStatus.get(pm))
|
|
|
+ // DB同步
|
|
|
+ || !status.equalsIgnoreCase(this.dbMeterStatus.get(pm))) {
|
|
|
Constant.Insert_agents_ps_virtual_meter_log(project, meter, "up", Constant.format(new Date()),
|
|
|
status);
|
|
|
if ("disconn".equalsIgnoreCase(status)) {
|
|
@@ -246,7 +305,9 @@ public class CheckThread extends Thread {
|
|
|
// 首次
|
|
|
!this.physicalStatus.containsKey(physical) || null == this.physicalStatus.get(physical) ||
|
|
|
// 已有记录且状态发生变化
|
|
|
- !status.equalsIgnoreCase(this.physicalStatus.get(physical))) {
|
|
|
+ !status.equalsIgnoreCase(this.physicalStatus.get(physical)) ||
|
|
|
+ // DB同步
|
|
|
+ !status.equalsIgnoreCase(this.dbPhysicalStatus.get(physical))) {
|
|
|
Constant.Insert_agents_ps_physical_log(project, address_1, address_2, address_3, address_4,
|
|
|
Constant.format(new Date()), status);
|
|
|
|
|
@@ -465,7 +526,9 @@ public class CheckThread extends Thread {
|
|
|
}
|
|
|
} else if (
|
|
|
// 已有记录且状态发生变化
|
|
|
- (!status.equalsIgnoreCase(this.pointStatus.get(pointUp.getKey())))) {
|
|
|
+ (!status.equalsIgnoreCase(this.pointStatus.get(pointUp.getKey()))) ||
|
|
|
+ // DB同步
|
|
|
+ (!status.equalsIgnoreCase(this.dbPointStatus.get(pointUp.getKey())))) {
|
|
|
// 添加Log记录
|
|
|
if (Constant.RecordAddress.containsKey(building + "-" + point.replace(".", "-"))) {
|
|
|
if (Constant.RecordAddress.get(building + "-" + point.replace(".", "-")) != null) {
|
|
@@ -662,7 +725,7 @@ public class CheckThread extends Thread {
|
|
|
// String status = "";
|
|
|
//
|
|
|
// if (pointUp.getValue() != null
|
|
|
- // && this.realCheck - pointUp.getValue() < Constant.Millisecond.MINUTE_10)
|
|
|
+ // && this.realCheck - pointUp.getValue() < Constant.Millisecond.MINUTE_15)
|
|
|
// {
|
|
|
// HBaseUtil.InsertPointStatus(Constant.agent,
|
|
|
// Constant.BuildingDB.get(building), building,
|