Class DefaultRoom

java.lang.Object
org.atmosphere.room.DefaultRoom
All Implemented Interfaces:
Room

public class DefaultRoom extends Object implements Room
Default Room implementation backed by a Broadcaster.

Each room wraps a dedicated Broadcaster identified by the room name. Presence events are tracked via a BroadcasterListenerAdapter that listens for resource additions and removals.

Since:
4.0
  • Constructor Details

    • DefaultRoom

      public DefaultRoom(String name, Broadcaster broadcaster)
      Create a room backed by the given broadcaster.
      Parameters:
      name - the room name
      broadcaster - the backing broadcaster
  • Method Details

    • name

      public String name()
      Specified by:
      name in interface Room
      Returns:
      the room name (unique identifier)
    • join

      public Room join(AtmosphereResource resource)
      Description copied from interface: Room
      Add a resource to this room.
      Specified by:
      join in interface Room
      Parameters:
      resource - the resource to add
      Returns:
      this room for chaining
    • join

      public Room join(AtmosphereResource resource, RoomMember member)
      Description copied from interface: Room
      Add a resource to this room with application-level member info.
      Specified by:
      join in interface Room
      Parameters:
      resource - the resource to add
      member - the member identity and metadata
      Returns:
      this room for chaining
    • leave

      public Room leave(AtmosphereResource resource)
      Description copied from interface: Room
      Remove a resource from this room.
      Specified by:
      leave in interface Room
      Parameters:
      resource - the resource to remove
      Returns:
      this room for chaining
    • broadcast

      public Future<Object> broadcast(Object message)
      Description copied from interface: Room
      Broadcast a message to all members of this room.
      Specified by:
      broadcast in interface Room
      Parameters:
      message - the message to broadcast
      Returns:
      a future that completes when the broadcast is delivered
    • broadcast

      public Future<Object> broadcast(Object message, AtmosphereResource sender)
      Description copied from interface: Room
      Broadcast a message to all members except the sender.
      Specified by:
      broadcast in interface Room
      Parameters:
      message - the message to broadcast
      sender - the resource to exclude
      Returns:
      a future that completes when the broadcast is delivered
    • sendTo

      public Future<Object> sendTo(Object message, String uuid)
      Description copied from interface: Room
      Send a direct message to a specific member by UUID.
      Specified by:
      sendTo in interface Room
      Parameters:
      message - the message to send
      uuid - the target resource's UUID
      Returns:
      a future that completes when the message is delivered
    • members

      public Set<AtmosphereResource> members()
      Specified by:
      members in interface Room
      Returns:
      an unmodifiable set of all current members
    • size

      public int size()
      Specified by:
      size in interface Room
      Returns:
      the number of members in this room
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Room
      Returns:
      true if this room has no members
    • contains

      public boolean contains(AtmosphereResource resource)
      Description copied from interface: Room
      Check if a resource is a member of this room.
      Specified by:
      contains in interface Room
      Parameters:
      resource - the resource to check
      Returns:
      true if the resource is in this room
    • onPresence

      public Room onPresence(Consumer<PresenceEvent> listener)
      Description copied from interface: Room
      Register a presence listener for join/leave events.
      Specified by:
      onPresence in interface Room
      Parameters:
      listener - the presence event listener
      Returns:
      this room for chaining
    • memberInfo

      public Map<String,RoomMember> memberInfo()
      Specified by:
      memberInfo in interface Room
      Returns:
      a map of resource UUID to RoomMember for all members that joined with member info
    • memberOf

      public Optional<RoomMember> memberOf(AtmosphereResource resource)
      Description copied from interface: Room
      Retrieve the RoomMember associated with a resource, if present.
      Specified by:
      memberOf in interface Room
      Parameters:
      resource - the resource to look up
      Returns:
      the member info, or empty if the resource has none
    • enableHistory

      public Room enableHistory(int maxMessages)
      Description copied from interface: Room
      Enable message history (replay) for this room. New joiners will receive up to maxMessages cached messages.
      Specified by:
      enableHistory in interface Room
      Parameters:
      maxMessages - the maximum number of messages to cache
      Returns:
      this room for chaining
    • historySize

      public int historySize()
      Returns:
      the configured history size, or 0 if history is disabled
    • joinVirtual

      public Room joinVirtual(VirtualRoomMember member)
      Description copied from interface: Room
      Add a virtual (non-connection) member to this room. Virtual members receive broadcasts via VirtualRoomMember.onMessage(org.atmosphere.room.Room, java.lang.String, java.lang.Object) and can respond by broadcasting back into the room.
      Specified by:
      joinVirtual in interface Room
      Parameters:
      member - the virtual member (e.g., an AI agent)
      Returns:
      this room for chaining
    • leaveVirtual

      public Room leaveVirtual(VirtualRoomMember member)
      Description copied from interface: Room
      Remove a virtual member from this room.
      Specified by:
      leaveVirtual in interface Room
      Parameters:
      member - the virtual member to remove
      Returns:
      this room for chaining
    • virtualMembers

      public Set<VirtualRoomMember> virtualMembers()
      Specified by:
      virtualMembers in interface Room
      Returns:
      an unmodifiable set of all virtual members in this room
    • destroy

      public void destroy()
      Description copied from interface: Room
      Destroy this room, removing all members and releasing resources.
      Specified by:
      destroy in interface Room
    • isDestroyed

      public boolean isDestroyed()
      Specified by:
      isDestroyed in interface Room
      Returns:
      true if this room has been destroyed
    • broadcaster

      public Broadcaster broadcaster()
      Returns:
      the underlying broadcaster for advanced use cases