loop shutdown preparation
This commit is contained in:
parent
65791ae804
commit
dd0b223348
@ -14,7 +14,8 @@ import org.apache.logging.log4j.Logger;
|
|||||||
public class ConfigProperties extends Properties {
|
public class ConfigProperties extends Properties {
|
||||||
static final String DEFAULT_PROPS_FILENAME = "mbusMaster.props";
|
static final String DEFAULT_PROPS_FILENAME = "mbusMaster.props";
|
||||||
static final String PROPS_VERBOSE = "verbose";
|
static final String PROPS_VERBOSE = "verbose";
|
||||||
static final String PRPOS_MAINCONFIGFILE = "mainConfigFile";
|
static final String PROPS_MAINCONFIGFILE = "mainConfigFile";
|
||||||
|
static final String PROPS_ERRORRATIOTHRESHOLD = "errorRatioThreshold";
|
||||||
|
|
||||||
static final Logger logger = LogManager.getRootLogger();
|
static final Logger logger = LogManager.getRootLogger();
|
||||||
|
|
||||||
@ -23,7 +24,7 @@ public class ConfigProperties extends Properties {
|
|||||||
|
|
||||||
public ConfigProperties() throws ConfigPropertiesException {
|
public ConfigProperties() throws ConfigPropertiesException {
|
||||||
super();
|
super();
|
||||||
String propsFilename = System.getProperty(PRPOS_MAINCONFIGFILE, DEFAULT_PROPS_FILENAME);
|
String propsFilename = System.getProperty(PROPS_MAINCONFIGFILE, DEFAULT_PROPS_FILENAME);
|
||||||
try {
|
try {
|
||||||
try (FileInputStream propsFileInputStream = new FileInputStream(propsFilename)) {
|
try (FileInputStream propsFileInputStream = new FileInputStream(propsFilename)) {
|
||||||
load(propsFileInputStream);
|
load(propsFileInputStream);
|
||||||
|
@ -57,11 +57,8 @@ abstract public class MbusDevice {
|
|||||||
this.errorCnt++;
|
this.errorCnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetSuccessCnt() {
|
public void resetCounter() {
|
||||||
this.successCnt = 0;
|
this.successCnt = 0;
|
||||||
}
|
|
||||||
|
|
||||||
public void resetErrorCnt() {
|
|
||||||
this.errorCnt = 0;
|
this.errorCnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
|
|
||||||
public class MbusScheduledQuerier extends Thread {
|
public class MbusScheduledQuerier extends Thread {
|
||||||
|
static final double DEFAULT_ERRORRATIOTHRESHOLD = 0.5;
|
||||||
|
|
||||||
static final Logger logger = LogManager.getRootLogger();
|
static final Logger logger = LogManager.getRootLogger();
|
||||||
|
|
||||||
private ArrayList<MbusDevice> devices;
|
private ArrayList<MbusDevice> devices;
|
||||||
@ -18,6 +20,7 @@ public class MbusScheduledQuerier extends Thread {
|
|||||||
private ConfigProperties config;
|
private ConfigProperties config;
|
||||||
private BlockingQueue<ADataObject> queue;
|
private BlockingQueue<ADataObject> queue;
|
||||||
|
|
||||||
|
|
||||||
public MbusScheduledQuerier(ConfigProperties config, BlockingQueue<ADataObject> queue) {
|
public MbusScheduledQuerier(ConfigProperties config, BlockingQueue<ADataObject> queue) {
|
||||||
super("MbusScheduledQuerier");
|
super("MbusScheduledQuerier");
|
||||||
|
|
||||||
@ -47,6 +50,11 @@ public class MbusScheduledQuerier extends Thread {
|
|||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
int errCnt = 0;
|
int errCnt = 0;
|
||||||
int successCnt = 0;
|
int successCnt = 0;
|
||||||
|
int shutdownCnt = 0;
|
||||||
|
double maxErrorRatio = 0;
|
||||||
|
int timeSinceLastLoopShutdown = 0;
|
||||||
|
int meantimeBetweenLoopShutdowns = 0;
|
||||||
|
|
||||||
|
|
||||||
while (! this.stopSignal) {
|
while (! this.stopSignal) {
|
||||||
cnt++;
|
cnt++;
|
||||||
@ -67,9 +75,32 @@ public class MbusScheduledQuerier extends Thread {
|
|||||||
errCnt++;
|
errCnt++;
|
||||||
logger.error("Error " + e.toString() + " in Meterbus dialog for device " + device.shortString());
|
logger.error("Error " + e.toString() + " in Meterbus dialog for device " + device.shortString());
|
||||||
}
|
}
|
||||||
|
this.maxErrorRatio = (this.maxErrorRatio > device.getErrorRatio()) ? this.maxErrorRatio : device.getErrorRatio();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.maxErrorRatio > config.getDoubleProperties(ConfigProperties.PROPS_ERRORRATIOTHRESHOLD, DEFAULT_ERRORRATIOTHRESHOLD)) {
|
||||||
|
// disable loop
|
||||||
|
shutdownCnt++;
|
||||||
|
|
||||||
|
// reset counters in devices
|
||||||
|
for (MbusDevice device : this.devices) {
|
||||||
|
device.resetCounter();
|
||||||
|
}
|
||||||
|
// reset local counters
|
||||||
|
errCnt = 0;
|
||||||
|
successCnt = 0;
|
||||||
|
|
||||||
|
// remember time of loop shutdown
|
||||||
|
// calculate time since last shutdown
|
||||||
|
// calculate mean time between shutdowns
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
logger.info("CycleCnt: " + cnt + ", SuccessCnt: " + successCnt + ", ErrCnt: " + errCnt);
|
logger.info("CycleCnt: " + cnt + ", SuccessCnt: " + successCnt + ", ErrCnt: " + errCnt);
|
||||||
this.queue.add(new MbusStatisticsDataObject("MbusgwChild", errCnt, successCnt, ((double)errCnt / (double)(errCnt+successCnt))));
|
this.queue.add(new MbusStatisticsDataObject("MbusgwChild", errCnt, successCnt, shutdownCnt,
|
||||||
|
((double)errCnt / (double)(errCnt+successCnt))),
|
||||||
|
timeSinceLastLoopShutdown, meantimeBetweenLoopShutdowns);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5*1000);
|
Thread.sleep(5*1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -7,15 +7,22 @@ public class MbusStatisticsDataObject extends ADataObject {
|
|||||||
static final String ERROR_CNT_KEY = "error";
|
static final String ERROR_CNT_KEY = "error";
|
||||||
static final String SUCCESS_CNT_KEY = "success";
|
static final String SUCCESS_CNT_KEY = "success";
|
||||||
static final String ERROR_RATIO_KEY = "errorRatio";
|
static final String ERROR_RATIO_KEY = "errorRatio";
|
||||||
|
static final String TIME_SINCE_LAST_SHUTDOWN_KEY = "timeSinceLastShutdown";
|
||||||
|
static final String MEANTIME_BETWEEN_SHUTDOWNS_KEY = "meantimeBetweenShutdowns";
|
||||||
|
static final String SHUTDOWNS_KEY = "shutdowns";
|
||||||
static final String TABLE_NAME = "Statistics";
|
static final String TABLE_NAME = "Statistics";
|
||||||
static final String KIND_NAME = "Statistics";
|
static final String KIND_NAME = "Statistics";
|
||||||
|
|
||||||
public MbusStatisticsDataObject(String name, int error, int success, double errorRatio) {
|
public MbusStatisticsDataObject(String name, int error, int success, int shutdowns,
|
||||||
|
double errorRatio, int timeSinceLastShutdown, int meantimeBetweenShutdowns) {
|
||||||
super(name, KIND_NAME);
|
super(name, KIND_NAME);
|
||||||
HashMap<String, Object> values = new HashMap<String, Object>();
|
HashMap<String, Object> values = new HashMap<String, Object>();
|
||||||
values.put(ERROR_CNT_KEY, error);
|
values.put(ERROR_CNT_KEY, error);
|
||||||
values.put(SUCCESS_CNT_KEY, success);
|
values.put(SUCCESS_CNT_KEY, success);
|
||||||
values.put(ERROR_RATIO_KEY, errorRatio);
|
values.put(ERROR_RATIO_KEY, errorRatio);
|
||||||
|
values.put(TIME_SINCE_LAST_SHUTDOWN_KEY, timeSinceLastShutdown);
|
||||||
|
values.put(MEANTIME_BETWEEN_SHUTDOWNS_KEY, meantimeBetweenShutdowns);
|
||||||
|
values.put(SHUTDOWNS_KEY, shutdowns);
|
||||||
setValues(values);
|
setValues(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user