Edit server-side code to conform to checkstyle rules #181
@@ -5,9 +5,7 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.events.DisconnectEvent;
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.events.EventBus;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.events.EventBus;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionManager;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionManager;
|
||||||
|
|
||||||
/**
|
/** Application class for starting the server. */
|
||||||
* Application class for starting the server.
|
|
||||||
*/
|
|
||||||
public class ServerApp {
|
public class ServerApp {
|
||||||
public static void start(String arg) {
|
public static void start(String arg) {
|
||||||
int port = Integer.parseInt(arg);
|
int port = Integer.parseInt(arg);
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import java.net.Socket;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/** Creates and manages the server socket. Accepts new incoming connections and creates sessions. */
|
||||||
* Creates and manages the server socket. Accepts new incoming connections and creates sessions.
|
|
||||||
*/
|
|
||||||
public class NetworkManager implements Runnable {
|
public class NetworkManager implements Runnable {
|
||||||
private Integer port;
|
private Integer port;
|
||||||
private Logger logger;
|
private Logger logger;
|
||||||
@@ -39,9 +37,7 @@ public class NetworkManager implements Runnable {
|
|||||||
this.eventBus.subscribe(DisconnectEvent.class, event -> clientDisconnected(event));
|
this.eventBus.subscribe(DisconnectEvent.class, event -> clientDisconnected(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Starts the internal thread to accept new connections. */
|
||||||
* Starts the internal thread to accept new connections.
|
|
||||||
*/
|
|
||||||
public void start() {
|
public void start() {
|
||||||
logger.debug("Starting server at port " + port);
|
logger.debug("Starting server at port " + port);
|
||||||
thread.start();
|
thread.start();
|
||||||
@@ -56,9 +52,7 @@ public class NetworkManager implements Runnable {
|
|||||||
logger.info("Session " + event.sessionId().value() + " disconnected adhasghd");
|
logger.info("Session " + event.sessionId().value() + " disconnected adhasghd");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Runs the network manager loop, accepting connections. */
|
||||||
* Runs the network manager loop, accepting connections.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try (ServerSocket serverSocket = new ServerSocket(port)) {
|
try (ServerSocket serverSocket = new ServerSocket(port)) {
|
||||||
|
|||||||
+1
-3
@@ -2,7 +2,5 @@ package ch.unibas.dmi.dbis.cs108.casono.server.network.events;
|
|||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionId;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionId;
|
||||||
|
|
||||||
/**
|
/** Represents a disconnect event for a session. */
|
||||||
* Represents a disconnect event for a session.
|
|
||||||
*/
|
|
||||||
public record DisconnectEvent(SessionId sessionId) implements Event {}
|
public record DisconnectEvent(SessionId sessionId) implements Event {}
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.events;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.events;
|
||||||
|
|
||||||
/**
|
/** Marker interface for events in the event bus system. */
|
||||||
* Marker interface for events in the event bus system.
|
|
||||||
*/
|
|
||||||
interface Event {}
|
interface Event {}
|
||||||
|
|||||||
@@ -7,9 +7,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/** A simple event bus for publishing and subscribing to events. */
|
||||||
* A simple event bus for publishing and subscribing to events.
|
|
||||||
*/
|
|
||||||
public class EventBus {
|
public class EventBus {
|
||||||
private final Map<Class<?>, List<Consumer<Object>>> handlers = new ConcurrentHashMap<>();
|
private final Map<Class<?>, List<Consumer<Object>>> handlers = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ import java.io.IOException;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/** Represents a client session in the network server. */
|
||||||
* Represents a client session in the network server.
|
|
||||||
*/
|
|
||||||
public class Session implements Runnable {
|
public class Session implements Runnable {
|
||||||
private SessionId id;
|
private SessionId id;
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
@@ -18,12 +16,12 @@ public class Session implements Runnable {
|
|||||||
private Logger logger;
|
private Logger logger;
|
||||||
private Boolean running;
|
private Boolean running;
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Session with the given transport and event bus.
|
* Creates a new Session with the given transport and event bus.
|
||||||
*
|
*
|
||||||
* @param transport the transport layer for communication
|
* @param transport the transport layer for communication
|
||||||
* @param eventBus the event bus for publishing events
|
* @param eventBus the event bus for publishing events
|
||||||
* @throws IOException if an I/O error occurs during initialization
|
* @throws IOException if an I/O error occurs during initialization
|
||||||
*/
|
*/
|
||||||
public Session(TransportLayer transport, EventBus eventBus) throws IOException {
|
public Session(TransportLayer transport, EventBus eventBus) throws IOException {
|
||||||
@@ -46,9 +44,7 @@ public class Session implements Runnable {
|
|||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Starts the session thread. */
|
||||||
* Starts the session thread.
|
|
||||||
*/
|
|
||||||
public void start() {
|
public void start() {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
@@ -63,9 +59,7 @@ public class Session implements Runnable {
|
|||||||
this.running = false;
|
this.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Runs the session loop, reading from the transport. */
|
||||||
* Runs the session loop, reading from the transport.
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (running) {
|
while (running) {
|
||||||
|
|||||||
+2
-6
@@ -2,15 +2,11 @@ package ch.unibas.dmi.dbis.cs108.casono.server.network.sessions;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/** Represents a unique identifier for a session. */
|
||||||
* Represents a unique identifier for a session.
|
|
||||||
*/
|
|
||||||
public class SessionId {
|
public class SessionId {
|
||||||
private final UUID value;
|
private final UUID value;
|
||||||
|
|
||||||
/**
|
/** Creates a new SessionId with a randomly generated UUID. */
|
||||||
* Creates a new SessionId with a randomly generated UUID.
|
|
||||||
*/
|
|
||||||
public SessionId() {
|
public SessionId() {
|
||||||
this.value = UUID.randomUUID();
|
this.value = UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-6
@@ -3,15 +3,11 @@ package ch.unibas.dmi.dbis.cs108.casono.server.network.sessions;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
/**
|
/** Manages active sessions in the server. */
|
||||||
* Manages active sessions in the server.
|
|
||||||
*/
|
|
||||||
public class SessionManager {
|
public class SessionManager {
|
||||||
private Map<SessionId, Session> sessions;
|
private Map<SessionId, Session> sessions;
|
||||||
|
|
||||||
/**
|
/** Constructs a new SessionManager. */
|
||||||
* Constructs a new SessionManager.
|
|
||||||
*/
|
|
||||||
public SessionManager() {
|
public SessionManager() {
|
||||||
this.sessions = new ConcurrentHashMap<>();
|
this.sessions = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -6,9 +6,7 @@ import java.io.IOException;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/** Implements TCP-based transport layer for network communication. */
|
||||||
* Implements TCP-based transport layer for network communication.
|
|
||||||
*/
|
|
||||||
public class TcpTransport implements TransportLayer {
|
public class TcpTransport implements TransportLayer {
|
||||||
private Socket socket;
|
private Socket socket;
|
||||||
private DataInputStream in;
|
private DataInputStream in;
|
||||||
|
|||||||
+1
-3
@@ -2,9 +2,7 @@ package ch.unibas.dmi.dbis.cs108.casono.server.network.transport;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/** Interface for transport layer implementations. */
|
||||||
* Interface for transport layer implementations.
|
|
||||||
*/
|
|
||||||
public interface TransportLayer {
|
public interface TransportLayer {
|
||||||
/**
|
/**
|
||||||
* Reads data from the transport layer.
|
* Reads data from the transport layer.
|
||||||
|
|||||||
Reference in New Issue
Block a user