From e688eeae1224fcbf64d667dee96132c123f2ef2c Mon Sep 17 00:00:00 2001 From: Michal Date: Mon, 10 Feb 2025 20:44:57 +0100 Subject: [PATCH] --- jnetserver.service | 18 ++ log.log | 246 +++------------------- nbproject/project.properties | 4 +- src/jnet/server/probe/NettyPing.java | 87 ++++++++ src/jnet/server/probe/Ping2.java | 78 ------- src/jnet/server/probe/PingResult.java | 53 +++++ src/jnet/server/probe/PingTestResult.java | 91 -------- 7 files changed, 185 insertions(+), 392 deletions(-) create mode 100644 jnetserver.service create mode 100644 src/jnet/server/probe/NettyPing.java delete mode 100644 src/jnet/server/probe/Ping2.java create mode 100644 src/jnet/server/probe/PingResult.java delete mode 100644 src/jnet/server/probe/PingTestResult.java diff --git a/jnetserver.service b/jnetserver.service new file mode 100644 index 0000000..d3b212f --- /dev/null +++ b/jnetserver.service @@ -0,0 +1,18 @@ +[Unit] +Description=jNetServer +After=network.target + +[Service] +User=root +Group=root +WorkingDirectory=/var/jNetServer/ +ExecStart=/usr/bin/java -jar /var/jNetServer/jNetServer.jar +Restart=always +RestartSec=10 +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=my-java-service + +[Install] +WantedBy=multi-user.target + diff --git a/log.log b/log.log index 41e6fc8..5365a45 100644 --- a/log.log +++ b/log.log @@ -1,222 +1,24 @@ -04.02.25 18:20:10 I --------------------------------------------- -04.02.25 18:20:10 I jNet Server -04.02.25 18:20:10 I Version: 1 (Tue Feb 04 17:54:52 CET 2025) -04.02.25 18:20:10 I --------------------------------------------- -04.02.25 18:20:10 I -04.02.25 18:20:10 I Loading config ... -04.02.25 18:20:10 I successfully -04.02.25 18:20:10 D Debug mode on -04.02.25 18:20:10 I Connecting to a selected database ... -04.02.25 18:20:10 I successfully -04.02.25 18:20:10 I Loading user list ... -04.02.25 18:20:10 I load 2 user(s) -04.02.25 18:20:10 I Loading map list ... -04.02.25 18:20:10 I load 6 map(s) -04.02.25 18:20:10 I Loading object list ... -04.02.25 18:20:10 I load 5 object(s) -04.02.25 18:20:10 I Loading object type ... -04.02.25 18:20:10 I load 12 type(s) -04.02.25 18:20:10 I Loading SNMP profile ... -04.02.25 18:20:10 I load 2 profile(s) -04.02.25 18:20:10 I Loading events ... -04.02.25 18:20:11 I load 259 event(s) -04.02.25 18:20:11 I Ping start ... -04.02.25 18:20:11 I Server is ready and listening on port 1225 -04.02.25 18:20:13 D -> Message type: 1 -04.02.25 18:20:13 I Authorization request send (kubernetes.docker.internal) -04.02.25 18:20:13 D <- Message type: 3 -04.02.25 18:20:13 D -> Message type: 4 -04.02.25 18:20:13 I User: michal logged in (kubernetes.docker.internal) -04.02.25 18:20:13 D <- Message type: 5 -04.02.25 18:20:13 D <- Message type: 9 -04.02.25 18:20:13 D <- For all. Message type: 7 -04.02.25 18:20:13 D <- Message type: 13 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 8 -04.02.25 18:20:13 D <- Message type: 11 -04.02.25 18:20:13 D <- Message type: 11 -04.02.25 18:20:13 D <- Message type: 100 -04.02.25 18:20:13 D <- Message type: 100 -04.02.25 18:20:13 D <- Message type: 100 -04.02.25 18:20:13 D <- Message type: 100 -04.02.25 18:20:13 D <- Message type: 100 -04.02.25 18:20:13 D <- Message type: 100 -04.02.25 18:20:13 D <- Message type: 14 -04.02.25 18:20:13 D <- Message type: 110 -04.02.25 18:20:13 D <- Message type: 107 -04.02.25 18:20:13 D <- Message type: 107 -04.02.25 18:28:05 D <- For all. Message type: 108 -04.02.25 18:28:05 D <- For all. Message type: 101 -04.02.25 18:28:05 D <- For all. Message type: 101 -04.02.25 18:29:45 D <- For all. Message type: 108 -04.02.25 18:29:45 D <- For all. Message type: 101 -04.02.25 18:29:45 D <- For all. Message type: 101 -04.02.25 18:34:14 D <- For all. Message type: 108 -04.02.25 18:34:14 D <- For all. Message type: 101 -04.02.25 18:34:14 D <- For all. Message type: 101 -04.02.25 18:35:53 D <- For all. Message type: 108 -04.02.25 18:35:53 D <- For all. Message type: 101 -04.02.25 18:35:54 D <- For all. Message type: 101 -04.02.25 18:38:18 D <- For all. Message type: 108 -04.02.25 18:38:18 D <- For all. Message type: 101 -04.02.25 18:38:18 D <- For all. Message type: 101 -04.02.25 18:39:31 D <- For all. Message type: 108 -04.02.25 18:39:31 D <- For all. Message type: 101 -04.02.25 18:39:31 D <- For all. Message type: 101 -04.02.25 18:40:31 D <- For all. Message type: 108 -04.02.25 18:40:31 D <- For all. Message type: 101 -04.02.25 18:40:31 D <- For all. Message type: 101 -04.02.25 18:44:12 D <- For all. Message type: 108 -04.02.25 18:44:12 D <- For all. Message type: 101 -04.02.25 18:44:13 D <- For all. Message type: 101 -04.02.25 18:44:43 D <- For all. Message type: 108 -04.02.25 18:44:43 D <- For all. Message type: 101 -04.02.25 18:44:44 D <- For all. Message type: 101 -04.02.25 18:46:19 D <- For all. Message type: 108 -04.02.25 18:46:19 D <- For all. Message type: 101 -04.02.25 18:46:20 D <- For all. Message type: 101 -04.02.25 18:48:13 D <- For all. Message type: 108 -04.02.25 18:48:13 D <- For all. Message type: 101 -04.02.25 18:48:14 D <- For all. Message type: 101 -04.02.25 18:49:37 D <- For all. Message type: 108 -04.02.25 18:49:37 D <- For all. Message type: 101 -04.02.25 18:49:37 D <- For all. Message type: 101 -04.02.25 18:54:18 D <- For all. Message type: 108 -04.02.25 18:54:18 D <- For all. Message type: 101 -04.02.25 18:54:18 D <- For all. Message type: 101 -04.02.25 18:59:24 D <- For all. Message type: 108 -04.02.25 18:59:24 D <- For all. Message type: 101 -04.02.25 18:59:27 D <- For all. Message type: 101 -04.02.25 18:59:56 D <- For all. Message type: 108 -04.02.25 18:59:56 D <- For all. Message type: 101 -04.02.25 18:59:56 D <- For all. Message type: 101 -04.02.25 19:11:38 D <- For all. Message type: 108 -04.02.25 19:11:38 D <- For all. Message type: 101 -04.02.25 19:11:39 D <- For all. Message type: 101 -04.02.25 19:14:33 D <- For all. Message type: 108 -04.02.25 19:14:33 D <- For all. Message type: 101 -04.02.25 19:14:33 D <- For all. Message type: 101 -04.02.25 19:20:55 D <- For all. Message type: 108 -04.02.25 19:20:55 D <- For all. Message type: 101 -04.02.25 19:20:55 D <- For all. Message type: 101 -04.02.25 19:24:30 D <- For all. Message type: 108 -04.02.25 19:24:30 D <- For all. Message type: 101 -04.02.25 19:24:30 D <- For all. Message type: 101 -04.02.25 19:29:23 D <- For all. Message type: 108 -04.02.25 19:29:23 D <- For all. Message type: 101 -04.02.25 19:29:24 D <- For all. Message type: 101 -04.02.25 19:34:17 D <- For all. Message type: 108 -04.02.25 19:34:17 D <- For all. Message type: 101 -04.02.25 19:34:18 D <- For all. Message type: 101 -04.02.25 19:44:31 D <- For all. Message type: 108 -04.02.25 19:44:31 D <- For all. Message type: 101 -04.02.25 19:44:31 D <- For all. Message type: 101 -04.02.25 19:48:14 D <- For all. Message type: 108 -04.02.25 19:48:14 D <- For all. Message type: 101 -04.02.25 19:48:14 D <- For all. Message type: 101 -04.02.25 19:59:37 D <- For all. Message type: 108 -04.02.25 19:59:37 D <- For all. Message type: 101 -04.02.25 19:59:38 D <- For all. Message type: 101 -04.02.25 20:0:02 D <- For all. Message type: 108 -04.02.25 20:0:02 D <- For all. Message type: 101 -04.02.25 20:0:03 D <- For all. Message type: 101 -04.02.25 20:8:49 D <- For all. Message type: 108 -04.02.25 20:8:49 D <- For all. Message type: 101 -04.02.25 20:8:50 D <- For all. Message type: 101 -04.02.25 20:9:35 D <- For all. Message type: 108 -04.02.25 20:9:35 D <- For all. Message type: 101 -04.02.25 20:9:35 D <- For all. Message type: 101 -04.02.25 20:17:35 D <- For all. Message type: 108 -04.02.25 20:17:35 D <- For all. Message type: 101 -04.02.25 20:17:35 D <- For all. Message type: 101 -04.02.25 20:19:33 D <- For all. Message type: 108 -04.02.25 20:19:33 D <- For all. Message type: 101 -04.02.25 20:19:33 D <- For all. Message type: 101 -04.02.25 20:19:47 D <- For all. Message type: 108 -04.02.25 20:19:47 D <- For all. Message type: 101 -04.02.25 20:19:47 D <- For all. Message type: 101 -04.02.25 20:23:18 D <- For all. Message type: 108 -04.02.25 20:23:18 D <- For all. Message type: 101 -04.02.25 20:23:19 D <- For all. Message type: 101 -04.02.25 20:24:28 D <- For all. Message type: 108 -04.02.25 20:24:28 D <- For all. Message type: 101 -04.02.25 20:24:29 D <- For all. Message type: 101 -04.02.25 20:24:31 D <- For all. Message type: 108 -04.02.25 20:24:31 D <- For all. Message type: 101 -04.02.25 20:24:31 D <- For all. Message type: 101 -04.02.25 20:26:06 D <- For all. Message type: 108 -04.02.25 20:26:06 D <- For all. Message type: 101 -04.02.25 20:26:06 D <- For all. Message type: 101 -04.02.25 20:34:17 D <- For all. Message type: 108 -04.02.25 20:34:17 D <- For all. Message type: 101 -04.02.25 20:34:18 D <- For all. Message type: 101 -04.02.25 20:44:50 D <- For all. Message type: 108 -04.02.25 20:44:50 D <- For all. Message type: 101 -04.02.25 20:44:53 D <- For all. Message type: 108 -04.02.25 20:44:53 D <- For all. Message type: 101 -04.02.25 20:44:53 D <- For all. Message type: 101 -04.02.25 20:44:53 D <- For all. Message type: 101 -04.02.25 20:52:08 D <- For all. Message type: 108 -04.02.25 20:52:08 D <- For all. Message type: 101 -04.02.25 20:52:09 D <- For all. Message type: 101 -04.02.25 20:54:29 D <- For all. Message type: 108 -04.02.25 20:54:29 D <- For all. Message type: 101 -04.02.25 20:54:30 D <- For all. Message type: 101 -04.02.25 21:8:32 D <- For all. Message type: 108 -04.02.25 21:8:32 D <- For all. Message type: 101 -04.02.25 21:8:32 D <- For all. Message type: 101 -04.02.25 21:13:54 D <- For all. Message type: 108 -04.02.25 21:13:54 D <- For all. Message type: 101 -04.02.25 21:13:55 D <- For all. Message type: 101 -04.02.25 21:29:31 D <- For all. Message type: 108 -04.02.25 21:29:31 D <- For all. Message type: 101 -04.02.25 21:29:31 D <- For all. Message type: 101 -04.02.25 21:30:11 D <- For all. Message type: 108 -04.02.25 21:30:11 D <- For all. Message type: 101 -04.02.25 21:30:12 D <- For all. Message type: 101 -04.02.25 21:30:18 D <- For all. Message type: 108 -04.02.25 21:30:18 D <- For all. Message type: 101 -04.02.25 21:30:19 D <- For all. Message type: 101 -04.02.25 21:39:31 D <- For all. Message type: 108 -04.02.25 21:39:31 D <- For all. Message type: 101 -04.02.25 21:39:31 D <- For all. Message type: 101 -04.02.25 21:40:04 D <- For all. Message type: 108 -04.02.25 21:40:04 D <- For all. Message type: 101 -04.02.25 21:40:05 D <- For all. Message type: 101 -04.02.25 21:41:08 D <- For all. Message type: 108 -04.02.25 21:41:08 D <- For all. Message type: 101 -04.02.25 21:41:08 D <- For all. Message type: 101 -04.02.25 21:53:54 D <- For all. Message type: 108 -04.02.25 21:53:54 D <- For all. Message type: 101 -04.02.25 21:53:55 D <- For all. Message type: 101 -04.02.25 21:54:05 D <- For all. Message type: 108 -04.02.25 21:54:05 D <- For all. Message type: 101 -04.02.25 21:54:05 D <- For all. Message type: 101 -04.02.25 21:54:38 D <- For all. Message type: 108 -04.02.25 21:54:38 D <- For all. Message type: 101 -04.02.25 21:54:38 D <- For all. Message type: 101 -04.02.25 22:4:46 D <- For all. Message type: 108 -04.02.25 22:4:46 D <- For all. Message type: 101 -04.02.25 22:4:47 D <- For all. Message type: 101 -04.02.25 22:10:03 D <- For all. Message type: 108 -04.02.25 22:10:03 D <- For all. Message type: 101 -04.02.25 22:10:03 D <- For all. Message type: 101 -04.02.25 22:39:33 D <- For all. Message type: 108 -04.02.25 22:39:33 D <- For all. Message type: 101 -04.02.25 22:39:34 D <- For all. Message type: 101 -04.02.25 22:52:23 D <- For all. Message type: 108 -04.02.25 22:52:23 D <- For all. Message type: 101 -04.02.25 22:52:24 D <- For all. Message type: 101 -04.02.25 22:54:16 D <- For all. Message type: 108 -04.02.25 22:54:16 D <- For all. Message type: 101 -04.02.25 22:54:16 D <- For all. Message type: 101 +10.02.25 20:29:05 I --------------------------------------------- +10.02.25 20:29:05 I jNet Server +10.02.25 20:29:05 I Version: 1 (Sat Feb 08 19:21:37 CET 2025) +10.02.25 20:29:05 I --------------------------------------------- +10.02.25 20:29:05 I +10.02.25 20:29:05 I Loading config ... +10.02.25 20:29:05 I successfully +10.02.25 20:29:05 D Debug mode on +10.02.25 20:29:05 I Connecting to a selected database ... +10.02.25 20:29:06 I successfully +10.02.25 20:29:06 I Loading user list ... +10.02.25 20:29:06 I load 2 user(s) +10.02.25 20:29:06 I Loading map list ... +10.02.25 20:29:06 I load 6 map(s) +10.02.25 20:29:06 I Loading object list ... +10.02.25 20:29:06 I load 7 object(s) +10.02.25 20:29:06 I Loading object type ... +10.02.25 20:29:06 I load 12 type(s) +10.02.25 20:29:06 I Loading SNMP profile ... +10.02.25 20:29:06 I load 2 profile(s) +10.02.25 20:29:06 I Loading events ... +10.02.25 20:29:06 I load 0 event(s) +10.02.25 20:29:06 I Ping probe start +10.02.25 20:29:06 I Server is ready and listening on port 1225 diff --git a/nbproject/project.properties b/nbproject/project.properties index 689f904..561d4b8 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -35,6 +35,7 @@ dist.jlink.dir=${dist.dir}/jlink dist.jlink.output=${dist.jlink.dir}/jNetServer endorsed.classpath= excludes= +file.reference.apache-commons-configuration2-2.9.0.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\apache-commons-configuration2-2.9.0.jar file.reference.apache-commons-lang3-3.12.0.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\apache-commons-lang3-3.12.0.jar file.reference.apache-commons-logging-1.2.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\apache-commons-logging-1.2.jar file.reference.apache-commons-text-1.10.0.jar=C:\\Users\\cucky\\Documents\\NetBeansProjects\\jar_files\\apache-commons-text-1.10.0.jar @@ -56,7 +57,8 @@ javac.classpath=\ ${file.reference.apache-commons-text-1.10.0.jar}:\ ${file.reference.jna-5.3.1.jar}:\ ${file.reference.jna-platform-5.9.0.jar}:\ - ${file.reference.spring-security-crypto-5.8.0.jar} + ${file.reference.spring-security-crypto-5.8.0.jar}:\ + ${file.reference.apache-commons-configuration2-2.9.0.jar} # Space-separated list of extra javac options javac.compilerargs= javac.deprecation=false diff --git a/src/jnet/server/probe/NettyPing.java b/src/jnet/server/probe/NettyPing.java new file mode 100644 index 0000000..a20c54f --- /dev/null +++ b/src/jnet/server/probe/NettyPing.java @@ -0,0 +1,87 @@ +package jnet.server.probe; + +import io.netty.util.HashedWheelTimer; +import io.netty.util.Timeout; +import io.netty.util.TimerTask; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.concurrent.TimeUnit; +import jnet.lib.LogFile; +import jnet.lib.Status; +import jnet.lib.object.MapObject; +import jnet.server.Server; + + +public class NettyPing extends Thread { + + private static final HashedWheelTimer TIMER = new HashedWheelTimer(); // Netty časovač + + public NettyPing() { + } + + + + @Override + public void start() { + LogFile.printInfo("Ping probe start"); + for (MapObject mapObject : Server.mapObject) { + schedulePing(mapObject); + } + } + + private static void schedulePing(MapObject object) { + TIMER.newTimeout(new TimerTask() { + @Override + public void run(Timeout timeout) { + pingHost(object); + timeout.timer().newTimeout(this, 3, TimeUnit.SECONDS); // Opakuje každých 5 sekund + } + }, 0, TimeUnit.SECONDS); + } + + private static void pingHost(MapObject object) { + try { + String command = System.getProperty("os.name").startsWith("Windows") + ? "ping -n 1 " + object.getIp() + : "ping -c 1 " + object.getIp(); + + Process process = Runtime.getRuntime().exec(command); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + + String line; + boolean success = false; + int timeMs = -1; + + while ((line = reader.readLine()) != null) { + if (line.contains("TTL=") || line.contains("bytes from")) { + success = true; + timeMs = extractTime(line); + } + } + + //System.out.println("Ping na " + object.getIp() + (success ? " uspesny! RTT: " + timeMs + " ms" : " selhal!")); + if (object.getStatus() != Status.OK) { + PingResult.stateOnline(object); + } + + + process.waitFor(); + } catch (Exception e) { + System.err.println("Chyba pri pingu na " + object.getIp()); + PingResult.stateOffline(object); + //e.printStackTrace(); + } + } + + private static int extractTime(String line) { + String[] parts = line.split(" "); + for (String part : parts) { + if (part.contains("time=") || part.contains("čas=")) { + return Integer.parseInt(part.replaceAll("[^0-9]", "")); + } + } + return -1; + } + + +} diff --git a/src/jnet/server/probe/Ping2.java b/src/jnet/server/probe/Ping2.java deleted file mode 100644 index 1d04400..0000000 --- a/src/jnet/server/probe/Ping2.java +++ /dev/null @@ -1,78 +0,0 @@ -package jnet.server.probe; - -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import jnet.lib.LogFile; -import jnet.lib.Status; -import jnet.lib.object.MapObject; -import jnet.server.Server; -import org.icmp4j.IcmpPingRequest; -import org.icmp4j.IcmpPingResponse; -import org.icmp4j.IcmpPingUtil; - -public class Ping2 extends Thread { - - // Maximální počet paralelně běžících pingů - private static final int MAX_COUNT = 1000; - // Čekání před dalším opakováním pingu (ms) - private static final int WAITING = 1000; - - private static final ExecutorService executor = Executors.newFixedThreadPool(MAX_COUNT); - private static final List hosts = new CopyOnWriteArrayList<>(); // Dynamický seznam hostů - - public Ping2() { - - } - - @Override - public void start() { - LogFile.printInfo("Ping start ..."); - startPingLoop(); - } - - // Metoda pro spuštění opakovaného pingování - private static void startPingLoop() { - while (true) { - - Iterator itMapObject = Server.mapObject.iterator(); - while (itMapObject.hasNext()) { - MapObject obj = itMapObject.next(); - if (obj.isActive()) { - executor.submit(() -> pingHost(obj)); - } - } - - try { - Thread.sleep(WAITING); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - } - } - - // Metoda pro provedení jednoho pingu na host - private static void pingHost(MapObject obj) { - try { - IcmpPingRequest request = IcmpPingUtil.createIcmpPingRequest(); - request.setHost(obj.getIp()); - // Nastavení timeoutu na 3000 ms (3 sekundy) - request.setTimeout(3000); - - // Odeslání pingu a zpracování odpovědi - IcmpPingResponse response = IcmpPingUtil.executePingRequest(request); - if (response.getSuccessFlag()) { - //System.out.println("Ping na " + obj.getIp() + " úspěšný. Latence: " + response.getDuration() + " ms"); - new PingTestResult(obj).test(Status.OK, response.getDuration()); - } else { - System.out.println("Ping na " + obj.getName() + " (obj id: " + obj.getId() + ") selhal. Status: " + response.getErrorMessage()); - new PingTestResult(obj).test(Status.OFFLINE, response.getDuration()); - } - } catch (Exception e) { - LogFile.printErr("Ping error: " + obj.getIp() + ": " + e.getMessage()); - } - } - -} diff --git a/src/jnet/server/probe/PingResult.java b/src/jnet/server/probe/PingResult.java new file mode 100644 index 0000000..df2d8d3 --- /dev/null +++ b/src/jnet/server/probe/PingResult.java @@ -0,0 +1,53 @@ +package jnet.server.probe; + +import jnet.lib.Message; +import jnet.lib.Status; +import jnet.lib.object.Event; +import jnet.lib.object.MapObject; +import jnet.server.Database; +import jnet.server.Server; +import jnet.server.ServerMessageParser; + +public class PingResult { + + private static final int POKUS = 2; + + + public static void stateOnline(MapObject obj) { + // oveří jestli neni zarizeni vypnuto + if (obj.isActive()) { + // vynuluje ping pokusy + obj.setPingAttemp(0); + // nastavi status objektu + obj.setStatus(Status.OK); + // odesle informaci o novem stavu klientum + sendState(obj.getId(), Status.OK); + } + } + + public static void stateOffline(MapObject obj) { + // oveří jestli neni zarizeni vypnuto + if (obj.isActive()) { + if (obj.getPingAttemp() >= POKUS) { + // nastavi status objektu + obj.setStatus(Status.OFFLINE); + // odesle informaci o novem stavu klientum + sendState(obj.getId(), Status.OFFLINE); + // pridáni eventu + Event event = Database.addEvent(obj.getId(), "Offline", Event.TYPE_PING); + Server.events.add(event); + // Odeslani eventu klientum + ServerMessageParser.sendAll(new Message(Message.EVENT_NEW, event)); + } else { + obj.pingAttemp++; + } + + } + } + + private static void sendState(int object, int state) { + int[] o = {object, state}; + ServerMessageParser.sendAll(new Message(Message.STATUS_UPDATE, o)); + } + +} diff --git a/src/jnet/server/probe/PingTestResult.java b/src/jnet/server/probe/PingTestResult.java deleted file mode 100644 index cc2bef5..0000000 --- a/src/jnet/server/probe/PingTestResult.java +++ /dev/null @@ -1,91 +0,0 @@ -package jnet.server.probe; - -import java.util.ListIterator; -import jnet.lib.Message; -import jnet.lib.Status; -import jnet.lib.object.Event; -import jnet.lib.object.MapObject; -import jnet.server.Database; -import jnet.server.Server; -import jnet.server.ServerMessageParser; - -public class PingTestResult { - - private static MapObject obj; - private static ListIterator it_event = Server.events.listIterator(); - - public PingTestResult(MapObject obj) { - this.obj = obj; - } - - public static void test(int state, long latency) { - - // oveří jestli neni zarizeni vypnuto - if (obj.isActive()) { - - // oveří zda je stav rozdilny od predchozího - if (obj.getStatus() != state) { - - switch (state) { - case Status.OK: - obj.setPingAttemp(0); - - if (obj.getStatus() == Status.OFFLINE) { - // pokud je predchozi stav offline ukonci event -// Event event = Database.endEvent(obj.getId(), Event.TYPE_PING); -// if (event != null) { -// // odesle event klientum -// ServerMessageParser.sendAll(new Message(Message.EVENT_UPDATE, event)); -// // aktualizuje v seznamu -// while (it_event.hasNext()) { -// Event e = it_event.next(); -// if (e.getId() == event.getId()) { -// it_event.set(e); -// break; -// } -// } -// } - } - // zmena stavu v seznamu - System.out.println("online obj id: " + obj.getId()); - changeStateOnObject(state); - // odesle informaci o novem stavu klientum - int[] o = {obj.getId(), state}; - ServerMessageParser.sendAll(new Message(Message.STATUS_UPDATE, o)); - break; - case Status.OFFLINE: - if (obj.getPingAttemp() >= Server.config.getInt("ping_attempt")) { - // pridáni eventu - Event event = Database.addEvent(obj.getId(), "Offline", Event.TYPE_PING); - it_event.add(event); - // Odeslani eventu klientum - ServerMessageParser.sendAll(new Message(Message.EVENT_NEW, event)); - // zmena stavu v seznamu - System.err.println("offline obj id: " + obj.getId()); - changeStateOnObject(state); - // odesle informaci o novem stavu klientum - int[] oo = {obj.getId(), state}; - ServerMessageParser.sendAll(new Message(Message.STATUS_UPDATE, oo)); - } else { - obj.pingAttemp++; - System.out.println("offline obj id: " + obj.getId() + " pokus: " + obj.pingAttemp); - } - - break; - default: - System.err.println("default -> " + state); - throw new AssertionError(); - } - - } - } - - } - - private static synchronized void changeStateOnObject(int state) { - System.out.println("Change status " + obj.getId() + " -> " + state); - // upravi stav v listu - obj.setStatus(state); - } - -}