Package org.red5.server.so
Class SharedObject
java.lang.Object
org.red5.server.AttributeStore
org.red5.server.so.SharedObject
- All Implemented Interfaces:
IAttributeStore,ICastingAttributeStore,IPersistable,ISharedObjectStatistics,IStatisticsBase,AttributeStoreMXBean,Constants
- Direct Known Subclasses:
ClientSharedObject
public class SharedObject
extends AttributeStore
implements ISharedObjectStatistics, IPersistable, Constants
Represents a remote shared object on server-side. RSO's are shared by multiple clients and synchronized on each data change. A shared
object can be persistent or transient; the difference being saved to the disk for later access vs transient objects that are not
persisted to storage. Shared objects have name identifiers and a path. In this implementation we use IPersistenceStore to delegate all
(de)serialization work. SOs store data as a "name-value" store. Each value in can be a complex object or map. All access to methods that
change properties in the SO must be properly synchronized for multithreaded access.
- Author:
- mondain
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.red5.server.net.rtmp.message.Constants
Constants.DataType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AtomicIntegerNumber of times the SO has been acquiredprotected AtomicIntegerCounts number of "change" events.protected AtomicBooleanWhether or not this shared object is closedprotected AtomicIntegerCounts number of "delete" events.protected longLast modified timestampprotected CopyOnWriteArraySet<IEventListener> Listenersprotected StatisticsCounterManages listener statistics.protected static org.slf4j.LoggerConstantlogprotected StringShared Object name (identifier)protected SharedObjectMessageOwner eventprotected StringSO pathprotected booleantrue if the SharedObject was stored by the persistence framework and can be used later on reconnectionprotected AtomicIntegerCounts number of "send message" events.protected IEventListenerEvent listener, actually RTMP connectionprotected IPersistenceStoreObject that is delegated with all storage work for persistent SOsprotected ConcurrentSkipListSet<ISharedObjectEvent> Synchronization eventsprotected AtomicIntegerNumber of pending update operations (beginUpdate / endUpdate)protected AtomicIntegerVersion.Fields inherited from class org.red5.server.AttributeStore
attributes, isDebug, isTraceFields inherited from interface org.red5.server.net.rtmp.message.Constants
HANDSHAKE_SIZE, HEADER_CONTINUE, HEADER_NEW, HEADER_SAME_SOURCE, HEADER_TIMER_CHANGE, MEDIUM_INT_MAX, SO_CLIENT_CLEAR_DATA, SO_CLIENT_DELETE_DATA, SO_CLIENT_INITIAL_DATA, SO_CLIENT_SEND_MESSAGE, SO_CLIENT_STATUS, SO_CLIENT_UPDATE_ATTRIBUTE, SO_CLIENT_UPDATE_DATA, SO_CONNECT, SO_DELETE_ATTRIBUTE, SO_DISCONNECT, SO_SEND_MESSAGE, SO_SET_ATTRIBUTE, SOURCE_TYPE_LIVE, SOURCE_TYPE_VOD, TYPE_ABORT, TYPE_AGGREGATE, TYPE_AUDIO_DATA, TYPE_BYTES_READ, TYPE_CHUNK_SIZE, TYPE_CLIENT_BANDWIDTH, TYPE_EDGE_ORIGIN, TYPE_FLEX_MESSAGE, TYPE_FLEX_SHARED_OBJECT, TYPE_FLEX_STREAM_SEND, TYPE_INVOKE, TYPE_NOTIFY, TYPE_PING, TYPE_SERVER_BANDWIDTH, TYPE_SHARED_OBJECT, TYPE_STREAM_METADATA, TYPE_VIDEO_DATAFields inherited from interface org.red5.server.api.persistence.IPersistable
TRANSIENT_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new SharedObject.SharedObject(String name, String path, boolean persistent) Creates new SO from given data map, name, path and persistence optionSharedObject(String name, String path, boolean persistent, IPersistenceStore storage) Creates new SO from given data map, name, path, storage object and persistence optionCreates new SO from given data map, name, path and persistence optionSharedObject(Map<String, Object> data, String name, String path, boolean persistent, IPersistenceStore storage) Creates new SO from given data map, name, path, storage object and persistence optionSharedObject(Input input) Constructs new SO from Input object -
Method Summary
Modifier and TypeMethodDescriptionvoidacquire()Prevent shared object from being released.voidBegin update of this Shared Object.voidbeginUpdate(IEventListener listener) Begin update of this Shared Object and setting listenerprotected voidCheck if shared object must be released.protected booleanclear()Deletes all the attributes and sends a clear event to all listeners.protected voidclose()Detaches a reference from this shared object, reset it's state, this will destroy the reference immediately.voiddeserialize(Input input) Load the object from the passed input stream.voidEnd update of this Shared Object.intReturn current number of subscribed listeners.getAttribute(String name) Return the value for a given attribute.getAttribute(String name, Object def) Return the value for a given attribute and set it if it doesn't exist.longReturn the timestamp the object was created.getData()Getter for data.longReturns the timestamp when the object was last modified.Get event listeners.intDeprecated.getName()Return the name of the shared object.getPath()Returns the path of the persistent object.getStore()Returns the persistence store this object is stored inintReturn number of attribute changes.intReturn number of attribute deletes.intReturn total number of subscribed listeners.intReturn number of times a message was sent.getType()Returns the type of the persistent object.intGetter for version.booleanCheck if shared object currently is acquired.booleanisClosed()isClosed.booleanCheck if the shared object is persistent.protected voidSend notification about modification of SOprotected booleanregister(IEventListener listener) Register event listenervoidrelease()Release previously acquired shared object.booleanremoveAttribute(String name) removeAttribute.voidRemove all attributes.protected voidreturnError(String message) Return an error message to the client.protected voidsendMessage(String handler, List<?> arguments) Broadcast event to event handlerprotected voidSend update notification over data channel of RTMP connectionvoidWrite the object to the passed output stream.booleansetAttribute(String name, Object value) Set an attribute on this object.booleansetAttributes(Map<String, Object> values) Set multiple attributes on this object.booleansetAttributes(IAttributeStore values) Set multiple attributes on this object.voidsetDirty(boolean dirty) voidvoidSet the name of the persistent object.voidSet the path of the persistent object.voidsetPersistent(boolean persistent) Set the persistent flag of the object.voidsetStore(IPersistenceStore store) Store a reference to the persistence store in the object.protected voidunregister(IEventListener listener) Unregister event listenerMethods inherited from class org.red5.server.AttributeStore
filterNull, from, getAttribute, getAttributeNames, getAttributes, getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute, hasAttribute, hasAttribute, removeAttribute, setAttribute, size
-
Field Details
-
log
protected static org.slf4j.Logger logConstantlog -
name
Shared Object name (identifier) -
path
SO path -
persistent
protected boolean persistenttrue if the SharedObject was stored by the persistence framework and can be used later on reconnection -
storage
Object that is delegated with all storage work for persistent SOs -
version
Version. Used on synchronization purposes. -
updateCounter
Number of pending update operations (beginUpdate / endUpdate) -
lastModified
protected volatile long lastModifiedLast modified timestamp -
ownerMessage
Owner event -
syncEvents
Synchronization events -
listeners
Listeners -
source
Event listener, actually RTMP connection -
acquireCount
Number of times the SO has been acquired -
listenerStats
Manages listener statistics. -
changeStats
Counts number of "change" events. -
deleteStats
Counts number of "delete" events. -
sendStats
Counts number of "send message" events. -
closed
Whether or not this shared object is closed
-
-
Constructor Details
-
SharedObject
public SharedObject()Constructs a new SharedObject. -
SharedObject
Constructs new SO from Input object- Parameters:
input- Input source- Throws:
IOException- I/O exception- See Also:
-
SharedObject
Creates new SO from given data map, name, path and persistence option- Parameters:
name- SO namepath- SO pathpersistent- SO persistence
-
SharedObject
Creates new SO from given data map, name, path, storage object and persistence option- Parameters:
name- SO namepath- SO pathpersistent- SO persistencestorage- Persistence storage
-
SharedObject
Creates new SO from given data map, name, path and persistence option- Parameters:
data- Dataname- SO namepath- SO pathpersistent- SO persistence
-
SharedObject
public SharedObject(Map<String, Object> data, String name, String path, boolean persistent, IPersistenceStore storage) Creates new SO from given data map, name, path, storage object and persistence option- Parameters:
data- Dataname- SO namepath- SO pathpersistent- SO persistencestorage- Persistence storage
-
-
Method Details
-
getName
Return the name of the shared object.- Specified by:
getNamein interfaceIPersistable- Specified by:
getNamein interfaceISharedObjectStatistics- Returns:
- a
Stringobject
-
setName
Set the name of the persistent object.- Specified by:
setNamein interfaceIPersistable- Parameters:
name- New object name
-
getPath
Returns the path of the persistent object.- Specified by:
getPathin interfaceIPersistable- Returns:
- a
Stringobject
-
setPath
Set the path of the persistent object.- Specified by:
setPathin interfaceIPersistable- Parameters:
path- New persisted object path
-
getType
Returns the type of the persistent object.- Specified by:
getTypein interfaceIPersistable- Returns:
- a
Stringobject
-
getLastModified
public long getLastModified()Returns the timestamp when the object was last modified.- Specified by:
getLastModifiedin interfaceIPersistable- Returns:
- a long
-
isPersistent
public boolean isPersistent()Check if the shared object is persistent.- Specified by:
isPersistentin interfaceIPersistable- Specified by:
isPersistentin interfaceISharedObjectStatistics- Returns:
- a boolean
-
setPersistent
public void setPersistent(boolean persistent) Set the persistent flag of the object.- Specified by:
setPersistentin interfaceIPersistable- Parameters:
persistent-true
if object is persistent,false
otherwise
-
sendUpdates
protected void sendUpdates()Send update notification over data channel of RTMP connection -
notifyModified
protected void notifyModified()Send notification about modification of SO -
returnError
Return an error message to the client.- Parameters:
message- message
-
getAttribute
Return the value for a given attribute.- Specified by:
getAttributein interfaceIAttributeStore- Overrides:
getAttributein classAttributeStore- Parameters:
name- aStringobject- Returns:
- a
Objectobject
-
getAttribute
Return the value for a given attribute and set it if it doesn't exist. This is a utility function that internally performs the following code:
if (!hasAttribute(name)) setAttribute(name, defaultValue); return getAttribute(name);- Specified by:
getAttributein interfaceIAttributeStore- Overrides:
getAttributein classAttributeStore- Parameters:
name- the name of the attribute to getdef- the value of the attribute to set if the attribute doesn't exist- Returns:
- the attribute value
-
setAttribute
Set an attribute on this object. Set an attribute on this object.- Specified by:
setAttributein interfaceIAttributeStore- Overrides:
setAttributein classAttributeStore- Parameters:
name- the name of the attribute to changevalue- the new value of the attribute- Returns:
- true if the attribute value changed otherwise false
-
setAttributes
Set multiple attributes on this object.- Specified by:
setAttributesin interfaceIAttributeStore- Overrides:
setAttributesin classAttributeStore- Parameters:
values- aMapobject- Returns:
- a boolean
-
setAttributes
Set multiple attributes on this object.- Specified by:
setAttributesin interfaceIAttributeStore- Overrides:
setAttributesin classAttributeStore- Parameters:
values- the attributes to set- Returns:
- true if the attribute values changed otherwise false
-
removeAttribute
removeAttribute.
Remove an attribute.- Specified by:
removeAttributein interfaceAttributeStoreMXBean- Specified by:
removeAttributein interfaceIAttributeStore- Overrides:
removeAttributein classAttributeStore- Parameters:
name- aStringobject- Returns:
- a boolean
-
removeAttributes
public void removeAttributes()Remove all attributes.- Specified by:
removeAttributesin interfaceAttributeStoreMXBean- Specified by:
removeAttributesin interfaceIAttributeStore- Overrides:
removeAttributesin classAttributeStore
-
sendMessage
Broadcast event to event handler- Parameters:
handler- Event handlerarguments- Arguments
-
getData
Getter for data.- Returns:
- SO data as unmodifiable map
-
getVersion
public int getVersion()Getter for version.- Specified by:
getVersionin interfaceISharedObjectStatistics- Returns:
- SO version.
-
register
Register event listener- Parameters:
listener- Event listener- Returns:
- true if listener was added
-
unregister
Unregister event listener- Parameters:
listener- Event listener
-
checkRelease
protected void checkRelease()Check if shared object must be released. -
getListeners
Get event listeners.- Returns:
- Value for property 'listeners'.
-
beginUpdate
public void beginUpdate()Begin update of this Shared Object. Increases number of pending update operations -
beginUpdate
Begin update of this Shared Object and setting listener- Parameters:
listener- Update with listener
-
endUpdate
public void endUpdate()End update of this Shared Object. Decreases number of pending update operations and broadcasts modified event if it is equal to zero (i.e. no more pending update operations). -
serialize
Write the object to the passed output stream.- Specified by:
serializein interfaceIPersistable- Parameters:
output- Output stream to write to- Throws:
IOException- Any I/O exception
-
deserialize
Load the object from the passed input stream.- Specified by:
deserializein interfaceIPersistable- Parameters:
input- Input stream to load from- Throws:
IOException- Any I/O exception
-
setStore
Store a reference to the persistence store in the object.- Specified by:
setStorein interfaceIPersistable- Parameters:
store- Store the object is saved in
-
getStore
Returns the persistence store this object is stored in- Specified by:
getStorein interfaceIPersistable- Returns:
- a
IPersistenceStoreobject
-
clear
protected boolean clear()Deletes all the attributes and sends a clear event to all listeners. The persistent data object is also removed from a persistent shared object.- Returns:
- true on success, false otherwise
-
close
protected void close()Detaches a reference from this shared object, reset it's state, this will destroy the reference immediately. This is useful when you don't want to proxy a shared object any longer. -
acquire
public void acquire()Prevent shared object from being released. Each call to acquire must be paired with a call to release so the SO isn't held forever. This is only valid for non-persistent SOs. -
isAcquired
public boolean isAcquired()Check if shared object currently is acquired.- Returns:
- true if the SO is acquired, false otherwise
-
release
public void release()Release previously acquired shared object. If the SO is non-persistent, no more clients are connected the SO isn't acquired any more, the data is released. -
isClosed
public boolean isClosed()isClosed.
- Returns:
- a boolean
-
getCreationTime
public long getCreationTime()Return the timestamp the object was created.- Specified by:
getCreationTimein interfaceIStatisticsBase- Returns:
- a long
-
getTotalListeners
public int getTotalListeners()Return total number of subscribed listeners.- Specified by:
getTotalListenersin interfaceISharedObjectStatistics- Returns:
- a int
-
getMaxListeners
Deprecated.Return maximum number of concurrent subscribed listenes.- Specified by:
getMaxListenersin interfaceISharedObjectStatistics- Returns:
- a int
-
getActiveListeners
public int getActiveListeners()Return current number of subscribed listeners.- Specified by:
getActiveListenersin interfaceISharedObjectStatistics- Returns:
- a int
-
getTotalChanges
public int getTotalChanges()Return number of attribute changes.- Specified by:
getTotalChangesin interfaceISharedObjectStatistics- Returns:
- a int
-
getTotalDeletes
public int getTotalDeletes()Return number of attribute deletes.- Specified by:
getTotalDeletesin interfaceISharedObjectStatistics- Returns:
- a int
-
getTotalSends
public int getTotalSends()Return number of times a message was sent.- Specified by:
getTotalSendsin interfaceISharedObjectStatistics- Returns:
- a int
-
setDirty
public void setDirty(boolean dirty) - Parameters:
dirty- a boolean
-
setDirty
- Parameters:
name- aStringobject
-