Module is.codion.common.rmi
Package is.codion.common.rmi.server
Class AbstractServer<T extends Remote,A extends ServerAdmin>
java.lang.Object
java.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
is.codion.common.rmi.server.AbstractServer<T,A>
- Type Parameters:
T
- the type of remote interface served by this serverA
- the type of the admin interface this server provides
- All Implemented Interfaces:
Server<T,
,A> Serializable
,Remote
- Direct Known Subclasses:
EntityServer
public abstract class AbstractServer<T extends Remote,A extends ServerAdmin>
extends UnicastRemoteObject
implements Server<T,A>
A default Server implementation.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static final class
Represents a remote client connection.Nested classes/interfaces inherited from interface is.codion.common.rmi.server.Server
Server.Locator
-
Field Summary
Fields inherited from class java.rmi.server.RemoteObject
ref
Fields inherited from interface is.codion.common.rmi.server.Server
CLIENT_HOST
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractServer
(ServerConfiguration configuration) Instantiates a new AbstractServer -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addAuthenticator
(Authenticator authenticator) Adds aAuthenticator
instance to this server.protected final void
addShutdownListener
(Runnable listener) protected final Collection<AuxiliaryServer>
protected final Collection<RemoteClient>
final T
connect
(ConnectionRequest connectionRequest) Establishes a connection to this Serverprotected abstract T
connect
(RemoteClient remoteClient) Establishes the actual client connection.final T
connection
(UUID clientId) final int
final Map<RemoteClient,
T> final boolean
final void
disconnect
(UUID clientId) Disconnects the connection identified by the given key.protected abstract void
disconnect
(T connection) Disconnects the given connection.protected final A
getAdmin()
final int
final int
protected final <T extends Throwable>
TlogShutdownAndReturn
(T exception) Logs the given exception and shuts down this serverprotected abstract void
maintainConnections
(Collection<AbstractServer.ClientConnection<T>> connections) Maintains the given connections, that is, disconnects inactive or invalid connections, if required.protected final Registry
registry()
final ServerInformation
protected final void
Sets the admin instance for this serverfinal void
setConnectionLimit
(int connectionLimit) final void
setMaintenanceInterval
(int maintenanceInterval) final void
shutdown()
Shuts down this server.protected static void
validateUserCredentials
(User userToCheck, User requiredUser) Validates the given user credentialsMethods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, 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 is.codion.common.rmi.server.Server
serverAdmin, serverLoad
-
Constructor Details
-
AbstractServer
Instantiates a new AbstractServer- Parameters:
configuration
- the configuration- Throws:
RemoteException
- in case of an exception
-
-
Method Details
-
connections
- Returns:
- a map containing the current connections
-
connection
- Parameters:
clientId
- the client id- Returns:
- the connection associated with the given client
- Throws:
IllegalArgumentException
- in case no such client is connected
-
connectionCount
public final int connectionCount()- 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.
-
getMaintenanceInterval
public final int getMaintenanceInterval()- Returns:
- the maintenance check interval in ms
-
setMaintenanceInterval
public final void setMaintenanceInterval(int maintenanceInterval) - Parameters:
maintenanceInterval
- the new maintenance interval in ms
-
serverInformation
- Specified by:
serverInformation
in interfaceServer<T extends Remote,
A extends ServerAdmin> - Returns:
- static information about this server
-
connectionsAvailable
public final boolean connectionsAvailable()- Specified by:
connectionsAvailable
in interfaceServer<T extends Remote,
A extends ServerAdmin> - Returns:
- true if there are connections available
-
connect
public final T connect(ConnectionRequest connectionRequest) throws RemoteException, ConnectionNotAvailableException, LoginException Description copied from interface:Server
Establishes a connection to this Server- Specified by:
connect
in interfaceServer<T extends Remote,
A extends ServerAdmin> - Parameters:
connectionRequest
- the information required for establishing a connection- Returns:
- a remote connection instance
- Throws:
RemoteException
- in case of a communication errorConnectionNotAvailableException
- in case the server isn't accepting more connectionsLoginException
- in case the login fails
-
disconnect
Description copied from interface:Server
Disconnects the connection identified by the given key.- Specified by:
disconnect
in interfaceServer<T extends Remote,
A extends ServerAdmin> - Parameters:
clientId
- the UUID identifying the client that should be disconnected
-
shutdown
public final void shutdown()Shuts down this server. -
addAuthenticator
Adds aAuthenticator
instance to this server. IfAuthenticator.clientType()
is empty, the authenticator is shared between all client types, otherwise it is only used for clients of the given type.- Parameters:
authenticator
- the authenticator to add- Throws:
IllegalStateException
- in case an authenticator with the same clientType has been added
-
setAdmin
Sets the admin instance for this server- Parameters:
admin
- the admin instance- Throws:
IllegalStateException
- in case an admin instance has already been set
-
getAdmin
- Returns:
- the admin instance associated with this server
- Throws:
IllegalStateException
- in case no admin instance has been set- See Also:
-
addShutdownListener
- Parameters:
listener
- a listener notified when this server is shutting down.
-
connect
Establishes the actual client connection.- Parameters:
remoteClient
- the remote client- Returns:
- a connection for the given client
- Throws:
RemoteException
- in case of an exceptionLoginException
- in case of an error during the login
-
disconnect
Disconnects the given connection.- Parameters:
connection
- the connection to disconnect- Throws:
RemoteException
- in case of an exception
-
maintainConnections
protected abstract void maintainConnections(Collection<AbstractServer.ClientConnection<T>> connections) throws RemoteException Maintains the given connections, that is, disconnects inactive or invalid connections, if required.- Parameters:
connections
- all current connections- Throws:
RemoteException
- in case of an exception
-
clients
- Parameters:
clientType
- the client type- Returns:
- all clients of the given type
-
registry
- Returns:
- the Registry instance
- Throws:
RemoteException
- in case of an exception
-
logShutdownAndReturn
Logs the given exception and shuts down this server- Type Parameters:
T
- the exception type- Parameters:
exception
- the exception- Returns:
- the exception
-
auxiliaryServers
- Returns:
- an unmodifiable view of the auxialiary servers running along side this server
-
validateUserCredentials
protected static void validateUserCredentials(User userToCheck, User requiredUser) throws ServerAuthenticationException Validates the given user credentials- Parameters:
userToCheck
- the credentials to checkrequiredUser
- the required credentials- Throws:
ServerAuthenticationException
- in case either User instance is null or if the username or password do not match
-