Package net.targetr.rc.room
Class RoomManager
java.lang.Object
net.targetr.rc.room.RoomManager
Maintains a map of active rooms.
- Author:
- Dr Michael Gardiner
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe room and client established by one atomic attachment operation. -
Constructor Summary
ConstructorsConstructorDescriptionRoomManager(LongSupplier clock) Creates a manager with an elapsed-time clock and no background task. -
Method Summary
Modifier and TypeMethodDescriptionLooks up or creates a room and attaches a client before it can be evicted.voidcloseAll()Forcefully closes all network connections currently established to all rooms.Looks up a room without creating it or extending its empty-room lifetime.static RoomManagerget()Retrieves the singleton RoomManager instance.intGets the total client slot count, including clients retained for reconnection.Retrieves a room, or creates a new one if it does not exist.getRoom(ClientRequest req) Retrieves the request's room, creating it if absent.intGets the number of registered rooms, including empty rooms awaiting expiry.getState()Aggregates state representations from all active rooms.voidRuns one maintenance cycle, keeping notifications outside the registry lock.
-
Constructor Details
-
RoomManager
Creates a manager with an elapsed-time clock and no background task.- Parameters:
clock- supplies monotonic elapsed time in milliseconds for room maintenance
-
-
Method Details
-
get
Retrieves the singleton RoomManager instance.- Returns:
- the room manager
-
attachClient
Looks up or creates a room and attaches a client before it can be evicted.- Parameters:
req- the incoming client request- Returns:
- the registered room and its attached client, or null if the room is full
-
findRoom
Looks up a room without creating it or extending its empty-room lifetime.- Parameters:
roomId- the requested room- Returns:
- the existing room, or null if it does not exist
-
getRoom
Retrieves the request's room, creating it if absent. UseattachClient(ClientRequest)to join a managed room safely.- Parameters:
req- the incoming client request- Returns:
- the associated Room instance
-
getRoom
Retrieves a room, or creates a new one if it does not exist. UseattachClient(ClientRequest)to join a managed room safely.- Parameters:
roomId- the requested room- Returns:
- the associated Room instance
-
getRoomCount
public int getRoomCount()Gets the number of registered rooms, including empty rooms awaiting expiry.- Returns:
- the room count
-
getLiveClientCount
public int getLiveClientCount()Gets the total client slot count, including clients retained for reconnection.- Returns:
- the total client count
-
maintainRooms
public void maintainRooms()Runs one maintenance cycle, keeping notifications outside the registry lock. -
getState
Aggregates state representations from all active rooms.- Returns:
- a map organizing room states by their roomIds.
-
closeAll
public void closeAll()Forcefully closes all network connections currently established to all rooms. Designed to be called during application shutdown.
-