Class AbstractServer<T extends Remote,​A extends ServerAdmin>

    • Method Detail

      • connections

        public final Map<RemoteClient,​T> connections()
        Returns:
        a map containing the current connections
      • connection

        public final T connection​(UUID clientId)
        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
      • disconnect

        public final void disconnect​(UUID clientId)
                              throws RemoteException
        Description copied from interface: Server
        Disconnects the connection identified by the given key.
        Specified by:
        disconnect in interface Server<T extends Remote,​A extends ServerAdmin>
        Parameters:
        clientId - the UUID identifying the client that should be disconnected
        Throws:
        RemoteException - in case of a communication error
      • shutdown

        public final void shutdown()
        Shuts down this server.
      • addLoginProxy

        public final void addLoginProxy​(LoginProxy loginProxy)
      • setAdmin

        protected final void setAdmin​(A admin)
      • getAdmin

        protected final A getAdmin()
      • addShutdownListener

        protected final void addShutdownListener​(EventListener listener)
        Parameters:
        listener - a listener notified when this server is shutting down.
      • connect

        protected abstract T connect​(RemoteClient remoteClient)
                              throws RemoteException,
                                     LoginException
        Establishes the actual client connection.
        Parameters:
        remoteClient - the client connection info
        Returns:
        a connection servicing the given client
        Throws:
        RemoteException - in case of an exception
        LoginException - in case of an error during the login
      • disconnect

        protected abstract void disconnect​(T connection)
                                    throws RemoteException
        Disconnects the given connection.
        Parameters:
        connection - the connection to disconnect
        Throws:
        RemoteException - in case of an exception
      • clients

        protected final Collection<RemoteClient> clients​(String clientTypeId)
        Parameters:
        clientTypeId - the client type id
        Returns:
        all clients of the given type
      • logShutdownAndReturn

        protected final <T extends Throwable> T logShutdownAndReturn​(T exception)
      • validateUserCredentials

        protected static final void validateUserCredentials​(User userToCheck,
                                                            User requiredUser)
                                                     throws ServerAuthenticationException
        Validates the given user credentials
        Parameters:
        userToCheck - the credentials to check
        requiredUser - the required credentials
        Throws:
        ServerAuthenticationException - in case either User instance is null or if the username or password does not match