Class ClientManager

  • All Implemented Interfaces:
    java.lang.Runnable

    public class ClientManager
    extends java.lang.Thread
    Administrates the clients an runs in its own Thread. It accepts them from the serversocket and starts a CommunicationHandler in a separate thread for each connecting client.
    See Also:
    CommunicationHandler
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      ClientManager​(Server server)
      Initiates a ClientManager object
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean close()
      Closes all client connection and the serversocket itself
      CommunicationHandler getCommunicationHandlerByIP​(java.lang.String clientAddress)
      Searches for a CommunicationHandler by its sockets remote socket address and returns it.
      protected void removeCommunicationHandler​(CommunicationHandler communicationHandler)
      Removes the given communicationHandler from the list
      void run()
      Starts the process of accepting clients to the server.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ClientManager

        public ClientManager​(Server server)
        Initiates a ClientManager object
        Parameters:
        server - that it should manage clients for
    • Method Detail

      • run

        public void run()
        Starts the process of accepting clients to the server. For each client that is accepted a CommunicationHandler is started in a separate Thread.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
        See Also:
        CommunicationHandler
      • close

        public boolean close()
        Closes all client connection and the serversocket itself
        Returns:
        true if the closing process finishes successfully
      • getCommunicationHandlerByIP

        public CommunicationHandler getCommunicationHandlerByIP​(java.lang.String clientAddress)
        Searches for a CommunicationHandler by its sockets remote socket address and returns it. If no CommunicationHandler with that address it will return null.
        Parameters:
        clientAddress - the IP address of the socket related to the CommunicationHandler to look for
        Returns:
        the communicationhandler or null
      • removeCommunicationHandler

        protected void removeCommunicationHandler​(CommunicationHandler communicationHandler)
        Removes the given communicationHandler from the list
        Parameters:
        communicationHandler - to remove