Class SFSRoomManager

java.lang.Object
sfs3.client.entities.managers.SFSRoomManager
All Implemented Interfaces:
IRoomManager

public class SFSRoomManager extends Object implements IRoomManager
The SFSRoomManager class is the entity in charge of managing the client-side Rooms list. It keeps track of all the Rooms available in the client-side Rooms list and of subscriptions to multiple Room Groups. It also provides various utility methods to look for Rooms by name and id, retrieve Rooms belonging to a specific Group, etc.
See Also:
  • Field Details

    • smartFox

      protected final ISmartFox smartFox
  • Constructor Details

    • SFSRoomManager

      public SFSRoomManager(ISmartFox smartFox)
      Creates a new SFSRoomManager instance.

      NOTE: developers never instantiate a SFSRoomManager manually: this is done by the SmartFoxServer 3 API internally. A reference to the existing instance can be retrieved using the SmartFox.getRoomManager() method.

      Parameters:
      smartFox - An instance of the SmartFoxServer 3 client API main SmartFox class.
      See Also:
  • Method Details

    • addRoom

      public void addRoom(Room room)
      Specified by:
      addRoom in interface IRoomManager
    • addRoom

      public void addRoom(Room room, boolean addGroupIfMissing)
      Specified by:
      addRoom in interface IRoomManager
    • addGroup

      public void addGroup(String groupId)
      Specified by:
      addGroup in interface IRoomManager
    • updateRoomList

      public void updateRoomList(ISFSArray roomList) throws SFSException
      Specified by:
      updateRoomList in interface IRoomManager
      Throws:
      SFSException
    • removeGroup

      public void removeGroup(String groupId)
      Specified by:
      removeGroup in interface IRoomManager
    • containsGroup

      public boolean containsGroup(String groupId)
      Description copied from interface: IRoomManager
      Indicates whether the specified Group has been subscribed by the client or not.
      Specified by:
      containsGroup in interface IRoomManager
      Parameters:
      groupId - The name of the Group.
      Returns:
      true if the client subscribed the passed Group.
    • containsRoom

      public boolean containsRoom(int id)
      Description copied from interface: IRoomManager
      Indicates whether a Room exists in the Rooms list or not.
      Specified by:
      containsRoom in interface IRoomManager
      Parameters:
      id - The id of the Room object whose presence in the Rooms list is to be tested.
      Returns:
      true if the passed Room exists in the Rooms list.
      See Also:
    • containsRoom

      public boolean containsRoom(String name)
      Description copied from interface: IRoomManager
      Indicates whether a Room exists in the Rooms list or not.
      Specified by:
      containsRoom in interface IRoomManager
      Parameters:
      name - The name of the Room object whose presence in the Rooms list is to be tested.
      Returns:
      true if the passed Room exists in the Rooms list.
      See Also:
    • containsRoomInGroup

      public boolean containsRoomInGroup(int roomId, String groupId)
      Description copied from interface: IRoomManager
      Indicates whether the Rooms list contains a Room belonging to the specified Group or not.
      Specified by:
      containsRoomInGroup in interface IRoomManager
      Parameters:
      roomId - The id of the Room object whose presence in the Rooms list is to be tested.
      groupId - The name of the Group to which the specified Room must belong.
      Returns:
      true if the Rooms list contains the passed Room and it belongs to the specified Group.
      See Also:
    • containsRoomInGroup

      public boolean containsRoomInGroup(String roomName, String groupId)
      Description copied from interface: IRoomManager
      Indicates whether the Rooms list contains a Room belonging to the specified Group or not.
      Specified by:
      containsRoomInGroup in interface IRoomManager
      Parameters:
      roomName - The name of the Room object whose presence in the Rooms list is to be tested.
      groupId - The name of the Group to which the specified Room must belong.
      Returns:
      true if the Rooms list contains the passed Room and it belongs to the specified Group.
      See Also:
    • changeRoomName

      public void changeRoomName(Room room, String newName)
      Specified by:
      changeRoomName in interface IRoomManager
    • changeRoomPasswordState

      public void changeRoomPasswordState(Room room, boolean isPassProtected)
      Specified by:
      changeRoomPasswordState in interface IRoomManager
    • changeRoomCapacity

      public void changeRoomCapacity(Room room, int maxUsers, int maxSpect)
      Specified by:
      changeRoomCapacity in interface IRoomManager
    • getRoomById

      public Room getRoomById(int id)
      Description copied from interface: IRoomManager
      Retrieves a Room object from its id.
      Specified by:
      getRoomById in interface IRoomManager
      Parameters:
      id - The id of the Room.
      Returns:
      An object representing the requested Room; null if no Room object with the passed id exists in the Rooms list.

      Example
      The following example retrieves a Room object and traces its name:

               
               	int roomId = 3;
               	Room room = sfs.getRoomById(roomId);
               	System.out.println("The name of Room " + roomId + " is " + room.getName());
               
               
      See Also:
    • getRoomByName

      public Room getRoomByName(String name)
      Description copied from interface: IRoomManager
      Retrieves a Room object from its name.
      Specified by:
      getRoomByName in interface IRoomManager
      Parameters:
      name - The name of the Room.
      Returns:
      An object representing the requested Room; null if no Room object with the passed name exists in the Rooms list.

      Example
      The following example retrieves a Room object and traces its id:

               
               	String roomName = "The Lobby";
               	Room room = sfs.getRoomByName(roomName);
               	System.out.println("The ID of Room '" + roomName + "' is " + room.getId());
               
               
      See Also:
    • getRoomList

      public List<Room> getRoomList()
      Description copied from interface: IRoomManager
      Returns a list of Rooms currently "known" by the client. The list contains all the Rooms that are currently joined and all the Rooms belonging to the Room Groups that have been subscribed.

      NOTE: at login time, the client automatically subscribes all the Room Groups specified in the Zone's Default Room Groups setting.

      Specified by:
      getRoomList in interface IRoomManager
      Returns:
      The list of the available Room objects.
      See Also:
    • getRoomCount

      public int getRoomCount()
      Description copied from interface: IRoomManager
      Returns the current number of Rooms in the Rooms list.
      Specified by:
      getRoomCount in interface IRoomManager
      Returns:
      The number of Rooms in the Rooms list.
    • getRoomGroups

      public List<String> getRoomGroups()
      Description copied from interface: IRoomManager
      Returns the names of Room Groups currently subscribed by the client.

      NOTE: at login time, the client automatically subscribes all the Room Groups specified in the Zone's Default Room Groups setting.

      Specified by:
      getRoomGroups in interface IRoomManager
      Returns:
      A list of Room Group names.
      See Also:
    • getRoomListFromGroup

      public List<Room> getRoomListFromGroup(String groupId)
      Description copied from interface: IRoomManager
      Retrieves the list of Rooms which are part of the specified Room Group.
      Specified by:
      getRoomListFromGroup in interface IRoomManager
      Parameters:
      groupId - The name of the Group.
      Returns:
      The list of Room objects belonging to the passed Room Group.
      See Also:
    • getJoinedRooms

      public List<Room> getJoinedRooms()
      Description copied from interface: IRoomManager
      Returns a list of Rooms currently joined by the client.
      Specified by:
      getJoinedRooms in interface IRoomManager
      Returns:
      The list of Room objects representing the Rooms currently joined by the client.
      See Also:
    • getUserRooms

      public List<Room> getUserRooms(User user)
      Description copied from interface: IRoomManager
      Retrieves a list of Rooms joined by the specified user. The list contains only those Rooms "known" by the Room Manager; the user might have joined others the client is not aware of.
      Specified by:
      getUserRooms in interface IRoomManager
      Parameters:
      user - A User object representing the user to look for in the current Rooms list.
      Returns:
      The list of Rooms joined by the passed user.
    • removeRoom

      public void removeRoom(Room room)
      Specified by:
      removeRoom in interface IRoomManager
    • removeRoomById

      public void removeRoomById(int id)
      Specified by:
      removeRoomById in interface IRoomManager
    • removeRoomByName

      public void removeRoomByName(String name)
      Specified by:
      removeRoomByName in interface IRoomManager
    • removeUser

      public void removeUser(User user)
      Specified by:
      removeUser in interface IRoomManager
    • getSmartFox

      public ISmartFox getSmartFox()
      Specified by:
      getSmartFox in interface IRoomManager