org.jminor.common.server
Class AbstractRemoteServer<T extends Remote>

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by org.jminor.common.server.AbstractRemoteServer<T>
All Implemented Interfaces:
Serializable, Remote, RemoteServer<T>
Direct Known Subclasses:
RemoteLoadTestServer

public abstract class AbstractRemoteServer<T extends Remote>
extends UnicastRemoteObject
implements RemoteServer<T>

A default RemoteServer implementation.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface org.jminor.common.server.RemoteServer
SERVER_ADMIN_PREFIX
 
Constructor Summary
AbstractRemoteServer(int serverPort, String serverName)
          Instantiates a new AbstractRemoteServer
AbstractRemoteServer(int serverPort, String serverName, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory)
          Instantiates a new AbstractRemoteServer
 
Method Summary
 T connect(ClientInfo clientInfo)
          Establishes a connection to this RemoteServer
 T connect(User user, UUID clientID, String clientTypeID)
          Establishes a connection to this RemoteServer
 boolean connectionsAvailable()
          
 boolean containsConnection(ClientInfo client)
           
 void disconnect(UUID clientID)
          Disconnects the connection identified by the given key.
protected abstract  T doConnect(ClientInfo clientInfo)
          Establishes the actual client connection.
protected abstract  void doDisconnect(T connection)
          Disconnects the given connection.
 T getConnection(ClientInfo client)
           
 int getConnectionCount()
           
 int getConnectionLimit()
           
 Map<ClientInfo,T> getConnections()
           
 String getServerName()
          
 int getServerPort()
          
protected  void handleShutdown()
          Called after shutdown has finished
 boolean isShuttingDown()
           
 void setConnectionLimit(int connectionLimit)
           
 void setLoginProxy(LoginProxy loginProxy)
           
 void shutdown()
          Shuts down this server.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jminor.common.server.RemoteServer
getServerLoad
 

Constructor Detail

AbstractRemoteServer

public AbstractRemoteServer(int serverPort,
                            String serverName)
                     throws RemoteException
Instantiates a new AbstractRemoteServer

Parameters:
serverPort - the port on which the server should be exported
serverName - the name used when exporting this server
Throws:
RemoteException - in case of an exception

AbstractRemoteServer

public AbstractRemoteServer(int serverPort,
                            String serverName,
                            RMIClientSocketFactory clientSocketFactory,
                            RMIServerSocketFactory serverSocketFactory)
                     throws RemoteException
Instantiates a new AbstractRemoteServer

Parameters:
serverPort - the port on which the server should be exported
serverName - the name used when exporting this server
clientSocketFactory - the client socket factory to use
serverSocketFactory - the server socket factory to use
Throws:
RemoteException - in case of an exception
Method Detail

getConnections

public final Map<ClientInfo,T> getConnections()
Returns:
a map containing the current connections

containsConnection

public final boolean containsConnection(ClientInfo client)
Parameters:
client - the client info
Returns:
true if such a client is connected

getConnection

public final T getConnection(ClientInfo client)
Parameters:
client - the client info
Returns:
the connection associated with the given client, null if none exists

getConnectionCount

public final int getConnectionCount()
Returns:
the current number of connections

getConnectionLimit

public final int getConnectionLimit()
Returns:
the maximum number of concurrent connections accepted by this server, a negative number means no limit while 0 means the server is closed.

setConnectionLimit

public final void setConnectionLimit(int connectionLimit)
Parameters:
connectionLimit - the maximum number of concurrent connections accepted by this server, a negative number means no limit while 0 means the server is closed.

connectionsAvailable

public final boolean connectionsAvailable()
                                   throws RemoteException

Specified by:
connectionsAvailable in interface RemoteServer<T extends Remote>
Returns:
true if there are connections available
Throws:
RemoteException - in case of an exception

connect

public final T connect(User user,
                       UUID clientID,
                       String clientTypeID)
                               throws RemoteException,
                                      ServerException.ServerFullException,
                                      ServerException.LoginException
Establishes a connection to this RemoteServer

Specified by:
connect in interface RemoteServer<T extends Remote>
Parameters:
user - the user
clientID - a UUID identifying the client
clientTypeID - a String identifying the client
Returns:
a remote connection instance
Throws:
RemoteException - in case of a RemoteException
ServerException.ServerFullException - in case the server isn't accepting more connections
ServerException.LoginException - in case the login fails

connect

public final T connect(ClientInfo clientInfo)
                               throws RemoteException,
                                      ServerException.ServerFullException,
                                      ServerException.LoginException
Establishes a connection to this RemoteServer

Specified by:
connect in interface RemoteServer<T extends Remote>
Parameters:
clientInfo - the client info
Returns:
a remote connection instance
Throws:
RemoteException - in case of a RemoteException
ServerException.ServerFullException - in case the server isn't accepting more connections
ServerException.LoginException - in case the login fails

disconnect

public final void disconnect(UUID clientID)
                      throws RemoteException
Disconnects the connection identified by the given key.

Specified by:
disconnect in interface RemoteServer<T extends Remote>
Parameters:
clientID - the UUID identifying the client that should be disconnected
Throws:
RemoteException - in case of a communication error

getServerName

public final String getServerName()

Specified by:
getServerName in interface RemoteServer<T extends Remote>
Returns:
the server name

getServerPort

public final int getServerPort()

Specified by:
getServerPort in interface RemoteServer<T extends Remote>
Returns:
the server port

setLoginProxy

public final void setLoginProxy(LoginProxy loginProxy)
Parameters:
loginProxy - the login proxy

isShuttingDown

public final boolean isShuttingDown()
Returns:
true if this server is in the process of shutting down

shutdown

public final void shutdown()
                    throws RemoteException
Shuts down this server.

Throws:
RemoteException - in case of an exception

handleShutdown

protected void handleShutdown()
                       throws RemoteException
Called after shutdown has finished

Throws:
RemoteException - in case of an exception

doConnect

protected abstract T doConnect(ClientInfo clientInfo)
                                       throws RemoteException
Establishes the actual client connection.

Parameters:
clientInfo - the client info
Returns:
a connection servicing the given client
Throws:
RemoteException - in case of an exception

doDisconnect

protected abstract void doDisconnect(T connection)
                              throws RemoteException
Disconnects the given connection.

Parameters:
connection - the connection to disconnect
Throws:
RemoteException - in case of an exception