mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Added logging.
This commit is contained in:
@@ -5,47 +5,64 @@ import org.toop.eventbus.Events;
|
||||
import org.toop.eventbus.GlobalEventBus;
|
||||
import org.toop.server.Server;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
public class Main {
|
||||
private static final Logger logger = LogManager.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerBackend.class, e -> {
|
||||
System.out.println("Server backend has changed to -> " + e.backend());
|
||||
});
|
||||
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerIp.class, e -> {
|
||||
System.out.println("Server ip has changed to -> " + e.ip());
|
||||
});
|
||||
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerPort.class, e -> {
|
||||
System.out.println("Server port has changed to -> " + e.port());
|
||||
});
|
||||
if (!initEvents()) {
|
||||
throw new RuntimeException("A event could not be initialized");
|
||||
}
|
||||
|
||||
Server server = new Server(Server.ServerBackend.LOCAL, "127.0.0.1", "5000");
|
||||
server.setBackend(Server.ServerBackend.REMOTE);
|
||||
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnCommand.class, e -> {
|
||||
if (e.command() == Server.Command.LOGIN) {
|
||||
System.out.println("LOGIN command -> " + String.join(" ", e.args()));
|
||||
logger.info("LOGIN command -> {}", String.join(" ", e.args()));
|
||||
}
|
||||
else if (e.command() == Server.Command.HELP) {
|
||||
System.out.println("HELP command -> " + String.join(" ", e.args()));
|
||||
logger.info("HELP command -> {}", String.join(" ", e.args()));
|
||||
}
|
||||
else {
|
||||
System.out.println(e.command().toString());
|
||||
logger.info(e.command().toString());
|
||||
}
|
||||
});
|
||||
|
||||
Server.Message msg = server.sendCommand(Server.Command.LOGIN, "move");
|
||||
server.sendCommand(Server.Command.HELP, "test", "test2");
|
||||
server.sendCommand(Server.Command.BYE);
|
||||
|
||||
GlobalEventBus.post(new Events.ServerEvents.command(Server.Command.HELP, "test", "test2"));
|
||||
GlobalEventBus.post(new Events.ServerEvents.command(Server.Command.BYE));
|
||||
GlobalEventBus.post(new Events.ServerEvents.changeServerIp("127.1.1.1"));
|
||||
GlobalEventBus.post(new Events.ServerEvents.changeServerPort("5003"));
|
||||
server.setBackend(Server.ServerBackend.REMOTE);
|
||||
|
||||
System.out.println(msg);
|
||||
System.out.println(server);
|
||||
|
||||
Window.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false if any event could not be initialized.
|
||||
*/
|
||||
private static boolean initEvents() {
|
||||
try {
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerBackend.class, e ->
|
||||
logger.info("Changing server backend state to {}", e.backend())
|
||||
);
|
||||
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerIp.class, e ->
|
||||
logger.info("Changing server ip to {}", e.ip())
|
||||
);
|
||||
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.OnChangingServerPort.class, e ->
|
||||
logger.info("Changing server port to {}", e.port())
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user