Class SharedObjectScope

java.lang.Object
org.red5.server.scope.BasicScope
org.red5.server.so.SharedObjectScope
All Implemented Interfaces:
Comparable<BasicScope>, 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 Details

  • Constructor Details

    • 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 Details

    • 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 no-op 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
    • isLocked

      @Deprecated public boolean isLocked()
      Deprecated.
      This is no longer supported and is only here to prevent issues at runtime for those implementing the call.
      Returns:
      false
    • setDirty

      @Deprecated public void setDirty(boolean dirty)
      Deprecated.
      Sets a "dirty" flag to indicate that the attributes have been modified.
      Specified by:
      setDirty in interface ISharedObject
      Parameters:
      dirty - if dirty / modified
    • setDirty

      public void setDirty(String name)
      Sets a "dirty" flag to indicate that the named attribute has been modified.
      Specified by:
      setDirty in interface ISharedObject
      Parameters:
      name - attribute key which is now dirty
    • 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
    • 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
    • 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 AttributeStoreMXBean
      Specified by:
      removeAttribute in interface IAttributeStore
      Parameters:
      name - the name of the attribute to remove
      Returns:
      true if the attribute was found and removed otherwise false
    • removeAttribute

      public boolean removeAttribute(Enum<?> enm)
      Description copied from interface: IAttributeStore
      Remove an attribute.
      Specified by:
      removeAttribute in interface IAttributeStore
      Parameters:
      enm - the enum 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 AttributeStoreMXBean
      Specified by:
      removeAttributes in interface IAttributeStore
    • size

      public int size()
      Size of the attribute store.
      Specified by:
      size in interface IAttributeStore
      Returns:
      count of attributes
    • addEventListener

      public boolean 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
      Returns:
      true if listener is added and false otherwise
    • removeEventListener

      public boolean 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
      Returns:
      true if listener is removed and false otherwise
    • hasAttribute

      public boolean hasAttribute(String name)
      Check the object has an attribute.
      Specified by:
      hasAttribute in interface AttributeStoreMXBean
      Specified by:
      hasAttribute in interface IAttributeStore
      Parameters:
      name - the name of the attribute to check
      Returns:
      true if the attribute exists otherwise false
    • hasAttribute

      public boolean hasAttribute(Enum<?> enm)
      Description copied from interface: IAttributeStore
      Check the object has an attribute.
      Specified by:
      hasAttribute in interface IAttributeStore
      Parameters:
      enm - the enum for 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(Enum<?> enm)
      Description copied from interface: IAttributeStore
      Return the value for a given attribute.
      Specified by:
      getAttribute in interface IAttributeStore
      Parameters:
      enm - the enum for 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 AttributeStoreMXBean
      Specified by:
      getAttributeNames in interface IAttributeStore
      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
    • setAttribute

      public boolean setAttribute(Enum<?> enm, Object value)
      Description copied from interface: IAttributeStore
      Set an attribute on this object.
      Specified by:
      setAttribute in interface IAttributeStore
      Parameters:
      enm - the enum of the attribute to change
      value - the new value of the attribute
      Returns:
      true if the attribute value was added or 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
    • 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
    • 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
    • getStatistics

      public ISharedObjectStatistics getStatistics()
      Return statistics about the shared object.
      Specified by:
      getStatistics in interface ISharedObject
      Returns:
      statistics
    • toString

      public String toString()
      Overrides:
      toString in class Object