Archived
0

Zond: настройка параметров пинга через конфиг

This commit is contained in:
2017-07-24 23:39:49 +03:00
parent dc891e3d28
commit a2952fc772
3 changed files with 30 additions and 24 deletions

View File

@@ -1,19 +1,24 @@
/*
* DmitriyMX <dimon550@gmail.com>
* 2017-07-21
*/
package asys.zond;
import asys.zond.shell.Shell;
public class PingMonitor {
private static final long STEP_PING = 5000;
private final long step_ping;
private final long delayStart;
private long lastPingTime;
private Thread threadPingMon;
private boolean correctShutdown = false;
private final int maxlost;
public PingMonitor(long delayStart) {
this.delayStart = delayStart;
PingMonitor(int delay, int second, int maxlost) {
this.delayStart = delay*1000;
this.step_ping = second*1000;
this.maxlost = maxlost;
}
public void start(final Runnable callback) {
void start(final Runnable callback) {
this.threadPingMon = new Thread(() -> {
correctShutdown = false;
try {
@@ -24,20 +29,13 @@ public class PingMonitor {
while (!Thread.currentThread().isInterrupted()) {
long currentTimeMillis = System.currentTimeMillis();
if ((currentTimeMillis - lastPingTime) >= (1*STEP_PING)) {
Shell.getInstance().getOutput().println("[D] lost one ping....");
}
else if ((currentTimeMillis - lastPingTime) >= (2*STEP_PING)) { // если пропущено два пинга
Shell.getInstance().getOutput().println("[D] lost two ping....");
if ((currentTimeMillis - lastPingTime) >= (maxlost*step_ping)) { // если пропущено N пингов
callback.run(); // запускаем код завершения процесса
return; // завершаем поток
}
else {
Shell.getInstance().getOutput().println("[D] check ping");
}
try {
Thread.sleep(STEP_PING);
Thread.sleep(step_ping);
} catch (InterruptedException e) {
return;
}
@@ -48,7 +46,7 @@ public class PingMonitor {
this.threadPingMon.start();
}
public void stop() {
void stop() {
if (threadPingMon != null) {
threadPingMon.interrupt();
threadPingMon = null;
@@ -63,7 +61,7 @@ public class PingMonitor {
correctShutdown = true;
}
public boolean isCorrectShutdown() {
boolean isCorrectShutdown() {
return correctShutdown;
}
}

View File

@@ -82,15 +82,19 @@ public class ZondCommandHandler implements CommandHandler {
executor.setWatchdog(watchdog);
}
final long delay = Config.getInstance().getLong("pingmonitor.delay");
pingMonitor = new PingMonitor(delay);
int delay = Config.getInstance().getInt("pingmonitor.delay");
pingMonitor = new PingMonitor(
delay,
Config.getInstance().getInt("bridge.second"),
Config.getInstance().getInt("pingmonitor.maxlost")
);
flagManualKill = false;
Runnable task = () -> {
short _try = 0;
do {
int code = 0;
int code;
long deadTime = 0;
try {
@@ -104,12 +108,12 @@ public class ZondCommandHandler implements CommandHandler {
flagForceRestartProcess = true;
killProcess();
});
deadTime = (System.currentTimeMillis()/1000) + delay;
deadTime = (System.currentTimeMillis()/1000) + (delay*1000);
code = executor.execute(commandLine);
} catch (ExecuteException e) {
code = e.getExitValue();
} catch (IOException e) {
Shell.getInstance().getOutput().println("Exception message: " + e.getMessage());
Shell.getInstance().getOutput().println("[!] Exception message: " + e.getMessage());
code = -99;
}
long currTime = System.currentTimeMillis()/1000;
@@ -117,7 +121,7 @@ public class ZondCommandHandler implements CommandHandler {
server.shutdown();
pingMonitor.stop();
server = null;
Shell.getInstance().getOutput().println("Process finished. Code: " + code);
Shell.getInstance().getOutput().println("[i] Process finished. Code: " + code);
if (pingMonitor.isCorrectShutdown()) {
flagForceRestartProcess = false;

View File

@@ -3,6 +3,10 @@ host = 127.0.0.1
port = 8779
passcode = testpassphrase
bridge.port = 8710
pingmonitor.delay = 2100
bridge.second = 5
pingmonitor.delay = 2
pingmonitor.maxlost = 6
#Windows
#cmdkiller = taskkill /F /PID %PID
#Linux
cmdkiller = kill -KILL %PID