Class Room

java.lang.Object
net.targetr.rc.Room

public class Room extends Object
Allows multiple clients in the same room to communicate.
Author:
Dr Michael Gardiner
  • Constructor Details

    • Room

      public Room()
      Constructs a new Room instance.
  • Method Details

    • broadcast

      public int broadcast(Client source, ClientCommand command)
      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 null
      command - the command payload and its desired targets
      Returns:
      the number of clients the command was successfully sent to
    • getClient

      public Client getClient(ClientRequest clientReq)
      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

      public Client getClient(String clientId)
      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

      public Client attachClient(ClientRequest clientReq)
      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

      public Map<String,Object> getState()
      Retrieves the current tracking state for all clients in the same room.
      Returns:
      a map organizing states by client IDs
    • collectConnections

      public void collectConnections(List<Closeable> connections)
      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