Compare commits
No commits in common. "ca6161b5052e8fb1b5b0c2c8f39570b86558ace2" and "8276df1596ca1adf562fb47d7baf30ef53258a3f" have entirely different histories.
ca6161b505
...
8276df1596
|
|
@ -1 +0,0 @@
|
|||
*.log
|
||||
|
|
@ -6,9 +6,8 @@ mysql_password=Michal2407
|
|||
mysql_database=jnet
|
||||
server_port=1225
|
||||
debug=true
|
||||
ping_attempt=4
|
||||
ping_timeout=2
|
||||
ping_repeat=3
|
||||
ping_attempt=2
|
||||
ping_timeout=2000
|
||||
instability_attempt=2
|
||||
instability_limit=1
|
||||
instability_limit=1000
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
03.02.25 16:34:13 I ---------------------------------------------
|
||||
03.02.25 16:34:13 I jNet Server
|
||||
03.02.25 16:34:13 I Version: 1 (Mon Feb 03 16:33:44 CET 2025)
|
||||
03.02.25 16:34:13 I ---------------------------------------------
|
||||
03.02.25 16:34:13 I
|
||||
03.02.25 16:34:13 I Loading config ...
|
||||
03.02.25 16:34:13 E fail. Soubor konfigurace nenalezen config.properties (Systém nemůže nalézt uvedený soubor)
|
||||
84
log.log
84
log.log
|
|
@ -1,60 +1,24 @@
|
|||
13.02.25 18:7:16 I ---------------------------------------------
|
||||
13.02.25 18:7:16 I jNet Server
|
||||
13.02.25 18:7:16 I Version: 1 (Thu Feb 13 09:04:35 CET 2025)
|
||||
13.02.25 18:7:16 I ---------------------------------------------
|
||||
13.02.25 18:7:16 I
|
||||
13.02.25 18:7:16 I Loading config ...
|
||||
13.02.25 18:7:16 I successfully
|
||||
13.02.25 18:7:16 D Debug mode on
|
||||
13.02.25 18:7:16 I Connecting to a selected database ...
|
||||
13.02.25 18:7:16 I successfully
|
||||
13.02.25 18:7:16 I Loading user list ...
|
||||
13.02.25 18:7:16 I load 2 user(s)
|
||||
13.02.25 18:7:16 I Loading map list ...
|
||||
13.02.25 18:7:16 I load 6 map(s)
|
||||
13.02.25 18:7:16 I Loading object list ...
|
||||
13.02.25 18:7:17 I load 8 object(s)
|
||||
13.02.25 18:7:17 I Loading object type ...
|
||||
13.02.25 18:7:17 I load 12 type(s)
|
||||
13.02.25 18:7:17 I Loading SNMP profile ...
|
||||
13.02.25 18:7:17 I load 2 profile(s)
|
||||
13.02.25 18:7:17 I Loading events ...
|
||||
13.02.25 18:7:17 I load 30 event(s)
|
||||
13.02.25 18:7:17 I Ping probe start
|
||||
13.02.25 18:7:17 I Server is ready and listening on port 1225
|
||||
13.02.25 18:7:49 D -> Message type: 1
|
||||
13.02.25 18:7:49 I Authorization request send (kubernetes.docker.internal)
|
||||
13.02.25 18:7:49 D <- Message type: 3
|
||||
13.02.25 18:7:49 D -> Message type: 4
|
||||
13.02.25 18:7:49 I User: michal logged in (kubernetes.docker.internal)
|
||||
13.02.25 18:7:49 D <- Message type: 5
|
||||
13.02.25 18:7:49 D <- Message type: 9
|
||||
13.02.25 18:7:49 D <- For all. Message type: 7
|
||||
13.02.25 18:7:49 D <- Message type: 13
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 8
|
||||
13.02.25 18:7:49 D <- Message type: 11
|
||||
13.02.25 18:7:49 D <- Message type: 11
|
||||
13.02.25 18:7:49 D <- Message type: 100
|
||||
13.02.25 18:7:49 D <- Message type: 100
|
||||
13.02.25 18:7:49 D <- Message type: 100
|
||||
13.02.25 18:7:49 D <- Message type: 100
|
||||
13.02.25 18:7:49 D <- Message type: 100
|
||||
13.02.25 18:7:49 D <- Message type: 100
|
||||
13.02.25 18:7:49 D <- Message type: 14
|
||||
13.02.25 18:7:49 D <- Message type: 110
|
||||
13.02.25 18:7:49 D <- Message type: 107
|
||||
13.02.25 18:7:49 D <- Message type: 107
|
||||
13.02.25 18:8:31 D -> Message type: 105
|
||||
13.02.25 18:8:31 D <- For all. Message type: 105
|
||||
13.02.25 18:8:31 D <- For all. Message type: 108
|
||||
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
|
||||
|
|
|
|||
|
|
@ -635,6 +635,7 @@ public class Database {
|
|||
try {
|
||||
|
||||
String select_query = "SELECT * FROM events WHERE object = '" + objectId + "' && type = '" + type + "' ORDER BY id DESC LIMIT 1";
|
||||
System.err.println(select_query);
|
||||
PreparedStatement stmt = getCurrentConnection().prepareStatement(select_query);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
// Process the result
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package jnet.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import jnet.lib.BuilddDate;
|
||||
|
|
@ -47,6 +45,7 @@ public class Server {
|
|||
}
|
||||
|
||||
|
||||
LogWindow.addRow("tset");
|
||||
|
||||
LogFile.clear();
|
||||
LogFile.setDebug(false);
|
||||
|
|
@ -144,30 +143,5 @@ public class Server {
|
|||
np.start();
|
||||
|
||||
}
|
||||
|
||||
public static void restartServer() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
try {
|
||||
String java = System.getProperty("java.home") + "/bin/java";
|
||||
File jarFile = new File(Server.class
|
||||
.getProtectionDomain().getCodeSource().getLocation().getPath());
|
||||
|
||||
List<String> command = new ArrayList<>();
|
||||
command.add(java);
|
||||
command.add("-jar");
|
||||
command.add(jarFile.getAbsolutePath());
|
||||
|
||||
new ProcessBuilder(command).start();
|
||||
System.exit(0);
|
||||
} catch (IOException ex) {
|
||||
LogFile.printErr("Restart failed! " + ex.getMessage());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
LogFile.printErr("Restart failed! " + e.getMessage());
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import io.netty.channel.Channel;
|
|||
import io.netty.channel.group.ChannelGroup;
|
||||
import io.netty.channel.group.DefaultChannelGroup;
|
||||
import io.netty.util.concurrent.GlobalEventExecutor;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ListIterator;
|
||||
import jnet.lib.LogFile;
|
||||
|
|
@ -80,7 +79,6 @@ public class ServerMessageParser {
|
|||
sendAll(new Message(Message.ONLINE_CLIENTS, Server.onlineClients));
|
||||
// odeslat nastaveni serveru
|
||||
ServerConfig sc = new ServerConfig(
|
||||
Server.config.getInt("ping_repeat"),
|
||||
Server.config.getInt("ping_attempt"),
|
||||
Server.config.getInt("ping_timeout"),
|
||||
Server.config.getInt("instability_attempt"),
|
||||
|
|
@ -111,16 +109,6 @@ public class ServerMessageParser {
|
|||
LogFile.printInfo("Authorization failed (ser: " + username + " )");
|
||||
}
|
||||
break;
|
||||
|
||||
case Message.RESTART:
|
||||
LogFile.printInfo("Prijat pozadavek na restart serveru");
|
||||
Server.restartServer();
|
||||
break;
|
||||
|
||||
case Message.UPTIME:
|
||||
long uptime = ManagementFactory.getRuntimeMXBean().getUptime();
|
||||
send(Message.UPTIME, uptime);
|
||||
break;
|
||||
|
||||
case Message.NEW_OBJECT_TYPE:
|
||||
ObjectType not = (ObjectType) msg.getMsg();
|
||||
|
|
@ -148,7 +136,7 @@ public class ServerMessageParser {
|
|||
case Message.ADD_OBJECT:
|
||||
MapObject mo = Database.addMapObject((MapObject) msg.getMsg());
|
||||
// pridat do seznamu
|
||||
Server.mapObject.add(mo);
|
||||
iteratorMapObject.add(mo);
|
||||
// odesle všem novy objekt
|
||||
sendAll(new Message(Message.ADD_OBJECT, mo));
|
||||
// prida event a odesle ho
|
||||
|
|
@ -285,7 +273,6 @@ public class ServerMessageParser {
|
|||
case Message.SERVER_CONFIG:
|
||||
ServerConfig sc = (ServerConfig) msg.getMsg();
|
||||
// ulozeni
|
||||
Server.config.setInt("ping_repeat", sc.getPingRepeat());
|
||||
Server.config.setInt("ping_attempt", sc.getPingAttempt());
|
||||
Server.config.setInt("ping_timeout", sc.getPingTimeout());
|
||||
Server.config.setInt("instability_attempt", sc.getInstabilityAttempt());
|
||||
|
|
|
|||
|
|
@ -11,36 +11,39 @@ import jnet.lib.Status;
|
|||
import jnet.lib.object.MapObject;
|
||||
import jnet.server.Server;
|
||||
|
||||
public class NettyPing extends Thread {
|
||||
|
||||
public class NettyPing extends Thread {
|
||||
|
||||
private static final HashedWheelTimer TIMER = new HashedWheelTimer(); // Netty časovač
|
||||
|
||||
public NettyPing() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
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, Server.config.getInt("ping_repeat"), TimeUnit.SECONDS); // Opakuje každých x sekund
|
||||
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 -w " + String.valueOf((Server.config.getInt("ping_timeout")*1000)) + " " + object.getIp() // Timeout 2000 ms (Windows)
|
||||
: "ping -c 1 -W " + String.valueOf(Server.config.getInt("ping_timeout")) + " " + object.getIp(); // Timeout 2 sec (Linux)
|
||||
? "ping -n 1 " + object.getIp()
|
||||
: "ping -c 1 " + object.getIp();
|
||||
|
||||
Process process = Runtime.getRuntime().exec(command);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
|
|
@ -57,18 +60,16 @@ public class NettyPing extends Thread {
|
|||
}
|
||||
|
||||
//System.out.println("Ping na " + object.getIp() + (success ? " uspesny! RTT: " + timeMs + " ms" : " selhal!"));
|
||||
if (success) {
|
||||
if (object.getStatus() != Status.OK) {
|
||||
PingResult.stateOnline(object);
|
||||
}
|
||||
} else {
|
||||
PingResult.stateOffline(object);
|
||||
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);
|
||||
LogFile.printErr("Chyba pri pingu na " + object.getIp() + " " + e.getMessage());
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -81,5 +82,6 @@ public class NettyPing extends Thread {
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,26 +10,14 @@ import jnet.server.ServerMessageParser;
|
|||
|
||||
public class PingResult {
|
||||
|
||||
private static final int POKUS = Server.config.getInt("ping_attempt");
|
||||
private static final int POKUS = 2;
|
||||
|
||||
|
||||
public static void stateOnline(MapObject obj) {
|
||||
// oveří jestli neni zarizeni vypnuto
|
||||
if (obj.isActive() && obj.getStatus() != Status.OK) {
|
||||
if (obj.isActive()) {
|
||||
// vynuluje ping pokusy
|
||||
obj.setPingAttemp(0);
|
||||
// pokud byl předchozí stav offline ukončí event
|
||||
if (obj.getStatus() == Status.OFFLINE) {
|
||||
// aktualizace eventu
|
||||
Event event = Database.endEvent(obj.getId(), Event.TYPE_PING);
|
||||
for (int i = 0; i < Server.events.size(); i++) {
|
||||
if (Server.events.get(i).getId() == event.getId()) {
|
||||
Server.events.set(i, event);
|
||||
}
|
||||
}
|
||||
// odeslani aktualizovaného eventu
|
||||
ServerMessageParser.sendAll(Message.EVENT_UPDATE, event);
|
||||
}
|
||||
|
||||
// nastavi status objektu
|
||||
obj.setStatus(Status.OK);
|
||||
// odesle informaci o novem stavu klientum
|
||||
|
|
@ -40,8 +28,7 @@ public class PingResult {
|
|||
public static void stateOffline(MapObject obj) {
|
||||
// oveří jestli neni zarizeni vypnuto
|
||||
if (obj.isActive()) {
|
||||
if (obj.getPingAttemp() >= POKUS && obj.getStatus() != Status.OFFLINE) {
|
||||
System.err.println("objekt: " + obj.getName() + " pokus: " + obj.getPingAttemp());
|
||||
if (obj.getPingAttemp() >= POKUS) {
|
||||
// nastavi status objektu
|
||||
obj.setStatus(Status.OFFLINE);
|
||||
// odesle informaci o novem stavu klientum
|
||||
|
|
|
|||
Loading…
Reference in New Issue