mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-19 00:06:16 +01:00
server doc
This commit is contained in:
parent
957bf8ffcc
commit
95b9da9377
@ -70,7 +70,7 @@ import pp.monopoly.model.fields.TestStreckeField;
|
|||||||
import pp.monopoly.model.fields.WacheField;
|
import pp.monopoly.model.fields.WacheField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
|
* MonopolyServer implementing the visitor pattern as MessageReceiver for ClientMessages
|
||||||
*/
|
*/
|
||||||
public class MonopolyServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
|
public class MonopolyServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
|
||||||
private static final Logger LOGGER = System.getLogger(MonopolyServer.class.getName());
|
private static final Logger LOGGER = System.getLogger(MonopolyServer.class.getName());
|
||||||
@ -109,12 +109,18 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
logic = new ServerGameLogic(this, config);
|
logic = new ServerGameLogic(this, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run is executed on StartUp
|
||||||
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
startServer();
|
startServer();
|
||||||
while (true)
|
while (true)
|
||||||
processNextMessage();
|
processNextMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the Server
|
||||||
|
*/
|
||||||
private void startServer() {
|
private void startServer() {
|
||||||
try {
|
try {
|
||||||
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
|
||||||
@ -130,6 +136,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processesthe next incoming message
|
||||||
|
*/
|
||||||
private void processNextMessage() {
|
private void processNextMessage() {
|
||||||
try {
|
try {
|
||||||
pendingMessages.take().process(logic);
|
pendingMessages.take().process(logic);
|
||||||
@ -140,6 +149,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize alls Messages and Classes that need to be sent
|
||||||
|
*/
|
||||||
private void initializeSerializables() {
|
private void initializeSerializables() {
|
||||||
Serializer.registerClass(IntPoint.class);
|
Serializer.registerClass(IntPoint.class);
|
||||||
Serializer.registerClass(BuyPropertyResponse.class);
|
Serializer.registerClass(BuyPropertyResponse.class);
|
||||||
@ -182,6 +194,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
Serializer.registerClass(GameOver.class);
|
Serializer.registerClass(GameOver.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register all message listeners
|
||||||
|
*/
|
||||||
private void registerListeners() {
|
private void registerListeners() {
|
||||||
myServer.addMessageListener(this, BuyPropertyResponse.class);
|
myServer.addMessageListener(this, BuyPropertyResponse.class);
|
||||||
myServer.addMessageListener(this, EndTurn.class);
|
myServer.addMessageListener(this, EndTurn.class);
|
||||||
@ -220,6 +235,10 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exits the server
|
||||||
|
* @param exitValue the exit code to throw
|
||||||
|
*/
|
||||||
private void exit(int exitValue) { //NON-NLS
|
private void exit(int exitValue) { //NON-NLS
|
||||||
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
LOGGER.log(Level.INFO, "close request"); //NON-NLS
|
||||||
if (myServer != null)
|
if (myServer != null)
|
||||||
|
@ -10,6 +10,9 @@ package pp.monopoly.server;
|
|||||||
import pp.monopoly.message.client.ClientInterpreter;
|
import pp.monopoly.message.client.ClientInterpreter;
|
||||||
import pp.monopoly.message.client.ClientMessage;
|
import pp.monopoly.message.client.ClientMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Record to process incoming Client Messages
|
||||||
|
*/
|
||||||
record ReceivedMessage(ClientMessage message, int from) {
|
record ReceivedMessage(ClientMessage message, int from) {
|
||||||
void process(ClientInterpreter interpreter) {
|
void process(ClientInterpreter interpreter) {
|
||||||
message.accept(interpreter, from);
|
message.accept(interpreter, from);
|
||||||
|
Loading…
Reference in New Issue
Block a user