org.red5.server.so
Class SharedObjectScope

java.lang.Object
  extended by org.red5.server.scope.BasicScope
      extended by org.red5.server.so.SharedObjectScope
All Implemented Interfaces:
IEventDispatcher, IEventHandler, IEventListener, IEventObservable, IAttributeStore, ICastingAttributeStore, ICoreObject, IBasicScope, IScopeService, IServiceHandlerProvider, ISharedObject, ISharedObjectBase, ISharedObjectHandlerProvider, ISharedObjectSecurityService, AttributeStoreMXBean, StatusCodes

public class SharedObjectScope
extends BasicScope
implements ISharedObject, StatusCodes

Special scope for shared objects


Field Summary
protected  SharedObject so
          Scoped shared object
 
Fields inherited from class org.red5.server.scope.BasicScope
keepDelay, keepOnDisconnect, listeners, name, parent, persistenceClass, persistent, store, type
 
Fields inherited from interface org.red5.server.api.so.ISharedObjectSecurityService
BEAN_NAME
 
Fields inherited from interface org.red5.server.net.rtmp.status.StatusCodes
APP_GC, APP_RESOURCE_LOWMEMORY, APP_SCRIPT_ERROR, APP_SCRIPT_WARNING, APP_SHUTDOWN, NC_CALL_BADVERSION, NC_CALL_FAILED, NC_CONNECT_APPSHUTDOWN, NC_CONNECT_CLOSED, NC_CONNECT_FAILED, NC_CONNECT_INVALID_APPLICATION, NC_CONNECT_REJECTED, NC_CONNECT_SUCCESS, NS_BUFFER_EMPTY, NS_CLEAR_FAILED, NS_CLEAR_SUCCESS, NS_DATA_START, NS_FAILED, NS_INVALID_ARGUMENT, NS_PAUSE_NOTIFY, NS_PLAY_COMPLETE, NS_PLAY_FAILED, NS_PLAY_FILE_STRUCTURE_INVALID, NS_PLAY_INSUFFICIENT_BW, NS_PLAY_NO_SUPPORTED_TRACK_FOUND, NS_PLAY_PUBLISHNOTIFY, NS_PLAY_RESET, NS_PLAY_START, NS_PLAY_STOP, NS_PLAY_STREAMNOTFOUND, NS_PLAY_SWITCH, NS_PLAY_TRANSITION, NS_PLAY_TRANSITION_COMPLETE, NS_PLAY_UNPUBLISHNOTIFY, NS_PUBLISH_BADNAME, NS_PUBLISH_START, NS_RECORD_FAILED, NS_RECORD_NOACCESS, NS_RECORD_START, NS_RECORD_STOP, NS_SEEK_FAILED, NS_SEEK_NOTIFY, NS_TRANSITION_FORCED, NS_TRANSITION_SUCCESS, NS_UNPAUSE_NOTIFY, NS_UNPUBLISHED_SUCCESS, SO_CREATION_FAILED, SO_NO_READ_ACCESS, SO_NO_WRITE_ACCESS, SO_PERSISTENCE_MISMATCH
 
Constructor Summary
SharedObjectScope(IScope parent, String name, boolean persistent, IPersistenceStore store)
          Creates shared object with given parent scope, name, persistence flag state and store object
 
Method Summary
 void acquire()
          Prevent shared object from being released.
 void addEventListener(IEventListener listener)
          Add event listener to list of notified objects
 void addSharedObjectListener(ISharedObjectListener listener)
          Register object that will be notified about update events.
 void beginUpdate()
          Start performing multiple updates to the shared object from serverside code.
 void beginUpdate(IEventListener listener)
          Start performing multiple updates to the shared object from a connected client.
 boolean clear()
          Deletes all the attributes and sends a clear event to all listeners.
 void close()
          Detaches a reference from this shared object, this will destroy the reference immediately.
 void dispatchEvent(IEvent e)
          Dispatches event (notifies all listeners)
 void endUpdate()
          The multiple updates are complete, notify clients about all changes at once.
 Object getAttribute(String name)
          Return the value for a given attribute.
 Object getAttribute(String name, Object value)
          Return the value for a given attribute and set it if it doesn't exist.
 Set<String> getAttributeNames()
          Get the attribute names.
 Map<String,Object> getAttributes()
          Get the attributes.
 Boolean getBoolAttribute(String name)
          Get Boolean attribute by name
 Byte getByteAttribute(String name)
          Get Byte attribute by name
 Map<String,Object> getData()
          Return a map containing all attributes of the shared object.
 Double getDoubleAttribute(String name)
          Get Double attribute by name
 Integer getIntAttribute(String name)
          Get Integer attribute by name
 List<?> getListAttribute(String name)
          Get List attribute by name
 Long getLongAttribute(String name)
          Get boolean attribute by name
 Map<?,?> getMapAttribute(String name)
          Get Long attribute by name
 String getName()
          Get the name of this scope.
 String getPath()
          Get the full absolute path.
 Object getServiceHandler(String name)
          Return a previously registered service handler.
 Set<String> getServiceHandlerNames()
          Get list of registered service handler names.
 Set<?> getSetAttribute(String name)
          Get Set attribute by name
 Set<ISharedObjectSecurity> getSharedObjectSecurity()
          Get handlers that protect shared objects.
 Short getShortAttribute(String name)
          Get Short attribute by name
 ISharedObjectStatistics getStatistics()
          Return statistics about the shared object.
 IPersistenceStore getStore()
          Get the persistable store
 String getStringAttribute(String name)
          Get String attribute by name
 int getVersion()
          Returns the version of the shared object.
 boolean hasAttribute(String name)
          Check the object has an attribute.
 boolean isAcquired()
          Check if shared object currently is acquired.
protected  boolean isConnectionAllowed()
          Call handlers and check if connection to the existing SO is allowed.
protected  boolean isDeleteAllowed(String key)
          Call handlers and check if deleting a property from the SO is allowed.
 boolean isLocked()
          Returns the locked state of this SharedObject.
 boolean isPersistent()
          Check if the object has been created as persistent shared object by the client.
protected  boolean isSendAllowed(String message, List<?> arguments)
          Call handlers and check if sending a message to the clients connected to the SO is allowed.
protected  boolean isWriteAllowed(String key, Object value)
          Call handlers and check if writing to the SO is allowed.
 void lock()
          Locks the shared object instance.
 void registerServiceHandler(Object handler)
          Register an object that provides methods which handle calls without a service name to a shared object.
 void registerServiceHandler(String name, Object handler)
          Register an object that provides methods which can be called from a client.
 void registerSharedObjectSecurity(ISharedObjectSecurity handler)
          Add handler that protects shared objects.
 void release()
          Release previously acquired shared object.
 boolean removeAttribute(String name)
          Remove an attribute.
 void removeAttributes()
          Remove all attributes.
 void removeEventListener(IEventListener listener)
          Remove event listener from list of listeners
 void removeSharedObjectListener(ISharedObjectListener listener)
          Unregister object to not longer receive update events.
 void sendMessage(String handler, List<?> arguments)
          Send a message to a handler of the shared object.
 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 setPath(String path)
           
 int size()
          Size of the attribute store.
 String toString()
          
 void unlock()
          Unlocks a shared object instance that was locked with SharedObject.lock().
 void unregisterServiceHandler()
           
 void unregisterServiceHandler(String name)
          Unregister the shared object handler for calls without a service name.
 void unregisterSharedObjectSecurity(ISharedObjectSecurity handler)
          Remove handler that protects shared objects.
 
Methods inherited from class org.red5.server.scope.BasicScope
equals, getDepth, getEventListeners, getParent, getType, handleEvent, hasEventListeners, hashCode, hasParent, isValid, notifyEvent, setKeepDelay
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.red5.server.api.scope.IBasicScope
getDepth, getParent, getType, hasParent, isValid, setKeepDelay
 
Methods inherited from interface org.red5.server.api.event.IEventHandler
handleEvent
 
Methods inherited from interface org.red5.server.api.event.IEventListener
notifyEvent
 
Methods inherited from interface org.red5.server.api.event.IEventObservable
getEventListeners
 

Field Detail

so

protected volatile SharedObject so
Scoped shared object

Constructor Detail

SharedObjectScope

public SharedObjectScope(IScope parent,
                         String name,
                         boolean persistent,
                         IPersistenceStore store)
Creates shared object with given parent scope, name, persistence flag state and store object

Parameters:
parent - Parent scope
name - Name
persistent - Persistence flag state
store - Persistence store
Method Detail

registerSharedObjectSecurity

public void registerSharedObjectSecurity(ISharedObjectSecurity handler)
Add handler that protects shared objects.

Specified by:
registerSharedObjectSecurity in interface ISharedObjectSecurityService
Parameters:
handler - Handler to add.

unregisterSharedObjectSecurity

public void unregisterSharedObjectSecurity(ISharedObjectSecurity handler)
Remove handler that protects shared objects.

Specified by:
unregisterSharedObjectSecurity in interface ISharedObjectSecurityService
Parameters:
handler - Handler to remove.

getSharedObjectSecurity

public Set<ISharedObjectSecurity> getSharedObjectSecurity()
Get handlers that protect shared objects.

Specified by:
getSharedObjectSecurity in interface ISharedObjectSecurityService
Returns:
list of handlers

getStore

public IPersistenceStore getStore()
Get the persistable store

Specified by:
getStore in interface IBasicScope
Overrides:
getStore in class BasicScope
Returns:
the store

getName

public String getName()
Get the name of this scope. Eg. someroom.

Specified by:
getName in interface IBasicScope
Overrides:
getName in class BasicScope
Returns:
the name

getPath

public String getPath()
Get the full absolute path. Eg. host/myapp/someroom.

Specified by:
getPath in interface IBasicScope
Overrides:
getPath in class BasicScope
Returns:
Absolute scope path

setPath

public void setPath(String path)

isPersistent

public boolean isPersistent()
Check if the object has been created as persistent shared object by the client.

Specified by:
isPersistent in interface ISharedObjectBase
Returns:
true if the shared object is persistent, false otherwise

beginUpdate

public void beginUpdate()
Start performing multiple updates to the shared object from serverside code.

Specified by:
beginUpdate in interface ISharedObjectBase

beginUpdate

public void beginUpdate(IEventListener listener)
Start performing multiple updates to the shared object from a connected client.

Specified by:
beginUpdate in interface ISharedObjectBase
Parameters:
listener - Update events listener

endUpdate

public void endUpdate()
The multiple updates are complete, notify clients about all changes at once.

Specified by:
endUpdate in interface ISharedObjectBase

getVersion

public int getVersion()
Returns the version of the shared object. The version is incremented automatically on each modification.

Specified by:
getVersion in interface ISharedObjectBase
Returns:
the version of the shared object

sendMessage

public void sendMessage(String handler,
                        List<?> arguments)
Send a message to a handler of the shared object.

Specified by:
sendMessage in interface ISharedObjectBase
Parameters:
handler - the name of the handler to call
arguments - a list of objects that should be passed as arguments to the handler

removeAttribute

public boolean removeAttribute(String name)
Remove an attribute.

Specified by:
removeAttribute in interface IAttributeStore
Specified by:
removeAttribute in interface AttributeStoreMXBean
Parameters:
name - the name of the attribute to remove
Returns:
true if the attribute was found and removed otherwise false

removeAttributes

public void removeAttributes()
Remove all attributes.

Specified by:
removeAttributes in interface IAttributeStore
Specified by:
removeAttributes in interface AttributeStoreMXBean

size

public int size()
Size of the attribute store.

Specified by:
size in interface IAttributeStore
Returns:
count of attributes

addEventListener

public void addEventListener(IEventListener listener)
Add event listener to list of notified objects

Specified by:
addEventListener in interface IEventObservable
Overrides:
addEventListener in class BasicScope
Parameters:
listener - Listening object

removeEventListener

public void removeEventListener(IEventListener listener)
Remove event listener from list of listeners

Specified by:
removeEventListener in interface IEventObservable
Overrides:
removeEventListener in class BasicScope
Parameters:
listener - Listener to remove

hasAttribute

public boolean hasAttribute(String name)
Check the object has an attribute.

Specified by:
hasAttribute in interface IAttributeStore
Specified by:
hasAttribute in interface AttributeStoreMXBean
Parameters:
name - the name of the attribute to check
Returns:
true if the attribute exists otherwise false

getAttribute

public Object getAttribute(String name)
Return the value for a given attribute.

Specified by:
getAttribute in interface IAttributeStore
Parameters:
name - the name of the attribute to get
Returns:
the attribute value or null if the attribute doesn't exist

getAttribute

public Object getAttribute(String name,
                           Object value)
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:
getAttribute in interface IAttributeStore
Parameters:
name - the name of the attribute to get
value - the value of the attribute to set if the attribute doesn't exist
Returns:
the attribute value

getAttributes

public Map<String,Object> getAttributes()
Get the attributes. The resulting map will be read-only.

Specified by:
getAttributes in interface IAttributeStore
Returns:
map containing all attributes

getAttributeNames

public Set<String> getAttributeNames()
Get the attribute names. The resulting set will be read-only.

Specified by:
getAttributeNames in interface IAttributeStore
Specified by:
getAttributeNames in interface AttributeStoreMXBean
Returns:
set containing all attribute names

getBoolAttribute

public Boolean getBoolAttribute(String name)
Get Boolean attribute by name

Specified by:
getBoolAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getByteAttribute

public Byte getByteAttribute(String name)
Get Byte attribute by name

Specified by:
getByteAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getDoubleAttribute

public Double getDoubleAttribute(String name)
Get Double attribute by name

Specified by:
getDoubleAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getIntAttribute

public Integer getIntAttribute(String name)
Get Integer attribute by name

Specified by:
getIntAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getListAttribute

public List<?> getListAttribute(String name)
Get List attribute by name

Specified by:
getListAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getLongAttribute

public Long getLongAttribute(String name)
Get boolean attribute by name

Specified by:
getLongAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getMapAttribute

public Map<?,?> getMapAttribute(String name)
Get Long attribute by name

Specified by:
getMapAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getSetAttribute

public Set<?> getSetAttribute(String name)
Get Set attribute by name

Specified by:
getSetAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getShortAttribute

public Short getShortAttribute(String name)
Get Short attribute by name

Specified by:
getShortAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getStringAttribute

public String getStringAttribute(String name)
Get String attribute by name

Specified by:
getStringAttribute in interface ICastingAttributeStore
Parameters:
name - Attribute name
Returns:
Attribute

getData

public Map<String,Object> getData()
Return a map containing all attributes of the shared object.
NOTE: The returned map will be read-only.

Specified by:
getData in interface ISharedObjectBase
Returns:
a map containing all attributes of the shared object

isConnectionAllowed

protected boolean isConnectionAllowed()
Call handlers and check if connection to the existing SO is allowed.

Returns:
is connection allowed

isWriteAllowed

protected boolean isWriteAllowed(String key,
                                 Object value)
Call handlers and check if writing to the SO is allowed.

Parameters:
key - key
value - value
Returns:
is write allowed

isDeleteAllowed

protected boolean isDeleteAllowed(String key)
Call handlers and check if deleting a property from the SO is allowed.

Parameters:
key - key
Returns:
is delete allowed

isSendAllowed

protected boolean isSendAllowed(String message,
                                List<?> arguments)
Call handlers and check if sending a message to the clients connected to the SO is allowed.

Parameters:
message - message
arguments - arguments
Returns:
is send allowed

dispatchEvent

public void dispatchEvent(IEvent e)
Dispatches event (notifies all listeners)

Specified by:
dispatchEvent in interface IEventDispatcher
Overrides:
dispatchEvent in class BasicScope
Parameters:
e - Event to dispatch

setAttribute

public boolean setAttribute(String name,
                            Object value)
Set an attribute on this object.

Specified by:
setAttribute in interface IAttributeStore
Parameters:
name - the name of the attribute to change
value - the new value of the attribute
Returns:
true if the attribute value changed otherwise false

setAttributes

public boolean setAttributes(IAttributeStore values)
Set multiple attributes on this object.

Specified by:
setAttributes in interface IAttributeStore
Parameters:
values - the attributes to set
Returns:
true if the attribute values changed otherwise false

setAttributes

public boolean setAttributes(Map<String,Object> values)
Set multiple attributes on this object.

Specified by:
setAttributes in interface IAttributeStore
Parameters:
values - the attributes to set
Returns:
true if the attribute values changed otherwise false

toString

public String toString()

Overrides:
toString in class Object

addSharedObjectListener

public void addSharedObjectListener(ISharedObjectListener listener)
Register object that will be notified about update events.

Specified by:
addSharedObjectListener in interface ISharedObjectBase
Parameters:
listener - the object to notify

removeSharedObjectListener

public void removeSharedObjectListener(ISharedObjectListener listener)
Unregister object to not longer receive update events.

Specified by:
removeSharedObjectListener in interface ISharedObjectBase
Parameters:
listener - the object to unregister

registerServiceHandler

public void registerServiceHandler(Object handler)
Register an object that provides methods which handle calls without a service name to a shared object.

Specified by:
registerServiceHandler in interface ISharedObjectHandlerProvider
Parameters:
handler - the handler object

registerServiceHandler

public void registerServiceHandler(String name,
                                   Object handler)
Register an object that provides methods which can be called from a client.

Example:
If you registered a handler with the name "one.two" that provides a method "callMe", you can call a method "one.two.callMe" from the client.

Specified by:
registerServiceHandler in interface IServiceHandlerProvider
Parameters:
name - the name of the handler
handler - the handler object

unregisterServiceHandler

public void unregisterServiceHandler()

unregisterServiceHandler

public void unregisterServiceHandler(String name)
Unregister the shared object handler for calls without a service name.

Specified by:
unregisterServiceHandler in interface IServiceHandlerProvider
Specified by:
unregisterServiceHandler in interface ISharedObjectHandlerProvider
Parameters:
name - the name of the handler

getServiceHandler

public Object getServiceHandler(String name)
Return a previously registered service handler.

Specified by:
getServiceHandler in interface IServiceHandlerProvider
Parameters:
name - the name of the handler to return
Returns:
the previously registered handler

getServiceHandlerNames

public Set<String> getServiceHandlerNames()
Get list of registered service handler names.

Specified by:
getServiceHandlerNames in interface IServiceHandlerProvider
Returns:
the names of the registered handlers

lock

public void lock()
Locks the shared object instance. Prevents any changes to this object by clients until the SharedObject.unlock() method is called.

Specified by:
lock in interface ISharedObjectBase

unlock

public void unlock()
Unlocks a shared object instance that was locked with SharedObject.lock().

Specified by:
unlock in interface ISharedObjectBase

isLocked

public boolean isLocked()
Returns the locked state of this SharedObject.

Specified by:
isLocked in interface ISharedObjectBase
Returns:
true if in a locked state; false otherwise

clear

public 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.

Specified by:
clear in interface ISharedObjectBase
Returns:
true if successful; false otherwise

close

public void close()
Detaches a reference from this shared object, this will destroy the reference immediately. This is useful when you don't want to proxy a shared object any longer.

Specified by:
close in interface ISharedObjectBase

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 method basically is a noop for persistent SOs as their data is stored and they can be released without losing their contents.

Specified by:
acquire in interface ISharedObject

isAcquired

public boolean isAcquired()
Check if shared object currently is acquired.

Specified by:
isAcquired in interface ISharedObject
Returns:
true if the SO is acquired, otherwise false

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.

Specified by:
release in interface ISharedObject

getStatistics

public ISharedObjectStatistics getStatistics()
Return statistics about the shared object.

Specified by:
getStatistics in interface ISharedObject
Returns:
statistics


Copyright © 2006-2012 The Red5 Project