T
- the type of remote interface served by this serverA
- the type of the admin interface this server providespublic abstract class AbstractServer<T extends java.rmi.Remote,A extends java.rmi.Remote> extends java.rmi.server.UnicastRemoteObject implements Server<T,A>
Server.AuxiliaryServer, Server.ServerInfo
AUXILIARY_SERVER_CLASS_NAMES, CLIENT_HOST_KEY, DEFAULT_SERVER_CONNECTION_TIMEOUT, JAVAX_NET_KEYSTORE, JAVAX_NET_KEYSTORE_PASSWORD, JAVAX_NET_TRUSTSTORE, JAVAX_NET_TRUSTSTORE_PASSWORD, KEYSTORE, KEYSTORE_PASSWORD, LOCALHOST, REGISTRY_PORT, RMI_SERVER_HOSTNAME, SERVER_ADMIN_PORT, SERVER_ADMIN_USER, SERVER_CONNECTION_SSL_ENABLED, SERVER_CONNECTION_TIMEOUT, SERVER_HOST_NAME, SERVER_NAME_PREFIX, SERVER_PORT, TRUSTSTORE, TRUSTSTORE_PASSWORD
Constructor and Description |
---|
AbstractServer(int serverPort,
java.lang.String serverName)
Instantiates a new AbstractServer
|
AbstractServer(int serverPort,
java.lang.String serverName,
java.rmi.server.RMIClientSocketFactory clientSocketFactory,
java.rmi.server.RMIServerSocketFactory serverSocketFactory)
Instantiates a new AbstractServer
|
Modifier and Type | Method and Description |
---|---|
void |
addSharedLoginProxy(LoginProxy loginProxy)
Adds a shared LoginProxy, used for all connection requests.
|
T |
connect(ConnectionRequest connectionRequest)
Establishes a connection to this Server
|
boolean |
connectionsAvailable() |
void |
disconnect(java.util.UUID clientId)
Disconnects the connection identified by the given key.
|
protected abstract T |
doConnect(RemoteClient remoteClient)
Establishes the actual client connection.
|
protected abstract void |
doDisconnect(T connection)
Disconnects the given connection.
|
T |
getConnection(java.util.UUID clientId) |
int |
getConnectionCount() |
int |
getConnectionLimit() |
java.util.Map<RemoteClient,T> |
getConnections() |
Server.ServerInfo |
getServerInfo() |
protected void |
handleShutdown()
Called after shutdown has finished, for subclasses
|
boolean |
isShuttingDown() |
void |
setConnectionLimit(int connectionLimit) |
void |
setConnectionValidator(java.lang.String clientTypeId,
ConnectionValidator connectionValidator)
Sets the
ConnectionValidator for the given client type id, if connectionValidator is null
the current connection validator (if any) is removed. |
void |
setLoginProxy(java.lang.String clientTypeId,
LoginProxy loginProxy)
Sets the LoginProxy for the given client type id, if
loginProxy is null
the current login proxy (if any) is closed and removed. |
void |
shutdown()
Shuts down this server.
|
protected static void |
validateUserCredentials(User userToCheck,
User requiredUser)
Validates the given user credentials
|
clone, exportObject, exportObject, exportObject, unexportObject
equals, getRef, hashCode, toString, toStub
finalize, getClass, notify, notifyAll, wait, wait, wait
getServerAdmin, getServerLoad
public AbstractServer(int serverPort, java.lang.String serverName) throws java.rmi.RemoteException
serverPort
- the port on which the server should be exportedserverName
- the name used when exporting this serverjava.rmi.RemoteException
- in case of an exceptionpublic AbstractServer(int serverPort, java.lang.String serverName, java.rmi.server.RMIClientSocketFactory clientSocketFactory, java.rmi.server.RMIServerSocketFactory serverSocketFactory) throws java.rmi.RemoteException
serverPort
- the port on which the server should be exportedserverName
- the name used when exporting this serverclientSocketFactory
- the client socket factory to use, null for defaultserverSocketFactory
- the server socket factory to use, null for defaultjava.rmi.RemoteException
- in case of an exceptionpublic final java.util.Map<RemoteClient,T> getConnections()
public final T getConnection(java.util.UUID clientId)
clientId
- the client idpublic final int getConnectionCount()
public final int getConnectionLimit()
public final void setConnectionLimit(int connectionLimit)
connectionLimit
- the maximum number of concurrent connections accepted by this server,
a negative number means no limit while 0 means the server is closed.public final Server.ServerInfo getServerInfo()
getServerInfo
in interface Server<T extends java.rmi.Remote,A extends java.rmi.Remote>
public final boolean connectionsAvailable()
connectionsAvailable
in interface Server<T extends java.rmi.Remote,A extends java.rmi.Remote>
public final T connect(ConnectionRequest connectionRequest) throws java.rmi.RemoteException, ServerException.ServerFullException, ServerException.LoginException, ServerException.ConnectionValidationException
connect
in interface Server<T extends java.rmi.Remote,A extends java.rmi.Remote>
connectionRequest
- the information required for establishing a connectionjava.rmi.RemoteException
- in case of a communitation errorServerException.ServerFullException
- in case the server isn't accepting more connectionsServerException.LoginException
- in case the login failsServerException.ConnectionValidationException
- in case connection validation failspublic final void disconnect(java.util.UUID clientId) throws java.rmi.RemoteException
disconnect
in interface Server<T extends java.rmi.Remote,A extends java.rmi.Remote>
clientId
- the UUID identifying the client that should be disconnectedjava.rmi.RemoteException
- in case of a communication errorpublic final void addSharedLoginProxy(LoginProxy loginProxy)
loginProxy
- the login proxyjava.lang.IllegalStateException
- in case the given login proxy has already been addedpublic final void setLoginProxy(java.lang.String clientTypeId, LoginProxy loginProxy)
loginProxy
is null
the current login proxy (if any) is closed and removed.clientTypeId
- the client type ID with which to associate the given login proxyloginProxy
- the login proxyjava.lang.IllegalStateException
- in case the login proxy has already been set for the given client typepublic final void setConnectionValidator(java.lang.String clientTypeId, ConnectionValidator connectionValidator)
ConnectionValidator
for the given client type id, if connectionValidator
is null
the current connection validator (if any) is removed.clientTypeId
- the client type ID with which to associate the given connection validatorconnectionValidator
- the connection validatorjava.lang.IllegalStateException
- in case the connection validator has already been set for the given client typepublic final boolean isShuttingDown()
public final void shutdown() throws java.rmi.RemoteException
java.rmi.RemoteException
- in case of an exceptionprotected void handleShutdown() throws java.rmi.RemoteException
java.rmi.RemoteException
- in case of an exceptionprotected abstract T doConnect(RemoteClient remoteClient) throws java.rmi.RemoteException, ServerException.LoginException, ServerException.ServerFullException
remoteClient
- the client connection infojava.rmi.RemoteException
- in case of an exceptionServerException.LoginException
- in case of an error during the loginServerException.ServerFullException
- in case the server is not accepting new connectionsprotected abstract void doDisconnect(T connection) throws java.rmi.RemoteException
connection
- the connection to disconnectjava.rmi.RemoteException
- in case of an exceptionprotected static final void validateUserCredentials(User userToCheck, User requiredUser) throws ServerException.AuthenticationException
userToCheck
- the credentials to checkrequiredUser
- the required credentialsServerException.AuthenticationException
- in case either User instance is null or if the username or password does not match