Class RoomManager

java.lang.Object
org.atmosphere.room.RoomManager

public class RoomManager extends Object
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 Details

    • create

      public static RoomManager create(AtmosphereFramework framework)
      Create a RoomManager from an AtmosphereFramework.
      Parameters:
      framework - the Atmosphere framework instance
      Returns:
      a new RoomManager
    • getOrCreate

      public static RoomManager getOrCreate(AtmosphereFramework framework)
      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

      public Room room(String name)
      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

      public boolean exists(String name)
      Check if a room exists.
      Parameters:
      name - the room name
      Returns:
      true if the room exists
    • all

      public Collection<Room> all()
      Get all active rooms.
      Returns:
      an unmodifiable collection of rooms
    • count

      public int count()
      Returns:
      the number of active rooms
    • destroy

      public boolean destroy(String name)
      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.