Style: Magic number, linelength and trailing whitespace
This commit is contained in:
@@ -27,8 +27,7 @@ public class ServerApp {
|
|||||||
|
|
||||||
EventBus eventBus = new EventBus();
|
EventBus eventBus = new EventBus();
|
||||||
SessionManager sessionManager = new SessionManager(eventBus);
|
SessionManager sessionManager = new SessionManager(eventBus);
|
||||||
eventBus.subscribe(
|
eventBus.subscribe(DisconnectEvent.class, event -> sessionManager.onDisconnect(event));
|
||||||
DisconnectEvent.class, event -> sessionManager.onDisconnect(event));
|
|
||||||
NetworkManager networkManager = new NetworkManager(port, sessionManager);
|
NetworkManager networkManager = new NetworkManager(port, sessionManager);
|
||||||
|
|
||||||
UserRegistry userRegistry = new UserRegistry();
|
UserRegistry userRegistry = new UserRegistry();
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public class Session {
|
|||||||
private final TransportLayer transport;
|
private final TransportLayer transport;
|
||||||
private final BlockingQueue<PrimitiveResponse> responseQueue;
|
private final BlockingQueue<PrimitiveResponse> responseQueue;
|
||||||
|
|
||||||
|
private final int RESPOND_QUEUE_SIZE = 32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Session with the given transport and event bus.
|
* Creates a new Session with the given transport and event bus.
|
||||||
*
|
*
|
||||||
@@ -23,7 +25,7 @@ public class Session {
|
|||||||
public Session(TransportLayer transport, EventBus eventBus) {
|
public Session(TransportLayer transport, EventBus eventBus) {
|
||||||
this.id = new SessionId();
|
this.id = new SessionId();
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
this.responseQueue = new ArrayBlockingQueue<>(32);
|
this.responseQueue = new ArrayBlockingQueue<>(RESPOND_QUEUE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+8
-7
@@ -1,15 +1,14 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.sessions;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.sessions;
|
||||||
|
|
||||||
|
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.transport.TransportLayer;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
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.transport.TransportLayer;
|
|
||||||
|
|
||||||
/** Manages active sessions in the server. */
|
/** Manages active sessions in the server. */
|
||||||
public class SessionManager {
|
public class SessionManager {
|
||||||
private Map<SessionId, SessionHandle> sessions;
|
private Map<SessionId, SessionHandle> sessions;
|
||||||
@@ -26,7 +25,7 @@ public class SessionManager {
|
|||||||
/**
|
/**
|
||||||
* Create new Session from provided transport.
|
* Create new Session from provided transport.
|
||||||
*
|
*
|
||||||
* <p> Will create both worker threads and start them.
|
* <p>Will create both worker threads and start them.
|
||||||
*
|
*
|
||||||
* @param transport to create session from
|
* @param transport to create session from
|
||||||
* @return newly created session
|
* @return newly created session
|
||||||
@@ -51,14 +50,16 @@ public class SessionManager {
|
|||||||
/**
|
/**
|
||||||
* Disconnect specified client
|
* Disconnect specified client
|
||||||
*
|
*
|
||||||
* <p> WARNING: Client will be uninformed about disconnect. Use with caution.
|
* <p>WARNING: Client will be uninformed about disconnect. Use with caution.
|
||||||
*
|
*
|
||||||
* @param id of the client to disconnect
|
* @param id of the client to disconnect
|
||||||
*/
|
*/
|
||||||
public void disconnect(SessionId id) {
|
public void disconnect(SessionId id) {
|
||||||
SessionHandle handle = sessions.get(id);
|
SessionHandle handle = sessions.get(id);
|
||||||
if (handle == null) {
|
if (handle == null) {
|
||||||
logger.warn("Requested to disconnect client with id {}. Failed as client is not found", id.value());
|
logger.warn(
|
||||||
|
"Requested to disconnect client with id {}. Failed as client is not found",
|
||||||
|
id.value());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("Disconnecting session {}", id.value());
|
logger.debug("Disconnecting session {}", id.value());
|
||||||
|
|||||||
+4
-1
@@ -29,7 +29,10 @@ public class SessionWriter implements Runnable {
|
|||||||
packet = new RawPacket(response.requestId(), response.payload());
|
packet = new RawPacket(response.requestId(), response.payload());
|
||||||
transport.write(packet);
|
transport.write(packet);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Unexpected exception while writing to transport. RawPacket: {}", packet, e);
|
logger.error(
|
||||||
|
"Unexpected exception while writing to transport. RawPacket: {}",
|
||||||
|
packet,
|
||||||
|
e);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.warn("Thread got interrupted", e);
|
logger.warn("Thread got interrupted", e);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user