|
||||||||||
| 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 Set<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 boolean |
persistentSO
true if the client / server created the SO to be persistent |
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 |
|
| 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()
Returns true if the object is persistent,
false otherwise. |
boolean |
isPersistentObject()
Getter for persistent object |
protected void |
notifyModified()
Send notification about modification of SO |
protected void |
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 value of attribute with given name |
void |
setAttributes(IAttributeStore values)
Set attributes as attributes store. |
void |
setAttributes(Map<String,Object> values)
Set attributes as map. |
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, getAttribute, getAttributeNames, getAttributes, getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute, hasAttribute |
| 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 boolean persistentSO
protected IPersistenceStore storage
protected AtomicInteger version
protected AtomicInteger updateCounter
protected boolean modified
protected long lastModified
protected SharedObjectMessage ownerMessage
protected ConcurrentLinkedQueue<ISharedObjectEvent> syncEvents
protected Set<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(Map<String,Object> data,
String name,
String path,
boolean persistent)
data - Dataname - SO namepath - SO pathpersistent - SO persistence
public SharedObject(Map<String,Object> data,
String name,
String path,
boolean persistent,
IPersistenceStore storage)
data - Dataname - SO namepath - SO pathpersistent - SO persistencestorage - Persistence storage| Method Detail |
|---|
public String getName()
getName in interface IPersistablegetName in interface ISharedObjectStatisticspublic void setName(String name)
setName in interface IPersistablename - New object namepublic String getPath()
getPath in interface IPersistablepublic void setPath(String path)
setPath in interface IPersistablepath - New persisted object pathpublic String getType()
getType in interface IPersistablepublic long getLastModified()
getLastModified in interface IPersistablepublic boolean isPersistentObject()
isPersistentObject in interface ISharedObjectStatisticspublic boolean isPersistent()
true if the object is persistent,
false otherwise.
isPersistent in interface IPersistabletrue if object is persistent, false otherwisepublic void setPersistent(boolean persistent)
setPersistent in interface IPersistablepersistent - 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 AttributeStoreMBeangetAttribute in interface IAttributeStoregetAttribute in class AttributeStorename - Attribute namevalue - Value to set if attribute doesn't exist
public boolean setAttribute(String name,
Object value)
setAttribute in interface AttributeStoreMBeansetAttribute in interface IAttributeStoresetAttribute in class AttributeStorename - Attribute namevalue - Attribute value
true if there's such attribute and value was set, false otherwisepublic void setAttributes(Map<String,Object> values)
setAttributes in interface IAttributeStoresetAttributes in class AttributeStorevalues - Attributes.public void setAttributes(IAttributeStore values)
setAttributes in interface IAttributeStoresetAttributes in class AttributeStorevalues - Attributes.public boolean removeAttribute(String name)
removeAttribute in interface AttributeStoreMBeanremoveAttribute in interface IAttributeStoreremoveAttribute in class AttributeStorename - Attribute
true if there's such an attribute and it was removed, false otherwise
protected void sendMessage(String handler,
List<?> arguments)
handler - Event handlerarguments - Argumentspublic Map<String,Object> getData()
public int getVersion()
getVersion in interface ISharedObjectStatisticspublic void removeAttributes()
removeAttributes in interface AttributeStoreMBeanremoveAttributes in interface IAttributeStoreremoveAttributes in class AttributeStoreprotected void register(IEventListener listener)
listener - Event listenerprotected void checkRelease()
protected void unregister(IEventListener listener)
listener - Event listenerpublic 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 IPersistableoutput - Output stream to write to
IOException - Any I/O exception
public void deserialize(Input input)
throws IOException
deserialize in interface IPersistableinput - Input stream to load from
IOException - Any I/O exceptionpublic void setStore(IPersistenceStore store)
setStore in interface IPersistablestore - Store the object is saved inpublic IPersistenceStore getStore()
getStore in interface IPersistableprotected 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 falsepublic void release()
public long getCreationTime()
getCreationTime in interface IStatisticsBasepublic int getTotalListeners()
getTotalListeners in interface ISharedObjectStatisticspublic int getMaxListeners()
getMaxListeners in interface ISharedObjectStatisticspublic int getActiveListeners()
getActiveListeners in interface ISharedObjectStatisticspublic int getTotalChanges()
getTotalChanges in interface ISharedObjectStatisticspublic int getTotalDeletes()
getTotalDeletes in interface ISharedObjectStatisticspublic int getTotalSends()
getTotalSends in interface ISharedObjectStatistics
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||