Zond: настройка параметров пинга через конфиг
This commit is contained in:
@@ -1,19 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2017-07-21
|
||||||
|
*/
|
||||||
package asys.zond;
|
package asys.zond;
|
||||||
|
|
||||||
import asys.zond.shell.Shell;
|
|
||||||
|
|
||||||
public class PingMonitor {
|
public class PingMonitor {
|
||||||
private static final long STEP_PING = 5000;
|
private final long step_ping;
|
||||||
private final long delayStart;
|
private final long delayStart;
|
||||||
private long lastPingTime;
|
private long lastPingTime;
|
||||||
private Thread threadPingMon;
|
private Thread threadPingMon;
|
||||||
private boolean correctShutdown = false;
|
private boolean correctShutdown = false;
|
||||||
|
private final int maxlost;
|
||||||
|
|
||||||
public PingMonitor(long delayStart) {
|
PingMonitor(int delay, int second, int maxlost) {
|
||||||
this.delayStart = delayStart;
|
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(() -> {
|
this.threadPingMon = new Thread(() -> {
|
||||||
correctShutdown = false;
|
correctShutdown = false;
|
||||||
try {
|
try {
|
||||||
@@ -24,20 +29,13 @@ public class PingMonitor {
|
|||||||
|
|
||||||
while (!Thread.currentThread().isInterrupted()) {
|
while (!Thread.currentThread().isInterrupted()) {
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
long currentTimeMillis = System.currentTimeMillis();
|
||||||
if ((currentTimeMillis - lastPingTime) >= (1*STEP_PING)) {
|
if ((currentTimeMillis - lastPingTime) >= (maxlost*step_ping)) { // если пропущено N пингов
|
||||||
Shell.getInstance().getOutput().println("[D] lost one ping....");
|
|
||||||
}
|
|
||||||
else if ((currentTimeMillis - lastPingTime) >= (2*STEP_PING)) { // если пропущено два пинга
|
|
||||||
Shell.getInstance().getOutput().println("[D] lost two ping....");
|
|
||||||
callback.run(); // запускаем код завершения процесса
|
callback.run(); // запускаем код завершения процесса
|
||||||
return; // завершаем поток
|
return; // завершаем поток
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Shell.getInstance().getOutput().println("[D] check ping");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(STEP_PING);
|
Thread.sleep(step_ping);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -48,7 +46,7 @@ public class PingMonitor {
|
|||||||
this.threadPingMon.start();
|
this.threadPingMon.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
void stop() {
|
||||||
if (threadPingMon != null) {
|
if (threadPingMon != null) {
|
||||||
threadPingMon.interrupt();
|
threadPingMon.interrupt();
|
||||||
threadPingMon = null;
|
threadPingMon = null;
|
||||||
@@ -63,7 +61,7 @@ public class PingMonitor {
|
|||||||
correctShutdown = true;
|
correctShutdown = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCorrectShutdown() {
|
boolean isCorrectShutdown() {
|
||||||
return correctShutdown;
|
return correctShutdown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,15 +82,19 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
|
|
||||||
executor.setWatchdog(watchdog);
|
executor.setWatchdog(watchdog);
|
||||||
}
|
}
|
||||||
final long delay = Config.getInstance().getLong("pingmonitor.delay");
|
int delay = Config.getInstance().getInt("pingmonitor.delay");
|
||||||
pingMonitor = new PingMonitor(delay);
|
pingMonitor = new PingMonitor(
|
||||||
|
delay,
|
||||||
|
Config.getInstance().getInt("bridge.second"),
|
||||||
|
Config.getInstance().getInt("pingmonitor.maxlost")
|
||||||
|
);
|
||||||
flagManualKill = false;
|
flagManualKill = false;
|
||||||
|
|
||||||
Runnable task = () -> {
|
Runnable task = () -> {
|
||||||
short _try = 0;
|
short _try = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int code = 0;
|
int code;
|
||||||
long deadTime = 0;
|
long deadTime = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -104,12 +108,12 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
flagForceRestartProcess = true;
|
flagForceRestartProcess = true;
|
||||||
killProcess();
|
killProcess();
|
||||||
});
|
});
|
||||||
deadTime = (System.currentTimeMillis()/1000) + delay;
|
deadTime = (System.currentTimeMillis()/1000) + (delay*1000);
|
||||||
code = executor.execute(commandLine);
|
code = executor.execute(commandLine);
|
||||||
} catch (ExecuteException e) {
|
} catch (ExecuteException e) {
|
||||||
code = e.getExitValue();
|
code = e.getExitValue();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Shell.getInstance().getOutput().println("Exception message: " + e.getMessage());
|
Shell.getInstance().getOutput().println("[!] Exception message: " + e.getMessage());
|
||||||
code = -99;
|
code = -99;
|
||||||
}
|
}
|
||||||
long currTime = System.currentTimeMillis()/1000;
|
long currTime = System.currentTimeMillis()/1000;
|
||||||
@@ -117,7 +121,7 @@ public class ZondCommandHandler implements CommandHandler {
|
|||||||
server.shutdown();
|
server.shutdown();
|
||||||
pingMonitor.stop();
|
pingMonitor.stop();
|
||||||
server = null;
|
server = null;
|
||||||
Shell.getInstance().getOutput().println("Process finished. Code: " + code);
|
Shell.getInstance().getOutput().println("[i] Process finished. Code: " + code);
|
||||||
|
|
||||||
if (pingMonitor.isCorrectShutdown()) {
|
if (pingMonitor.isCorrectShutdown()) {
|
||||||
flagForceRestartProcess = false;
|
flagForceRestartProcess = false;
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ host = 127.0.0.1
|
|||||||
port = 8779
|
port = 8779
|
||||||
passcode = testpassphrase
|
passcode = testpassphrase
|
||||||
bridge.port = 8710
|
bridge.port = 8710
|
||||||
pingmonitor.delay = 2100
|
bridge.second = 5
|
||||||
|
pingmonitor.delay = 2
|
||||||
|
pingmonitor.maxlost = 6
|
||||||
|
#Windows
|
||||||
#cmdkiller = taskkill /F /PID %PID
|
#cmdkiller = taskkill /F /PID %PID
|
||||||
|
#Linux
|
||||||
cmdkiller = kill -KILL %PID
|
cmdkiller = kill -KILL %PID
|
||||||
Reference in New Issue
Block a user