Class SFSRoomVariable
- java.lang.Object
-
- com.smartfoxserver.v2.entities.variables.SFSUserVariable
-
- com.smartfoxserver.v2.entities.variables.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 Summary
Constructors Modifier Constructor Description protected
SFSRoomVariable(java.lang.String name)
SFSRoomVariable(java.lang.String name, java.lang.Object value)
Create a new Room VariableSFSRoomVariable(java.lang.String name, java.lang.Object value, boolean isPrivate, boolean isPersistent, boolean isGlobal)
Create a new Room Variableprotected
SFSRoomVariable(java.lang.String name, java.lang.String type, java.lang.String literal)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description User
getOwner()
Return the User that created the variable.java.lang.String
getOwnerAsString()
boolean
isGlobal()
Checks if a RoomVariable is globalboolean
isPersistent()
Checks if a RoomVariable is persistentboolean
isPrivate()
Checks if a RoomVariable is private.static SFSRoomVariable
newFromSFSArray(ISFSArray array)
static SFSRoomVariable
newFromStringLiteral(java.lang.String name, java.lang.String type, java.lang.String literal)
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 Groupvoid
setOwner(User user)
Sets the creator of a variable.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.void
setPrivate(boolean flag)
When a RoomVariable is set to private only its owner can modify or delete it.ISFSArray
toSFSArray()
Privatejava.lang.String
toString()
-
Methods inherited from class com.smartfoxserver.v2.entities.variables.SFSUserVariable
clone, getBoolValue, getDoubleValue, getIntValue, getName, getSFSArrayValue, getSFSObjectValue, getStringValue, getType, getValue, isHidden, isNull, isStorable, newInstance, newPrivateVariable, populateArrayWithValue, setHidden, setNull, setStorable, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromStringLiteral
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.smartfoxserver.v2.entities.variables.UserVariable
isHidden, isStorable, setHidden, setNull, setStorable
-
Methods inherited from interface com.smartfoxserver.v2.entities.variables.Variable
getBoolValue, getDoubleValue, getIntValue, getName, getSFSArrayValue, getSFSObjectValue, getStringValue, getType, getValue, isNull
-
-
-
-
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 namevalue
- 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 namevalue
- the variable value (see supported data types at the top)isPrivate
- the private flagisPersistent
- the persistent flagisGlobal
- the global flag
-
-
Method Detail
-
newFromStringLiteral
public static SFSRoomVariable newFromStringLiteral(java.lang.String name, java.lang.String type, java.lang.String literal)
-
newFromSFSArray
public static SFSRoomVariable newFromSFSArray(ISFSArray array)
-
isGlobal
public boolean isGlobal()
Checks if a RoomVariable is global- Specified by:
isGlobal
in interfaceRoomVariable
- Returns:
- true if the variable is global
- See Also:
RoomVariable.setGlobal(boolean)
-
isPersistent
public boolean isPersistent()
Checks if a RoomVariable is persistent- Specified by:
isPersistent
in interfaceRoomVariable
- Returns:
- true if the variable is persistent
- See Also:
RoomVariable.setPersistent(boolean)
-
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 interfaceUserVariable
- Overrides:
isPrivate
in classSFSUserVariable
- 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 interfaceRoomVariable
-
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 interfaceRoomVariable
-
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 interfaceUserVariable
- Overrides:
setPrivate
in classSFSUserVariable
- 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 interfaceRoomVariable
- 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 interfaceRoomVariable
-
getOwnerAsString
public java.lang.String getOwnerAsString()
-
toSFSArray
public ISFSArray toSFSArray()
Description copied from interface:Variable
Private- Specified by:
toSFSArray
in interfaceVariable
- Overrides:
toSFSArray
in classSFSUserVariable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classSFSUserVariable
-
-