Package net.targetr.rc
Class Room
java.lang.Object
net.targetr.rc.Room
Allows multiple clients in the same room to communicate.
- Author:
- Dr Michael Gardiner
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionattachClient(ClientRequest clientReq) Adds the client to this room.intbroadcast(Client source, ClientCommand command) Broadcasts a JavaScript command to designated targets in this room.voidcollectConnections(List<Closeable> connections) Aggregates all open internal network socket connections.Retrieves an existing client given their client ID.getClient(ClientRequest clientReq) Retrieves an existing client given their client request.intReturns the total number of connected clients.getState()Retrieves the current tracking state for all clients in the same room.voidmaintenence(long recent) Periodically called to clean up disjointed connections and broadcast update notification.
-
Constructor Details
-
Room
public Room()Constructs a new Room instance.
-
-
Method Details
-
broadcast
Broadcasts a JavaScript command to designated targets in this room. Optionally sends a notification back to the source client about the delivery status (for special apps such as c).- Parameters:
source- the client sending the command, or nullcommand- the command payload and its desired targets- Returns:
- the number of clients the command was successfully sent to
-
getClient
Retrieves an existing client given their client request.- Parameters:
clientReq- the incoming HTTP client request- Returns:
- the matching Client instance, or null if not found
-
getClient
Retrieves an existing client given their client ID.- Parameters:
clientId- the requested client ID- Returns:
- the matching Client instance, or null if not found
-
attachClient
Adds the client to this room. Reuses an existing client slot if matched by ID.- Parameters:
clientReq- the request describing the client- Returns:
- the established Client instance
-
getLiveClientCount
public int getLiveClientCount()Returns the total number of connected clients.- Returns:
- the size of the client list
-
maintenence
public void maintenence(long recent) Periodically called to clean up disjointed connections and broadcast update notification.- Parameters:
recent- the timestamp marking the acceptable idle cutoff
-
getState
Retrieves the current tracking state for all clients in the same room.- Returns:
- a map organizing states by client IDs
-
collectConnections
Aggregates all open internal network socket connections. Useful for safely shutting down network services.- Parameters:
connections- the target list in which to append active connections
-