Package org.atmosphere.room
Class RoomManager
java.lang.Object
org.atmosphere.room.RoomManager
Manages the lifecycle of
Room instances. Each room is backed by
a dedicated Broadcaster obtained from the framework's
BroadcasterFactory.
RoomManager rooms = RoomManager.create(framework);
// Get or create a room
Room lobby = rooms.room("lobby");
lobby.join(resource);
lobby.broadcast("Welcome!");
// List all rooms
rooms.all().forEach(r -> log.info("Room: " + r.name()));
// Destroy a room
rooms.destroy("lobby");
- Since:
- 4.0
-
Method Summary
Modifier and TypeMethodDescriptionall()Get all active rooms.intcount()static RoomManagercreate(AtmosphereFramework framework) Create a RoomManager from an AtmosphereFramework.booleanDestroy a room by name, removing all members.voidDestroy all rooms.booleanCheck if a room exists.static RoomManagergetOrCreate(AtmosphereFramework framework) Get or create a singleton RoomManager for the given framework.Get or create a room by name.
-
Method Details
-
create
Create a RoomManager from an AtmosphereFramework.- Parameters:
framework- the Atmosphere framework instance- Returns:
- a new RoomManager
-
getOrCreate
Get or create a singleton RoomManager for the given framework. When a servlet context is available, the instance is also stored there for lookup by other components.- Parameters:
framework- the Atmosphere framework instance- Returns:
- the shared RoomManager
-
room
Get or create a room by name. The room will be lazily created on first access and backed by a broadcaster with ID/atmosphere/room/<name>.- Parameters:
name- the room name- Returns:
- the room
-
exists
Check if a room exists.- Parameters:
name- the room name- Returns:
- true if the room exists
-
all
Get all active rooms.- Returns:
- an unmodifiable collection of rooms
-
count
public int count()- Returns:
- the number of active rooms
-
destroy
Destroy a room by name, removing all members.- Parameters:
name- the room name- Returns:
- true if the room existed and was destroyed
-
destroyAll
public void destroyAll()Destroy all rooms.
-