-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #247 from mattteochen/formatting
Applied automated formatting with checkstyle's Google rules
- Loading branch information
Showing
133 changed files
with
6,202 additions
and
6,292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ | |
import it.polimi.is23am10.utils.config.exceptions.InvalidPortNumberException; | ||
import it.polimi.is23am10.utils.exceptions.InvalidArgumentException; | ||
import it.polimi.is23am10.utils.exceptions.MissingParameterException; | ||
|
||
import java.io.IOException; | ||
import java.net.ConnectException; | ||
import java.net.ServerSocket; | ||
|
@@ -32,13 +31,12 @@ | |
import java.rmi.registry.Registry; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
/** | ||
* The entrypoint for the app. Parses args and launches | ||
* either client or server with desired options. | ||
* The entrypoint for the app. Parses args and launches either client or server with desired | ||
* options. | ||
* | ||
* @author Alessandro Amandonico ([email protected]) | ||
* @author Francesco Buccoliero ([email protected]) | ||
|
@@ -47,15 +45,12 @@ | |
*/ | ||
public class App { | ||
|
||
/** | ||
* Logger instance. | ||
* | ||
*/ | ||
protected final static Logger logger = LogManager.getLogger(App.class); | ||
/** Logger instance. */ | ||
protected static final Logger logger = LogManager.getLogger(App.class); | ||
|
||
/** | ||
* The main function. Entrypoint for both server and client. | ||
* | ||
* | ||
* @param args CLI arguments to parse. | ||
*/ | ||
public static void main(String[] args) { | ||
|
@@ -64,28 +59,41 @@ public static void main(String[] args) { | |
AppConfigContext ctx = new AppConfigContext(); | ||
if (ctx.getIsServer()) { | ||
// SERVER MODE | ||
Server server = new Server(new ServerSocket(ctx.getServerSocketPort()), | ||
Executors.newFixedThreadPool(ctx.getMaxConnections()), new ServerControllerAction(), | ||
LocateRegistry.createRegistry(ctx.getServerRmiPort())); | ||
Server server = | ||
new Server( | ||
new ServerSocket(ctx.getServerSocketPort()), | ||
Executors.newFixedThreadPool(ctx.getMaxConnections()), | ||
new ServerControllerAction(), | ||
LocateRegistry.createRegistry(ctx.getServerRmiPort())); | ||
|
||
server.start(ctx); | ||
} else { | ||
// CLIENT MODE | ||
UserInterface userInterface = ctx.getShowGUI() ? new GraphicUserInterface() : new CommandLineInterface(ctx.getShowDebug()); | ||
UserInterface userInterface = | ||
ctx.getShowGUI() | ||
? new GraphicUserInterface() | ||
: new CommandLineInterface(ctx.getShowDebug()); | ||
Client client = null; | ||
if (ctx.getUseRMI()) { | ||
try { | ||
Registry registry = LocateRegistry.getRegistry(ctx.getServerAddress(), ctx.getServerRmiPort()); | ||
PlayerConnectorRmi playerConnector = new PlayerConnectorRmi(new LinkedBlockingQueue<>(), client); | ||
IServerControllerAction serverControllerActionServerRef = (IServerControllerAction) registry | ||
.lookup(IServerControllerAction.class.getName()); | ||
client = new RMIClient(playerConnector, userInterface, serverControllerActionServerRef, registry); | ||
Registry registry = | ||
LocateRegistry.getRegistry(ctx.getServerAddress(), ctx.getServerRmiPort()); | ||
PlayerConnectorRmi playerConnector = | ||
new PlayerConnectorRmi(new LinkedBlockingQueue<>(), client); | ||
IServerControllerAction serverControllerActionServerRef = | ||
(IServerControllerAction) registry.lookup(IServerControllerAction.class.getName()); | ||
client = | ||
new RMIClient( | ||
playerConnector, userInterface, serverControllerActionServerRef, registry); | ||
playerConnector.setClient(client); | ||
} catch (NotBoundException e) { | ||
userInterface.displayError(new ErrorMessage("Server not found. Shutting down client...", ErrorSeverity.CRITICAL)); | ||
userInterface.displayError( | ||
new ErrorMessage( | ||
"Server not found. Shutting down client...", ErrorSeverity.CRITICAL)); | ||
return; | ||
} catch(NullBlockingQueueException e) { | ||
userInterface.displayError(new ErrorMessage("Client module error. Shutting down", ErrorSeverity.CRITICAL)); | ||
} catch (NullBlockingQueueException e) { | ||
userInterface.displayError( | ||
new ErrorMessage("Client module error. Shutting down", ErrorSeverity.CRITICAL)); | ||
return; | ||
} catch (IOException e) { | ||
logger.error("Cannot connect to server. Verify address and retry."); | ||
|
@@ -94,19 +102,26 @@ public static void main(String[] args) { | |
} else { | ||
try { | ||
Socket socket = new Socket(ctx.getServerAddress(), ctx.getServerSocketPort()); | ||
PlayerConnectorSocket playerConnector = new PlayerConnectorSocket(socket, new LinkedBlockingQueue<>()); | ||
PlayerConnectorSocket playerConnector = | ||
new PlayerConnectorSocket(socket, new LinkedBlockingQueue<>()); | ||
client = new SocketClient(playerConnector, userInterface); | ||
} catch (UnknownHostException e) { | ||
userInterface.displayError(new ErrorMessage("Server not found. Shutting down client...", ErrorSeverity.CRITICAL)); | ||
userInterface.displayError( | ||
new ErrorMessage( | ||
"Server not found. Shutting down client...", ErrorSeverity.CRITICAL)); | ||
return; | ||
} catch (NullBlockingQueueException | NullSocketConnectorException e) { | ||
userInterface.displayError(new ErrorMessage("Client module error. Shutting down", ErrorSeverity.CRITICAL)); | ||
userInterface.displayError( | ||
new ErrorMessage("Client module error. Shutting down", ErrorSeverity.CRITICAL)); | ||
return; | ||
} | ||
} | ||
client.run(); | ||
} | ||
} catch (NumberFormatException | InvalidArgumentException | MissingParameterException | InvalidPortNumberException | ||
} catch (NumberFormatException | ||
| InvalidArgumentException | ||
| MissingParameterException | ||
| InvalidPortNumberException | ||
| InvalidMaxConnectionsNumberException e) { | ||
logger.error("Cannot parse CLI arguments.", e); | ||
} catch (ConnectException e) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
package it.polimi.is23am10.client; | ||
|
||
import it.polimi.is23am10.server.network.messages.AbstractMessage; | ||
import java.rmi.Remote; | ||
import java.rmi.RemoteException; | ||
|
||
import it.polimi.is23am10.server.network.messages.AbstractMessage; | ||
|
||
/** | ||
* The <code>IClient</code> interface represents the remote interface for clients in a Java RMI application. | ||
* It defines methods that the server can call on the client. | ||
* The <code>IClient</code> interface represents the remote interface for clients in a Java RMI | ||
* application. It defines methods that the server can call on the client. | ||
*/ | ||
public interface IClient extends Remote { | ||
/** | ||
* Displays a server message on the client. | ||
* | ||
* @param msg The server message to be displayed on the client. | ||
* @throws RemoteException If a communication-related exception occurs during the remote method invocation. | ||
* @throws RemoteException If a communication-related exception occurs during the remote method | ||
* invocation. | ||
*/ | ||
void showServerMessage(AbstractMessage msg) throws RemoteException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.