mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Formatted code to follow google formatting guidelines using the Spotless formatter
This commit is contained in:
@@ -1,38 +1,40 @@
|
||||
package org.toop.frontend;
|
||||
|
||||
import org.toop.eventbus.Events;
|
||||
import org.toop.eventbus.GlobalEventBus;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.toop.eventbus.Events;
|
||||
import org.toop.eventbus.GlobalEventBus;
|
||||
|
||||
public class ConnectionManager {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(ConnectionManager.class);
|
||||
|
||||
/**
|
||||
* Map of serverId -> Server instances
|
||||
*/
|
||||
/** Map of serverId -> Server instances */
|
||||
private final Map<String, ServerConnection> serverConnections = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Starts a connection manager, to manage, connections.
|
||||
*/
|
||||
/** Starts a connection manager, to manage, connections. */
|
||||
public ConnectionManager() {
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.StartConnectionRequest.class, this::handleStartConnectionRequest);
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.StartConnection.class, this::handleStartConnection);
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.SendCommand.class, this::handleCommand);
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.Reconnect.class, this::handleReconnect);
|
||||
// GlobalEventBus.subscribeAndRegister(Events.ServerEvents.ChangeConnection.class, this::handleChangeConnection);
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.ForceCloseAllConnections.class, _ -> shutdownAll());
|
||||
GlobalEventBus.subscribeAndRegister(Events.ServerEvents.RequestsAllConnections.class, this::getAllConnections);
|
||||
GlobalEventBus.subscribeAndRegister(
|
||||
Events.ServerEvents.StartConnectionRequest.class,
|
||||
this::handleStartConnectionRequest);
|
||||
GlobalEventBus.subscribeAndRegister(
|
||||
Events.ServerEvents.StartConnection.class, this::handleStartConnection);
|
||||
GlobalEventBus.subscribeAndRegister(
|
||||
Events.ServerEvents.SendCommand.class, this::handleCommand);
|
||||
GlobalEventBus.subscribeAndRegister(
|
||||
Events.ServerEvents.Reconnect.class, this::handleReconnect);
|
||||
// GlobalEventBus.subscribeAndRegister(Events.ServerEvents.ChangeConnection.class,
|
||||
// this::handleChangeConnection);
|
||||
GlobalEventBus.subscribeAndRegister(
|
||||
Events.ServerEvents.ForceCloseAllConnections.class, _ -> shutdownAll());
|
||||
GlobalEventBus.subscribeAndRegister(
|
||||
Events.ServerEvents.RequestsAllConnections.class, this::getAllConnections);
|
||||
}
|
||||
|
||||
private String startConnectionRequest(String ip, String port) {
|
||||
@@ -49,18 +51,24 @@ public class ConnectionManager {
|
||||
}
|
||||
|
||||
private void handleStartConnectionRequest(Events.ServerEvents.StartConnectionRequest request) {
|
||||
request.future().complete(this.startConnectionRequest(request.ip(), request.port())); // TODO: Maybe post ConnectionEstablished event.
|
||||
request.future()
|
||||
.complete(
|
||||
this.startConnectionRequest(
|
||||
request.ip(),
|
||||
request.port())); // TODO: Maybe post ConnectionEstablished event.
|
||||
}
|
||||
|
||||
private void handleStartConnection(Events.ServerEvents.StartConnection event) {
|
||||
GlobalEventBus.post(new Events.ServerEvents.ConnectionEstablished(
|
||||
this.startConnectionRequest(event.ip(), event.port()),
|
||||
event.ip(),
|
||||
event.port()
|
||||
));
|
||||
GlobalEventBus.post(
|
||||
new Events.ServerEvents.ConnectionEstablished(
|
||||
this.startConnectionRequest(event.ip(), event.port()),
|
||||
event.ip(),
|
||||
event.port()));
|
||||
}
|
||||
|
||||
private void handleCommand(Events.ServerEvents.SendCommand event) { // TODO: Move this to ServerConnection class, keep it internal.
|
||||
private void handleCommand(
|
||||
Events.ServerEvents.SendCommand
|
||||
event) { // TODO: Move this to ServerConnection class, keep it internal.
|
||||
ServerConnection serverConnection = this.serverConnections.get(event.connectionId());
|
||||
if (serverConnection != null) {
|
||||
serverConnection.sendCommandByString(event.args());
|
||||
@@ -82,18 +90,21 @@ public class ConnectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
// private void handleChangeConnection(Events.ServerEvents.ChangeConnection event) {
|
||||
// ServerConnection serverConnection = this.serverConnections.get(event.connectionId());
|
||||
// if (serverConnection != null) {
|
||||
// try {
|
||||
// serverConnection.connect(event.ip(), event.port());
|
||||
// logger.info("Server {} changed connection to {}:{}", event.connectionId(), event.ip(), event.port());
|
||||
// } catch (Exception e) {
|
||||
// logger.error("Server {} failed to change connection", event.connectionId(), e);
|
||||
// GlobalEventBus.post(new Events.ServerEvents.CouldNotConnect(event.connectionId()));
|
||||
// }
|
||||
// }
|
||||
// } TODO
|
||||
// private void handleChangeConnection(Events.ServerEvents.ChangeConnection event) {
|
||||
// ServerConnection serverConnection = this.serverConnections.get(event.connectionId());
|
||||
// if (serverConnection != null) {
|
||||
// try {
|
||||
// serverConnection.connect(event.ip(), event.port());
|
||||
// logger.info("Server {} changed connection to {}:{}", event.connectionId(),
|
||||
// event.ip(), event.port());
|
||||
// } catch (Exception e) {
|
||||
// logger.error("Server {} failed to change connection", event.connectionId(),
|
||||
// e);
|
||||
// GlobalEventBus.post(new
|
||||
// Events.ServerEvents.CouldNotConnect(event.connectionId()));
|
||||
// }
|
||||
// }
|
||||
// } TODO
|
||||
|
||||
private void getAllConnections(Events.ServerEvents.RequestsAllConnections request) {
|
||||
List<ServerConnection> a = new ArrayList<>(this.serverConnections.values());
|
||||
@@ -105,4 +116,4 @@ public class ConnectionManager {
|
||||
this.serverConnections.clear();
|
||||
logger.info("All servers shut down");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user