Commit 32cb33ce authored by Bogdan's avatar Bogdan

Javadoc for RMI classes.

parent c2163620
......@@ -4,6 +4,8 @@ import java.io.Serializable;
/**
* Created by bogdanbear on 03/01/2016.
* Class which contains all the meta-parameters of a game,
* like port, id, number of free places etc.
*/
public class Lounge implements Serializable {
public static final int MAX_PLAYERS=3;
......@@ -31,8 +33,8 @@ public class Lounge implements Serializable {
}
/**
*
* @return whether the operation has been executed or not
* add a new player to the lounge by increasing player counter
* @return a boolean representing whether the operation has been executed or not
*/
public boolean addPlayer()
{
......@@ -41,6 +43,7 @@ public class Lounge implements Serializable {
else return false;
return true;
}
public boolean isFull()
{
return (occupiedSpots==MAX_PLAYERS);
......
......@@ -12,6 +12,7 @@ import java.util.logging.Logger;
/**
* Created by bogdanbear on 04/01/2016.
* This class contains methods which perform the actual RMI calls to the server
*/
public class RPCClient {
private static RegisterInterface registrar;
......@@ -19,6 +20,12 @@ public class RPCClient {
private static int port=1099;
private static Logger LOGGER = Logging.getInstance().getLogger();
//private static ArrayList<Lounge> LoungeList=new ArrayList<Lounge>();
/**
* Create a lounge on the remote server
* @param loungeName
* @return a Lounge object which contains all the parameters that define a lounge
*/
public static Lounge createLounge(String loungeName)
{
long id=0;
......@@ -34,6 +41,9 @@ public class RPCClient {
return null;
}
/**
* this method has been used for testing to check that connections are made correctly
*/
public static void connect()
{
LOGGER.info("RPCClient: Start test");
......@@ -46,6 +56,13 @@ public class RPCClient {
LOGGER.warning("RPCClient: Client exception: " + e);
}
}
/**
* Method on the RMI client side for joining a lounge.
* @param id - the id of the lounge we wish to join
* @return a boolean representing whether the operation has been accepted by the server and we are allowed to join
* the game or not
*/
public static boolean joinLounge(long id)
{
try {
......@@ -58,6 +75,11 @@ public class RPCClient {
}
return false;
}
/**
* method used to grab the lounge list from the server, will be used by the gui to display available rooms
* @return an arraylist of all the lounges which are waiting for new players
*/
public static ArrayList<Lounge> getLoungeList()
{
try {
......
......@@ -7,6 +7,7 @@ import java.util.ArrayList;
/**
* Created by bogdanbear on 02/01/2016.
* interface which provides the definitions of the methods which may be called by an rpc client
*/
public interface RegisterInterface extends Remote{
......
......@@ -10,6 +10,8 @@ import java.util.logging.Logger;
/**
* Created by bogdanbear on 02/01/2016.
* Main class for the RPC server which ensure lounge management
* Creates a registry at port 1099 and exports method declarations, definitions are provided by the Registrar class
*/
public class RPCServer {
public static int scale=25;
......
......@@ -14,6 +14,8 @@ import java.util.logging.Logger;
/**
* Created by bogdanbear on 02/01/2016.
* This class provides implementations for the methods defined in the RegisterInterfaces - this code will
* be run by the client on the server
* note on sunchronized methods - does not prevent simultaneous remote calls for two JVM (two clients)
but it works for one. (the pair client-server)
*/
......@@ -51,13 +53,22 @@ public class Registrar extends UnicastRemoteObject implements RegisterInterface
return gen;
}
/**
* This is a method used for testing purposes
* @throws RemoteException
*/
@Override
public synchronized void test() throws RemoteException {
Logging.getInstance().getLogger().info("A client has invoked the test method");
//test signals that there is a client connected, therefore we will create a robot in case the server is empty
}
/**
* called by a remote client who wants to create a lounge on the server
* @param name is the name of the lounge
* @return returns an object which contains all the parameters of the lounge
* @throws RemoteException
*/
@Override
public synchronized Lounge createLounge(String name) throws RemoteException {
LOGGER.info("RPCServer: Somebody called createLounge method");
......@@ -77,6 +88,12 @@ public class Registrar extends UnicastRemoteObject implements RegisterInterface
return lounge;
}
/**
* Method called by a client who wants to retrieve the list of all lounges
* @return an arraylist containing all the lounges for which the game has not started yet
* @throws RemoteException
*/
@Override
public synchronized ArrayList<Lounge> getWaiting() throws RemoteException {
ArrayList<Lounge> temp = new ArrayList<Lounge>();
......@@ -87,7 +104,12 @@ public class Registrar extends UnicastRemoteObject implements RegisterInterface
return temp;
}
/**
* method through which a client joins a lounge, simple implementation
* @param id the id of the lounge we wish to join
* @return a boolean value representing whether joining the lounge was successull or not
* @throws RemoteException
*/
@Override
public synchronized boolean joinLounge(long id) throws RemoteException {
LOGGER.info("someone is joining game "+id);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment