|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.red5.server.AttributeStore
org.red5.server.so.SharedObject
public class SharedObject
Represents shared object on server-side. Shared Objects in Flash are like cookies that are stored on client side. In Red5 and Flash Media Server there's one more special type of SOs : remote Shared Objects. These are shared by multiple clients and synchronized between them automatically on each data change. This is done asynchronously, used as events handling and is widely used in multiplayer Flash online games. Shared object can be persistent or transient. The difference is that first are saved to the disk and can be accessed later on next connection, transient objects are not saved and get lost each time they last client disconnects from it. Shared Objects has name identifiers and path on server's HD (if persistent). On deeper level server-side Shared Object in this implementation actually uses IPersistenceStore to delegate all (de)serialization work. SOs store data as simple map, that is, "name-value" pairs. Each value in turn can be complex object or map. All access to methods that change properties in the SO must be properly synchronized for multi-threaded access.
Field Summary | |
---|---|
protected AtomicInteger |
acquireCount
Number of times the SO has been acquired |
protected AtomicInteger |
changeStats
Counts number of "change" events. |
protected AtomicInteger |
deleteStats
Counts number of "delete" events. |
protected long |
lastModified
Last modified timestamp |
protected CopyOnWriteArraySet<IEventListener> |
listeners
Listeners |
protected StatisticsCounter |
listenerStats
Manages listener statistics. |
protected static Logger |
log
Logger |
protected boolean |
modified
Has changes? flag |
protected String |
name
Shared Object name (identifier) |
protected SharedObjectMessage |
ownerMessage
Owner event |
protected String |
path
SO path |
protected boolean |
persistent
true if the SharedObject was stored by the persistence framework (NOT in database, just plain serialization to the disk) and can be used later on reconnection |
protected AtomicInteger |
sendStats
Counts number of "send message" events. |
protected IEventListener |
source
Event listener, actually RTMP connection |
protected IPersistenceStore |
storage
Object that is delegated with all storage work for persistent SOs |
protected ConcurrentLinkedQueue<ISharedObjectEvent> |
syncEvents
Synchronization events |
protected AtomicInteger |
updateCounter
Number of pending update operations |
protected AtomicInteger |
version
Version. |
Fields inherited from class org.red5.server.AttributeStore |
---|
attributes |
Fields inherited from interface org.red5.server.api.persistence.IPersistable |
---|
TRANSIENT_PREFIX |
Constructor Summary | |
---|---|
SharedObject()
Constructs a new SharedObject. |
|
SharedObject(Input input)
Constructs new SO from Input object |
|
SharedObject(Map<String,Object> data,
String name,
String path,
boolean persistent)
Creates new SO from given data map, name, path and persistence option |
|
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 |
|
SharedObject(String name,
String path,
boolean persistent)
Creates new SO from given data map, name, path and persistence option |
|
SharedObject(String name,
String path,
boolean persistent,
IPersistenceStore storage)
Creates new SO from given data map, name, path, storage object and persistence option |
Method Summary | |
---|---|
void |
acquire()
Prevent shared object from being released. |
protected void |
beginUpdate()
Begin update of this Shared Object. |
protected void |
beginUpdate(IEventListener listener)
Begin update of this Shared Object and setting listener |
protected void |
checkRelease()
Check if shared object must be released. |
protected boolean |
clear()
Deletes all the attributes and sends a clear event to all listeners. |
protected void |
close()
Detaches a reference from this shared object, reset it's state, this will destroy the reference immediately. |
void |
deserialize(Input input)
Load the object from the passed input stream. |
protected void |
endUpdate()
End update of this Shared Object. |
int |
getActiveListeners()
Return current number of subscribed listeners. |
Object |
getAttribute(String name,
Object value)
Return attribute by name and set if it doesn't exist yet. |
long |
getCreationTime()
Return the timestamp the object was created. |
Map<String,Object> |
getData()
Getter for data. |
long |
getLastModified()
Returns the timestamp when the object was last modified. |
Set<IEventListener> |
getListeners()
Get event listeners. |
int |
getMaxListeners()
Return maximum number of concurrent subscribed listenes. |
String |
getName()
Return the name of the shared object. |
String |
getPath()
Returns the path of the persistent object. |
IPersistenceStore |
getStore()
Returns the persistence store this object is stored in |
int |
getTotalChanges()
Return number of attribute changes. |
int |
getTotalDeletes()
Return number of attribute deletes. |
int |
getTotalListeners()
Return total number of subscribed listeners. |
int |
getTotalSends()
Return number of times a message was sent. |
String |
getType()
Returns the type of the persistent object. |
int |
getVersion()
Getter for version. |
boolean |
isAcquired()
Check if shared object currently is acquired. |
boolean |
isPersistent()
Check if the shared object is persistent. |
protected void |
notifyModified()
Send notification about modification of SO |
protected boolean |
register(IEventListener listener)
Register event listener |
void |
release()
Release previously acquired shared object. |
boolean |
removeAttribute(String name)
Removes attribute with given name |
void |
removeAttributes()
Remove all attributes (clear Shared Object) |
protected void |
returnAttributeValue(String name)
Return an attribute value to the owner. |
protected void |
returnError(String message)
Return an error message to the client. |
protected void |
sendMessage(String handler,
List<?> arguments)
Broadcast event to event handler |
protected void |
sendUpdates()
Send update notification over data channel of RTMP connection |
void |
serialize(Output output)
Write the object to the passed output stream. |
boolean |
setAttribute(String name,
Object value)
Set an attribute on this object. |
boolean |
setAttributes(IAttributeStore values)
Set multiple attributes on this object. |
boolean |
setAttributes(Map<String,Object> values)
Set multiple attributes on this object. |
void |
setName(String name)
Set the name of the persistent object. |
void |
setPath(String path)
Set the path of the persistent object. |
void |
setPersistent(boolean persistent)
Set the persistent flag of the object. |
void |
setStore(IPersistenceStore store)
Store a reference to the persistence store in the object. |
protected void |
unregister(IEventListener listener)
Unregister event listener |
Methods inherited from class org.red5.server.AttributeStore |
---|
filterNull, from, getAttribute, getAttributeNames, getAttributes, getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute, hasAttribute, size |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static Logger log
protected String name
protected String path
protected boolean persistent
protected IPersistenceStore storage
protected AtomicInteger version
protected AtomicInteger updateCounter
protected volatile boolean modified
protected long lastModified
protected SharedObjectMessage ownerMessage
protected ConcurrentLinkedQueue<ISharedObjectEvent> syncEvents
protected CopyOnWriteArraySet<IEventListener> listeners
protected IEventListener source
protected AtomicInteger acquireCount
protected StatisticsCounter listenerStats
protected AtomicInteger changeStats
protected AtomicInteger deleteStats
protected AtomicInteger sendStats
Constructor Detail |
---|
public SharedObject()
public SharedObject(Input input) throws IOException
input
- Input source
IOException
- I/O exceptionInput
public SharedObject(String name, String path, boolean persistent)
name
- SO namepath
- SO pathpersistent
- SO persistencepublic SharedObject(String name, String path, boolean persistent, IPersistenceStore storage)
name
- SO namepath
- SO pathpersistent
- SO persistencestorage
- Persistence storagepublic SharedObject(Map<String,Object> data, String name, String path, boolean persistent)
data
- Dataname
- SO namepath
- SO pathpersistent
- SO persistencepublic SharedObject(Map<String,Object> data, String name, String path, boolean persistent, IPersistenceStore storage)
data
- Dataname
- SO namepath
- SO pathpersistent
- SO persistencestorage
- Persistence storageMethod Detail |
---|
public String getName()
getName
in interface IPersistable
getName
in interface ISharedObjectStatistics
public void setName(String name)
setName
in interface IPersistable
name
- New object namepublic String getPath()
getPath
in interface IPersistable
public void setPath(String path)
setPath
in interface IPersistable
path
- New persisted object pathpublic String getType()
getType
in interface IPersistable
public long getLastModified()
getLastModified
in interface IPersistable
public boolean isPersistent()
isPersistent
in interface IPersistable
isPersistent
in interface ISharedObjectStatistics
True
if the shared object is persistent, otherwise False
public void setPersistent(boolean persistent)
setPersistent
in interface IPersistable
persistent
- true
if object is persistent, false
otherwiseprotected void sendUpdates()
protected void notifyModified()
protected void returnError(String message)
message
- protected void returnAttributeValue(String name)
name
- public Object getAttribute(String name, Object value)
getAttribute
in interface IAttributeStore
getAttribute
in class AttributeStore
name
- Attribute namevalue
- Value to set if attribute doesn't exist
public boolean setAttribute(String name, Object value)
setAttribute
in interface IAttributeStore
setAttribute
in class AttributeStore
name
- the name of the attribute to changevalue
- the new value of the attribute
public boolean setAttributes(Map<String,Object> values)
setAttributes
in interface IAttributeStore
setAttributes
in class AttributeStore
values
- the attributes to set
public boolean setAttributes(IAttributeStore values)
setAttributes
in interface IAttributeStore
setAttributes
in class AttributeStore
values
- the attributes to set
public boolean removeAttribute(String name)
removeAttribute
in interface IAttributeStore
removeAttribute
in interface AttributeStoreMXBean
removeAttribute
in class AttributeStore
name
- Attribute
true
if there's such an attribute and it was removed, false
otherwiseprotected void sendMessage(String handler, List<?> arguments)
handler
- Event handlerarguments
- Argumentspublic Map<String,Object> getData()
public int getVersion()
getVersion
in interface ISharedObjectStatistics
public void removeAttributes()
removeAttributes
in interface IAttributeStore
removeAttributes
in interface AttributeStoreMXBean
removeAttributes
in class AttributeStore
protected boolean register(IEventListener listener)
listener
- Event listener
protected void unregister(IEventListener listener)
listener
- Event listenerprotected void checkRelease()
public Set<IEventListener> getListeners()
protected void beginUpdate()
protected void beginUpdate(IEventListener listener)
listener
- Update with listenerprotected void endUpdate()
public void serialize(Output output) throws IOException
serialize
in interface IPersistable
output
- Output stream to write to
IOException
- Any I/O exceptionpublic void deserialize(Input input) throws IOException
deserialize
in interface IPersistable
input
- Input stream to load from
IOException
- Any I/O exceptionpublic void setStore(IPersistenceStore store)
setStore
in interface IPersistable
store
- Store the object is saved inpublic IPersistenceStore getStore()
getStore
in interface IPersistable
protected boolean clear()
true
on success, false
otherwiseprotected void close()
public void acquire()
acquire
must be paired with a call to release
so the SO isn't held
forever. This is only valid for non-persistent SOs.
public boolean isAcquired()
true
if the SO is acquired, otherwise false
public void release()
public long getCreationTime()
getCreationTime
in interface IStatisticsBase
public int getTotalListeners()
getTotalListeners
in interface ISharedObjectStatistics
public int getMaxListeners()
getMaxListeners
in interface ISharedObjectStatistics
public int getActiveListeners()
getActiveListeners
in interface ISharedObjectStatistics
public int getTotalChanges()
getTotalChanges
in interface ISharedObjectStatistics
public int getTotalDeletes()
getTotalDeletes
in interface ISharedObjectStatistics
public int getTotalSends()
getTotalSends
in interface ISharedObjectStatistics
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |