- java.lang.Object
-
- java.lang.Thread
-
- dev.bitbite.networking.ClientManager
-
- All Implemented Interfaces:
java.lang.Runnable
public class ClientManager extends java.lang.ThreadAdministrates the clients an runs in its own Thread. It accepts them from the serversocket and starts aCommunicationHandlerin a separate thread for each connecting client.- See Also:
CommunicationHandler
-
-
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 booleanclose()Closes all client connection and the serversocket itselfCommunicationHandlergetCommunicationHandlerByIP(java.lang.String clientAddress)Searches for aCommunicationHandlerby its sockets remote socket address and returns it.protected voidremoveCommunicationHandler(CommunicationHandler communicationHandler)Removes the given communicationHandler from the listvoidrun()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
-
-
-
-
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 aCommunicationHandleris started in a separate Thread.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.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 aCommunicationHandlerby its sockets remote socket address and returns it. If no CommunicationHandler with that address it will returnnull.- 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
-
-