Class SFSRoomVariable

  • All Implemented Interfaces:
    RoomVariable, UserVariable, Variable, java.io.Serializable, java.lang.Cloneable

    public class SFSRoomVariable
    extends SFSUserVariable
    implements RoomVariable
    RoomVariables are custom values attached to each Room object that get automatically updated between client and server on every change. They are particularly useful to "attach" any custom data to each Room such as the current game status, Room-specific properties etc...

    RoomVariables support basic data types and nested complex objects:

    • Null
    • Bool
    • Int
    • Double
    • String
    • SFSObject
    • SFSArray

    RoomVariables also support different flags:

    • Private: a private variable can only be modified by its creator
    • Persistent: a persistent variable will continue to exist even if its creator has left the room. Server-created Room Variables will never be removed.
    • Global: a global variable will fire updates not only to all Users in the Room but also to all Users in the Room Group
    • Hidden: an hidden variable will be kept on the server side only
    • Storable: all variables are storable by default. When the flag is turned off the Room Persistence API will ignore the variable
    See Also:
    Serialized Form
    • Constructor Detail

      • SFSRoomVariable

        protected SFSRoomVariable​(java.lang.String name)
      • SFSRoomVariable

        protected SFSRoomVariable​(java.lang.String name,
                                  java.lang.String type,
                                  java.lang.String literal)
      • SFSRoomVariable

        public SFSRoomVariable​(java.lang.String name,
                               java.lang.Object value)
        Create a new Room Variable
        Parameters:
        name - the variable name
        value - the variable value (see supported data types at the top)
      • SFSRoomVariable

        public SFSRoomVariable​(java.lang.String name,
                               java.lang.Object value,
                               boolean isPrivate,
                               boolean isPersistent,
                               boolean isGlobal)
        Create a new Room Variable
        Parameters:
        name - the variable name
        value - the variable value (see supported data types at the top)
        isPrivate - the private flag
        isPersistent - the persistent flag
        isGlobal - the global flag
    • Method Detail

      • newFromStringLiteral

        public static SFSRoomVariable newFromStringLiteral​(java.lang.String name,
                                                           java.lang.String type,
                                                           java.lang.String literal)
      • isPrivate

        public boolean isPrivate()
        Checks if a RoomVariable is private. Private Room variables are visible to all Users in the Room but only the owner can modify or delete them.
        Specified by:
        isPrivate in interface UserVariable
        Overrides:
        isPrivate in class SFSUserVariable
        Returns:
        true if the variable is private
        See Also:
        setPrivate(boolean)
      • setGlobal

        public void setGlobal​(boolean flag)
        When a RoomVariable is set to global all changes will be broadcast not only to the Users in the Room but also to all other Users in the same Room Group
        Specified by:
        setGlobal in interface RoomVariable
      • setPersistent

        public void setPersistent​(boolean flag)
        When a RoomVariable is set to persistent the variable will not be removed from a Room when the user leaves it. RoomVariables created by a certain User are removed when the User disconnects
        Specified by:
        setPersistent in interface RoomVariable
      • setPrivate

        public void setPrivate​(boolean flag)
        When a RoomVariable is set to private only its owner can modify or delete it.
        Specified by:
        setPrivate in interface UserVariable
        Overrides:
        setPrivate in class SFSUserVariable
        Parameters:
        flag -
      • getOwner

        public User getOwner()
        Return the User that created the variable. Null is returned if the variable is owned by the Server
        Specified by:
        getOwner in interface RoomVariable
        Returns:
        the variable owner
      • setOwner

        public void setOwner​(User user)
        Sets the creator of a variable. Null can be used to set the Server as the owner. When a variable is owned by the Server it will never be removed.
        Specified by:
        setOwner in interface RoomVariable
      • getOwnerAsString

        public java.lang.String getOwnerAsString()