mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 19:04:49 +00:00
Reworked NetworkingClientManager into SRP model.
This commit is contained in:
@@ -134,7 +134,8 @@ public final class GlobalEventBus {
|
||||
for (Consumer<? super EventType> listener : classListeners) {
|
||||
try {
|
||||
listener.accept(event);
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,7 +147,8 @@ public final class GlobalEventBus {
|
||||
for (Consumer<? super EventType> listener : genericListeners) {
|
||||
try {
|
||||
listener.accept(event);
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
package org.toop.framework.networking;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.networking.interfaces.NetworkingClient;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
import org.toop.framework.networking.interfaces.NetworkingClientManager;
|
||||
|
||||
public class NetworkingClientEventListener {
|
||||
|
||||
private static final Logger logger = LogManager.getLogger(NetworkingClientEventListener.class);
|
||||
private final NetworkingClientManager clientManager;
|
||||
|
||||
/** Starts a connection manager, to manage, connections. */
|
||||
public NetworkingClientEventListener(NetworkingClientManager clientManager) {
|
||||
this.clientManager = clientManager;
|
||||
new EventFlow()
|
||||
.listen(this::handleStartClient)
|
||||
.listen(this::handleCommand)
|
||||
.listen(this::handleSendLogin)
|
||||
.listen(this::handleSendLogout)
|
||||
.listen(this::handleSendGetPlayerlist)
|
||||
.listen(this::handleSendGetGamelist)
|
||||
.listen(this::handleSendSubscribe)
|
||||
.listen(this::handleSendMove)
|
||||
.listen(this::handleSendChallenge)
|
||||
.listen(this::handleSendAcceptChallenge)
|
||||
.listen(this::handleSendForfeit)
|
||||
.listen(this::handleSendMessage)
|
||||
.listen(this::handleSendHelp)
|
||||
.listen(this::handleSendHelpForCommand)
|
||||
.listen(this::handleCloseClient)
|
||||
.listen(this::handleChangeClientHost)
|
||||
.listen(this::handleGetAllConnections)
|
||||
.listen(this::handleShutdownAll);
|
||||
}
|
||||
|
||||
void handleStartClient(NetworkEvents.StartClient<? extends NetworkingClient> event) {
|
||||
long clientId = clientManager.startClient(event.networkingClientClass(), event.host(), event.port()).orElse(-1);
|
||||
logger.info("Client {} started", clientId);
|
||||
try {
|
||||
new EventFlow()
|
||||
.addPostEvent(new NetworkEvents.StartClientResponse(clientId, event.getIdentifier()))
|
||||
.asyncPostEvent();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
void handleCommand(NetworkEvents.SendCommand event) {
|
||||
String args = String.join(" ", event.args());
|
||||
logger.error(args);
|
||||
clientManager.sendCommand(event.clientId(), args);
|
||||
}
|
||||
|
||||
void handleSendLogin(NetworkEvents.SendLogin event) {
|
||||
logger.error("{}", event.username());
|
||||
clientManager.sendCommand(event.clientId(), String.format("LOGIN %s", event.username()));
|
||||
}
|
||||
|
||||
private void handleSendLogout(NetworkEvents.SendLogout event) {
|
||||
clientManager.sendCommand(event.clientId(), "LOGOUT");
|
||||
}
|
||||
|
||||
private void handleSendGetPlayerlist(NetworkEvents.SendGetPlayerlist event) {
|
||||
clientManager.sendCommand(event.clientId(), "GET PLAYERLIST");
|
||||
}
|
||||
|
||||
private void handleSendGetGamelist(NetworkEvents.SendGetGamelist event) {
|
||||
clientManager.sendCommand(event.clientId(), "GET GAMELIST");
|
||||
}
|
||||
|
||||
private void handleSendSubscribe(NetworkEvents.SendSubscribe event) {
|
||||
clientManager.sendCommand(event.clientId(), String.format("SUBSCRIBE %s", event.gameType()));
|
||||
}
|
||||
|
||||
private void handleSendMove(NetworkEvents.SendMove event) {
|
||||
clientManager.sendCommand(event.clientId(), String.format("MOVE %d", event.moveNumber()));
|
||||
}
|
||||
|
||||
private void handleSendChallenge(NetworkEvents.SendChallenge event) {
|
||||
clientManager.sendCommand(
|
||||
event.clientId(),
|
||||
String.format("CHALLENGE %s %s", event.usernameToChallenge(), event.gameType()));
|
||||
}
|
||||
|
||||
private void handleSendAcceptChallenge(NetworkEvents.SendAcceptChallenge event) {
|
||||
clientManager.sendCommand(event.clientId(), String.format("CHALLENGE ACCEPT %d", event.challengeId()));
|
||||
}
|
||||
|
||||
private void handleSendForfeit(NetworkEvents.SendForfeit event) {
|
||||
clientManager.sendCommand(event.clientId(), "FORFEIT");
|
||||
}
|
||||
|
||||
private void handleSendMessage(NetworkEvents.SendMessage event) {
|
||||
clientManager.sendCommand(event.clientId(), String.format("MESSAGE %s", event.message()));
|
||||
}
|
||||
|
||||
private void handleSendHelp(NetworkEvents.SendHelp event) {
|
||||
clientManager.sendCommand(event.clientId(), "HELP");
|
||||
}
|
||||
|
||||
private void handleSendHelpForCommand(NetworkEvents.SendHelpForCommand event) {
|
||||
clientManager.sendCommand(event.clientId(), String.format("HELP %s", event.command()));
|
||||
}
|
||||
|
||||
private void handleChangeClientHost(NetworkEvents.ChangeClientHost event) {
|
||||
// NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
// client.closeConnection();
|
||||
// startClientRequest(event.ip(), event.port(), event.clientId());
|
||||
}
|
||||
|
||||
void handleCloseClient(NetworkEvents.CloseClient event) {
|
||||
this.clientManager.closeClient(event.clientId());
|
||||
}
|
||||
|
||||
void handleGetAllConnections(NetworkEvents.RequestsAllClients request) {
|
||||
// List<NetworkingClient> a = new ArrayList<>(this.networkClients.values());
|
||||
// request.future().complete(a);
|
||||
}
|
||||
|
||||
public void handleShutdownAll(NetworkEvents.ForceCloseAllClients request) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
@@ -5,193 +5,57 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.toop.framework.SnowflakeGenerator;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
|
||||
public class NetworkingClientManager {
|
||||
import org.toop.framework.networking.interfaces.NetworkingClient;
|
||||
|
||||
public class NetworkingClientManager implements org.toop.framework.networking.interfaces.NetworkingClientManager {
|
||||
private static final Logger logger = LogManager.getLogger(NetworkingClientManager.class);
|
||||
private final Map<Long, NetworkingClient> networkClients = new ConcurrentHashMap<>();
|
||||
|
||||
/** Map of serverId -> Server instances */
|
||||
final Map<Long, NetworkingClient> networkClients = new ConcurrentHashMap<>();
|
||||
public NetworkingClientManager() {}
|
||||
|
||||
/** Starts a connection manager, to manage, connections. */
|
||||
public NetworkingClientManager() throws NetworkingInitializationException {
|
||||
@Override
|
||||
public OptionalLong startClient(Class<? extends NetworkingClient> networkingClientClass, String host, int port) {
|
||||
long clientId = SnowflakeGenerator.nextId();
|
||||
try {
|
||||
new EventFlow()
|
||||
.listen(this::handleStartClient)
|
||||
.listen(this::handleCommand)
|
||||
.listen(this::handleSendLogin)
|
||||
.listen(this::handleSendLogout)
|
||||
.listen(this::handleSendGetPlayerlist)
|
||||
.listen(this::handleSendGetGamelist)
|
||||
.listen(this::handleSendSubscribe)
|
||||
.listen(this::handleSendMove)
|
||||
.listen(this::handleSendChallenge)
|
||||
.listen(this::handleSendAcceptChallenge)
|
||||
.listen(this::handleSendForfeit)
|
||||
.listen(this::handleSendMessage)
|
||||
.listen(this::handleSendHelp)
|
||||
.listen(this::handleSendHelpForCommand)
|
||||
.listen(this::handleCloseClient)
|
||||
.listen(this::handleChangeClientHost)
|
||||
.listen(this::handleGetAllConnections)
|
||||
.listen(this::handleShutdownAll);
|
||||
logger.info("NetworkingClientManager initialized");
|
||||
NetworkingClient networkingClient = networkingClientClass
|
||||
.getConstructor(long.class, String.class, int.class).newInstance(clientId, host, port);
|
||||
this.networkClients.put(clientId, networkingClient);
|
||||
logger.info("New client started successfully for {}:{}", host, port);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to initialize the client manager", e);
|
||||
throw e;
|
||||
logger.error(e); // TODO Better error handling
|
||||
return OptionalLong.empty();
|
||||
}
|
||||
return OptionalLong.of(clientId);
|
||||
}
|
||||
|
||||
long startClientRequest(String ip, int port) {
|
||||
long connectionId = SnowflakeGenerator.nextId();
|
||||
try {
|
||||
NetworkingClient client =
|
||||
new NetworkingClient(
|
||||
() -> new NetworkingGameClientHandler(connectionId),
|
||||
ip,
|
||||
port,
|
||||
connectionId);
|
||||
client.setConnectionId(connectionId);
|
||||
this.networkClients.put(connectionId, client);
|
||||
logger.info("New client started successfully for {}:{}", ip, port);
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
}
|
||||
return connectionId;
|
||||
@Override
|
||||
public boolean sendCommand(long id, String command) {
|
||||
logger.info("Sending command to client for {}:{}", id, command);
|
||||
if (command.isEmpty()) { return false; }
|
||||
|
||||
NetworkingClient client = this.networkClients.get(id);
|
||||
if (client == null) { return false; } // TODO: Create client not found exceptions.
|
||||
|
||||
String toSend = command.trim();
|
||||
|
||||
if (toSend.endsWith("\n")) { client.writeAndFlush(toSend); }
|
||||
else { client.writeAndFlush(toSend + "\n"); }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private long startClientRequest(String ip, int port, long clientId) {
|
||||
try { // With EventFlow
|
||||
NetworkingClient client =
|
||||
new NetworkingClient(
|
||||
() -> new NetworkingGameClientHandler(clientId), ip, port, clientId);
|
||||
client.setConnectionId(clientId);
|
||||
this.networkClients.replace(clientId, client);
|
||||
logger.info(
|
||||
"New client started successfully for {}:{}, replaced: {}", ip, port, clientId);
|
||||
} catch (Exception e) {
|
||||
logger.error(e);
|
||||
}
|
||||
logger.info("Client {} started", clientId);
|
||||
return clientId;
|
||||
@Override
|
||||
public boolean reconnect(long id) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
void handleStartClient(NetworkEvents.StartClient event) {
|
||||
long id = this.startClientRequest(event.ip(), event.port());
|
||||
new Thread(
|
||||
() ->
|
||||
new EventFlow()
|
||||
.addPostEvent(
|
||||
NetworkEvents.StartClientResponse.class,
|
||||
id,
|
||||
event.eventSnowflake())
|
||||
.asyncPostEvent())
|
||||
.start();
|
||||
@Override
|
||||
public boolean changeAddress(long id, String host, int port) {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
void handleCommand(
|
||||
NetworkEvents.SendCommand
|
||||
event) { // TODO: Move this to ServerConnection class, keep it internal.
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
String args = String.join(" ", event.args());
|
||||
sendCommand(client, args);
|
||||
}
|
||||
|
||||
void handleSendLogin(NetworkEvents.SendLogin event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, String.format("LOGIN %s", event.username()));
|
||||
}
|
||||
|
||||
private void handleSendLogout(NetworkEvents.SendLogout event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, "LOGOUT");
|
||||
}
|
||||
|
||||
private void handleSendGetPlayerlist(NetworkEvents.SendGetPlayerlist event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, "GET PLAYERLIST");
|
||||
}
|
||||
|
||||
private void handleSendGetGamelist(NetworkEvents.SendGetGamelist event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, "GET GAMELIST");
|
||||
}
|
||||
|
||||
private void handleSendSubscribe(NetworkEvents.SendSubscribe event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, String.format("SUBSCRIBE %s", event.gameType()));
|
||||
}
|
||||
|
||||
private void handleSendMove(NetworkEvents.SendMove event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, String.format("MOVE %d", event.moveNumber()));
|
||||
}
|
||||
|
||||
private void handleSendChallenge(NetworkEvents.SendChallenge event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(
|
||||
client,
|
||||
String.format("CHALLENGE %s %s", event.usernameToChallenge(), event.gameType()));
|
||||
}
|
||||
|
||||
private void handleSendAcceptChallenge(NetworkEvents.SendAcceptChallenge event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, String.format("CHALLENGE ACCEPT %d", event.challengeId()));
|
||||
}
|
||||
|
||||
private void handleSendForfeit(NetworkEvents.SendForfeit event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, "FORFEIT");
|
||||
}
|
||||
|
||||
private void handleSendMessage(NetworkEvents.SendMessage event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, String.format("MESSAGE %s", event.message()));
|
||||
}
|
||||
|
||||
private void handleSendHelp(NetworkEvents.SendHelp event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, "HELP");
|
||||
}
|
||||
|
||||
private void handleSendHelpForCommand(NetworkEvents.SendHelpForCommand event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
sendCommand(client, String.format("HELP %s", event.command()));
|
||||
}
|
||||
|
||||
private void sendCommand(NetworkingClient client, String command) {
|
||||
logger.info(
|
||||
"Preparing to send command: {} to server: {}:{}. clientId: {}",
|
||||
command.trim(),
|
||||
client.getHost(),
|
||||
client.getPort(),
|
||||
client.getId());
|
||||
client.writeAndFlushnl(command);
|
||||
}
|
||||
|
||||
private void handleChangeClientHost(NetworkEvents.ChangeClientHost event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
client.closeConnection();
|
||||
startClientRequest(event.ip(), event.port(), event.clientId());
|
||||
}
|
||||
|
||||
void handleCloseClient(NetworkEvents.CloseClient event) {
|
||||
NetworkingClient client = this.networkClients.get(event.clientId());
|
||||
client.closeConnection();
|
||||
this.networkClients.remove(event.clientId());
|
||||
logger.info("Client {} closed successfully.", event.clientId());
|
||||
}
|
||||
|
||||
void handleGetAllConnections(NetworkEvents.RequestsAllClients request) {
|
||||
List<NetworkingClient> a = new ArrayList<>(this.networkClients.values());
|
||||
request.future().complete(a);
|
||||
}
|
||||
|
||||
public void handleShutdownAll(NetworkEvents.ForceCloseAllClients request) {
|
||||
this.networkClients.values().forEach(NetworkingClient::closeConnection);
|
||||
this.networkClients.clear();
|
||||
logger.info("All servers shut down");
|
||||
@Override
|
||||
public boolean closeClient(long id) {
|
||||
return false; // TODO
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.toop.framework.networking;
|
||||
package org.toop.framework.networking.clients;
|
||||
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.*;
|
||||
@@ -9,27 +9,16 @@ import io.netty.handler.codec.LineBasedFrameDecoder;
|
||||
import io.netty.handler.codec.string.StringDecoder;
|
||||
import io.netty.handler.codec.string.StringEncoder;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import java.util.function.Supplier;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.networking.events.NetworkEvents;
|
||||
import org.toop.framework.networking.handlers.NetworkingGameClientHandler;
|
||||
import org.toop.framework.networking.interfaces.NetworkingClient;
|
||||
|
||||
public class NetworkingClient {
|
||||
private static final Logger logger = LogManager.getLogger(NetworkingClient.class);
|
||||
|
||||
private long connectionId;
|
||||
private String host;
|
||||
private int port;
|
||||
public class TournamentNetworkingClient implements NetworkingClient {
|
||||
private static final Logger logger = LogManager.getLogger(TournamentNetworkingClient.class);
|
||||
private Channel channel;
|
||||
private NetworkingGameClientHandler handler;
|
||||
|
||||
public NetworkingClient(
|
||||
Supplier<NetworkingGameClientHandler> handlerFactory,
|
||||
String host,
|
||||
int port,
|
||||
long connectionId) {
|
||||
this.connectionId = connectionId;
|
||||
public TournamentNetworkingClient(long clientId, String host, int port) {
|
||||
try {
|
||||
Bootstrap bootstrap = new Bootstrap();
|
||||
EventLoopGroup workerGroup = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
|
||||
@@ -40,7 +29,7 @@ public class NetworkingClient {
|
||||
new ChannelInitializer<SocketChannel>() {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) {
|
||||
handler = handlerFactory.get();
|
||||
NetworkingGameClientHandler handler = new NetworkingGameClientHandler(clientId);
|
||||
|
||||
ChannelPipeline pipeline = ch.pipeline();
|
||||
pipeline.addLast(new LineBasedFrameDecoder(1024)); // split at \n
|
||||
@@ -52,53 +41,28 @@ public class NetworkingClient {
|
||||
});
|
||||
ChannelFuture channelFuture = bootstrap.connect(host, port).sync();
|
||||
this.channel = channelFuture.channel();
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to create networking client instance", e);
|
||||
}
|
||||
}
|
||||
|
||||
public NetworkingGameClientHandler getHandler() {
|
||||
return this.handler;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return this.host;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
public void setConnectionId(long connectionId) {
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
||||
public boolean isChannelActive() {
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return this.channel != null && this.channel.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeAndFlush(String msg) {
|
||||
String literalMsg = msg.replace("\n", "\\n").replace("\r", "\\r");
|
||||
if (isChannelActive()) {
|
||||
if (isActive()) {
|
||||
this.channel.writeAndFlush(msg);
|
||||
logger.info(
|
||||
"Connection {} sent message: '{}' ", this.channel.remoteAddress(), literalMsg);
|
||||
logger.info("Connection {} sent message: '{}' ", this.channel.remoteAddress(), literalMsg);
|
||||
} else {
|
||||
logger.warn("Cannot send message: '{}', connection inactive. ", literalMsg);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeAndFlushnl(String msg) {
|
||||
if (isChannelActive()) {
|
||||
this.channel.writeAndFlush(msg + "\r\n");
|
||||
logger.info("Connection {} sent message: '{}'", this.channel.remoteAddress(), msg);
|
||||
} else {
|
||||
logger.warn("Cannot send message: '{}', connection inactive.", msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
if (this.channel != null && this.channel.isActive()) {
|
||||
this.channel
|
||||
@@ -109,11 +73,6 @@ public class NetworkingClient {
|
||||
logger.info(
|
||||
"Connection {} closed successfully",
|
||||
this.channel.remoteAddress());
|
||||
new EventFlow()
|
||||
.addPostEvent(
|
||||
new NetworkEvents.ClosedConnection(
|
||||
this.connectionId))
|
||||
.asyncPostEvent();
|
||||
} else {
|
||||
logger.error(
|
||||
"Error closing connection {}. Error: {}",
|
||||
@@ -123,8 +82,4 @@ public class NetworkingClient {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.connectionId;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.toop.framework.eventbus.events.ResponseToUniqueEvent;
|
||||
import org.toop.framework.eventbus.events.UniqueEvent;
|
||||
import org.toop.framework.eventbus.events.EventsBase;
|
||||
import org.toop.annotations.AutoResponseResult;
|
||||
import org.toop.framework.networking.NetworkingClient;
|
||||
import org.toop.framework.networking.interfaces.NetworkingClient;
|
||||
|
||||
/**
|
||||
* A collection of networking-related event records for use with the {@link
|
||||
@@ -106,11 +106,16 @@ public class NetworkEvents extends EventsBase {
|
||||
*
|
||||
* <p>Carries IP, port, and a unique event ID for correlation with responses.
|
||||
*
|
||||
* @param ip Server IP address.
|
||||
* @param networkingClientClass The type of networking client to create.
|
||||
* @param host Server IP address.
|
||||
* @param port Server port.
|
||||
* @param eventSnowflake Unique event identifier for correlation.
|
||||
*/
|
||||
public record StartClient(String ip, int port, long eventSnowflake) implements UniqueEvent {}
|
||||
public record StartClient<T extends NetworkingClient>(
|
||||
Class<T> networkingClientClass,
|
||||
String host,
|
||||
int port,
|
||||
long identifier) implements UniqueEvent {}
|
||||
|
||||
/**
|
||||
* Response confirming a client was started.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.toop.framework.networking;
|
||||
package org.toop.framework.networking.handlers;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
@@ -1,12 +0,0 @@
|
||||
//package org.toop.frontend.networking.handlers;
|
||||
//
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
//import org.apache.logging.log4j.LogManager;
|
||||
//import org.apache.logging.log4j.Logger;
|
||||
//import org.toop.frontend.networking.NetworkingGameClientHandler;
|
||||
//
|
||||
//public class NetworkingTicTacToeClientHandler extends NetworkingGameClientHandler {
|
||||
// static final Logger logger = LogManager.getLogger(NetworkingTicTacToeClientHandler.class);
|
||||
//
|
||||
//
|
||||
//}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.toop.framework.networking.interfaces;
|
||||
|
||||
public interface NetworkingClient {
|
||||
boolean isActive();
|
||||
void writeAndFlush(String msg);
|
||||
void closeConnection();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.toop.framework.networking.interfaces;
|
||||
|
||||
import java.util.OptionalLong;
|
||||
|
||||
public interface NetworkingClientManager {
|
||||
OptionalLong startClient(Class<? extends NetworkingClient> networkingClientClass, String host, int port);
|
||||
boolean sendCommand(long id, String command);
|
||||
boolean reconnect(long id);
|
||||
boolean changeAddress(long id, String host, int port);
|
||||
boolean closeClient(long id);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package org.toop.framework.networking.types;
|
||||
|
||||
public record ServerCommand(long clientId, String command) {}
|
||||
@@ -0,0 +1,3 @@
|
||||
package org.toop.framework.networking.types;
|
||||
|
||||
public record ServerMessage(String message) {}
|
||||
Reference in New Issue
Block a user