Add: shared actionQueue between ServerLauncher, ServerRMI and ServerTCP
This commit is contained in:
@@ -11,6 +11,7 @@ import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
@@ -22,12 +23,14 @@ public class RMIServer implements IGameServer {
|
||||
private Registry registry;
|
||||
private int nPort;
|
||||
private final Map<String, IClientCallback> clients = new ConcurrentHashMap<>();
|
||||
BlockingQueue<NetworkEvent> actionQueue;
|
||||
|
||||
|
||||
// Costruttore
|
||||
public RMIServer(GameController controller, int nPort) throws RemoteException {
|
||||
public RMIServer(GameController controller, int nPort, BlockingQueue<NetworkEvent> actionQueue) throws RemoteException {
|
||||
this.controller = controller;
|
||||
this.nPort = nPort;
|
||||
this.actionQueue = actionQueue;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,13 +52,7 @@ public class RMIServer implements IGameServer {
|
||||
}
|
||||
@Override
|
||||
public boolean doEvent(NetworkEvent event) throws RemoteException {
|
||||
boolean result = event.apply(controller);
|
||||
if (!result) {
|
||||
notifyError(event.getUsername(),"Mossa non valida");
|
||||
} else {
|
||||
notifyAll(event);
|
||||
}
|
||||
return result;
|
||||
return actionQueue.offer(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,12 +7,14 @@ import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
public class TCPServer {
|
||||
int port = -1;
|
||||
int ConnectedPlayers = 0;
|
||||
ServerSocket serverTCP = null;
|
||||
GameController gameController;
|
||||
BlockingQueue<NetworkEvent> actionQueue;
|
||||
|
||||
private List<ClientHandler> clientHandlers;
|
||||
|
||||
@@ -80,9 +82,10 @@ public class TCPServer {
|
||||
}
|
||||
}
|
||||
|
||||
public TCPServer(GameController gameController, int port){
|
||||
public TCPServer(GameController gameController, int port, BlockingQueue<NetworkEvent> actionQueue){
|
||||
this.port = port;
|
||||
this.gameController = gameController;
|
||||
this.actionQueue = actionQueue;
|
||||
}
|
||||
|
||||
public void broadcastUpdate(NetworkEvent event){
|
||||
|
||||
Reference in New Issue
Block a user