Package org.red5.server.scope
Class Scope
java.lang.Object
org.red5.server.scope.BasicScope
org.red5.server.scope.Scope
- All Implemented Interfaces:
Comparable<BasicScope>
,IEventDispatcher
,IEventHandler
,IEventListener
,IEventObservable
,ICoreObject
,IBasicScope
,IScope
,IServiceHandlerProvider
,IScopeStatistics
,IStatisticsBase
,ScopeMXBean
,ResourceLoader
,ResourcePatternResolver
- Direct Known Subclasses:
GlobalScope
,RoomScope
,WebScope
@ManagedResource(objectName="org.red5.server:type=Scope",
description="Scope")
public class Scope
extends BasicScope
implements IScope, IScopeStatistics, ScopeMXBean
The scope object.
A stateful object shared between a group of clients connected to the same context path. Scopes are arranged in a hierarchical way, so a scope always has a parent unless its a "global" scope. If a client is connected to a scope then they are also connected to its parent scope. The scope object is used to access resources, shared object, streams, etc.
Scope layout:
A stateful object shared between a group of clients connected to the same context path. Scopes are arranged in a hierarchical way, so a scope always has a parent unless its a "global" scope. If a client is connected to a scope then they are also connected to its parent scope. The scope object is used to access resources, shared object, streams, etc.
Scope layout:
/Global scope - Contains application scopes /Application scope - Contains room, shared object, and stream scopes /Room scope - Contains other room, shared object, and / or stream scopes /Shared object scope - Contains shared object /Broadcast stream scope - Contains a broadcast stream
- Author:
- The Red5 Project, Paul Gregoire (mondain@gmail.com), Nathan Smith (nathgs@gmail.com)
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
Builder patternprivate final class
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AttributeStore
Storage for scope attributesprivate boolean
Auto-start flagprivate final Scope.ConcurrentScopeSet
Child scopesprivate final CopyOnWriteArraySet<IClient>
Connected clients mapprotected final StatisticsCounter
Statistics about connections to the scope.private IContext
Scope contextprivate long
Timestamp the scope was created.private int
Scope nesting depth, unset by defaultprivate boolean
Whether scope is enabledprivate IScopeHandler
Scope handlerprotected static org.slf4j.Logger
protected ObjectName
Mbean object name.private boolean
Whether scope is runningprivate ConcurrentMap<String,
Object> Registered service handlers for this scope.protected final StatisticsCounter
Statistics about sub-scopes.private static final int
Unset flag constantFields inherited from class org.red5.server.scope.BasicScope
creation, keepDelay, keepOnDisconnect, listeners, name, parent, persistenceClass, persistent, securityHandlers, store, type
Fields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIX
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX
-
Constructor Summary
ConstructorDescriptionScope()
Creates a scopeScope
(Scope.Builder builder) Creates scope using a Builder -
Method Summary
Modifier and TypeMethodDescriptionboolean
addChildScope
(IBasicScope scope) Add child scope to this scopeboolean
connect
(IConnection conn) Connect to scopeboolean
connect
(IConnection conn, Object[] params) Connect to scope with parameters.boolean
createChildScope
(String name) Create child scope of room type, with the given name.void
destroy()
Destroys scopevoid
disconnect
(IConnection conn) Disconnect connection from scopevoid
dispatchEvent
(IEvent event) Dispatches event (notifies all listeners)void
dump()
boolean
Equality is based on the scope's name and type.static Scope
from
(CompositeData cd) Allows for reconstruction via CompositeData.int
Return current number of clients connected to the scope.int
Return current number of connections to the scope.int
Return number of currently existing subscopes.getAttribute
(String name) Get attribute by nameReturn attribute namesReturn scope attributesgetBasicScope
(ScopeType type, String name) Return base scope of given type with given namegetBasicScopeNames
(ScopeType type) Return basic scope names matching given typegetBroadcastScope
(String name) Return the broadcast scope for a given nameReturn current thread context classloaderGet all current connections.Return set of clientsDeprecated.Return scope context.Return scope context pathlong
Return the timestamp the object was created.int
getDepth()
return scope depthboolean
Here for JMX only, uses isEnabled()Return scope handler or parent's scope handler if this scope doesn't have one.int
Deprecated.int
Return maximum number of concurrent connections to the scope.int
Return maximum number of concurrently existing subscopes.Return parent scopegetPath()
Return scope path calculated from parent path and parent scope namegetResource
(String path) Return resource located at given pathResource[]
getResources
(String path) Return array of resources from path string, usually used with pattern pathboolean
Here for JMX only, uses isEnabled()Return child scope by nameReturn child scope names iteratorReturn the server instance connected to this scope.getServiceHandler
(String name) Return service handler by nameReturn set of service handler names.Return map of service handlers.getServiceHandlers
(boolean allowCreate) Return map of service handlers and optionally created it if it doesn't exist.Return statistics informations about the scope.int
Deprecated.int
Return total number of connections to the scope.int
Return total number of subscopes created.boolean
handleEvent
(IEvent event) Handles event.boolean
hasAttribute
(String name) Whether or not an attribute exists, keyed by the given nameboolean
hasChildScope
(String name) Check whether scope has child scope with given nameboolean
hasChildScope
(ScopeType type, String name) Check whether scope has child scope with given name and typeboolean
Check if scope has a contextboolean
Check if scope or it's parent has handlerint
hashCode()
Hash code is based on the scope's name and typeboolean
Check if scope has parent scopevoid
init()
Initialization actions, start if autostart is set to true.boolean
Check if scope is enabledboolean
Check if scope is in running statelookupConnection
(IClient client) Lookup connection for a given client.lookupConnections
(IClient client) Deprecated.protected void
void
registerServiceHandler
(String name, Object handler) Register service handler by nameboolean
removeAttribute
(String name) Remove attribute by namevoid
Removes all the child scopesvoid
removeChildScope
(IBasicScope scope) Removes child scopeboolean
setAttribute
(String name, Object value) Set attribute by namevoid
setAutoStart
(boolean autoStart) Setter for autostart flagvoid
setChildLoadPath
(String pattern) Setter for child load path.void
setContext
(IContext context) Setter for contextvoid
setDepth
(int depth) Set scope depthvoid
setEnabled
(boolean enabled) Enable or disable scope by setting enable flagvoid
setHandler
(IScopeHandler handler) Setter for scope event handlerfinal void
Setter for scope namevoid
Setter for parent scopevoid
setPersistenceClass
(String persistenceClass) Set scope persistence classboolean
start()
Starts scopevoid
stop()
Stops scopetoString()
void
uninit()
Uninitialize scope and unregister from parent.protected void
void
Unregisters service handler by nameMethods inherited from class org.red5.server.scope.BasicScope
addEventListener, compareTo, getEventListeners, getName, getStore, getType, hasEventListeners, isConnectionAllowed, isScopeAllowed, isValid, notifyEvent, removeEventListener, setKeepDelay, setSecurityHandlers
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
getName, getStore, getType, isConnectionAllowed, isScopeAllowed, isValid, setKeepDelay, setSecurityHandlers
Methods inherited from interface org.red5.server.api.event.IEventListener
notifyEvent
Methods inherited from interface org.red5.server.api.event.IEventObservable
addEventListener, getEventListeners, removeEventListener
Methods inherited from interface org.red5.server.api.statistics.IScopeStatistics
getName
-
Field Details
-
log
protected static org.slf4j.Logger log -
UNSET
private static final int UNSETUnset flag constant- See Also:
-
creationTime
private long creationTimeTimestamp the scope was created. -
depth
private int depthScope nesting depth, unset by default -
enabled
private boolean enabledWhether scope is enabled -
running
private boolean runningWhether scope is running -
autoStart
private boolean autoStartAuto-start flag -
context
Scope context -
handler
Scope handler -
serviceHandlers
Registered service handlers for this scope. The map is created on-demand only if it's accessed for writing. -
children
Child scopes -
clients
Connected clients map -
connectionStats
Statistics about connections to the scope. -
subscopeStats
Statistics about sub-scopes. -
attributes
Storage for scope attributes -
oName
Mbean object name.
-
-
Constructor Details
-
Scope
Creates a scope -
Scope
Creates scope using a Builder- Parameters:
builder
- Builder
-
-
Method Details
-
addChildScope
Add child scope to this scope- Specified by:
addChildScope
in interfaceIScope
- Parameters:
scope
- Child scope- Returns:
- true on success (if scope has handler and it accepts child scope addition), false otherwise
-
connect
Connect to scope -
connect
Connect to scope with parameters. To successfully connect to scope it must have handler that will accept this connection with given set of parameters. Client associated with connection is added to scope clients set, connection is registered as scope event listener. -
createChildScope
Create child scope of room type, with the given name.- Specified by:
createChildScope
in interfaceIScope
- Specified by:
createChildScope
in interfaceScopeMXBean
- Parameters:
name
- child scope name- Returns:
- true on success, false otherwise
-
destroy
Destroys scope- Specified by:
destroy
in interfaceScopeMXBean
- Throws:
Exception
- on error
-
disconnect
Disconnect connection from scope- Specified by:
disconnect
in interfaceIScope
- Parameters:
conn
- Connection object
-
dispatchEvent
Dispatches event (notifies all listeners)- Specified by:
dispatchEvent
in interfaceIEventDispatcher
- Overrides:
dispatchEvent
in classBasicScope
- Parameters:
event
- Event to dispatch
-
getAttribute
Get attribute by name- Specified by:
getAttribute
in interfaceIScope
- Parameters:
name
- name- Returns:
- value for the given name in the attributes or null if not found
-
setAttribute
Set attribute by name- Specified by:
setAttribute
in interfaceIScope
- Parameters:
name
- namevalue
- value- Returns:
- true if added, false if not added
-
hasAttribute
Whether or not an attribute exists, keyed by the given name- Specified by:
hasAttribute
in interfaceIScope
- Parameters:
name
- name- Returns:
- true if it exists, false otherwise
-
removeAttribute
Remove attribute by name- Specified by:
removeAttribute
in interfaceIScope
- Parameters:
name
- name- Returns:
- true if removed, false otherwise
-
getAttributeNames
Return attribute names- Specified by:
getAttributeNames
in interfaceIScope
- Returns:
- attribute names
-
getAttributes
Return scope attributes- Specified by:
getAttributes
in interfaceIScope
- Returns:
- attributes
-
getActiveClients
public int getActiveClients()Return current number of clients connected to the scope.- Specified by:
getActiveClients
in interfaceIScopeStatistics
- Specified by:
getActiveClients
in interfaceScopeMXBean
- Returns:
- number of clients
-
getActiveConnections
public int getActiveConnections()Return current number of connections to the scope.- Specified by:
getActiveConnections
in interfaceIScopeStatistics
- Specified by:
getActiveConnections
in interfaceScopeMXBean
- Returns:
- number of connections
-
getActiveSubscopes
public int getActiveSubscopes()Return number of currently existing subscopes.- Specified by:
getActiveSubscopes
in interfaceIScopeStatistics
- Specified by:
getActiveSubscopes
in interfaceScopeMXBean
- Returns:
- number of subscopes
-
getBroadcastScope
Return the broadcast scope for a given name- Specified by:
getBroadcastScope
in interfaceIScope
- Parameters:
name
- name- Returns:
- broadcast scope or null if not found
-
getBasicScope
Return base scope of given type with given name- Specified by:
getBasicScope
in interfaceIScope
- Parameters:
type
- Scope typename
- Scope name- Returns:
- Basic scope object
-
getBasicScopeNames
Return basic scope names matching given type- Specified by:
getBasicScopeNames
in interfaceIScope
- Parameters:
type
- Scope type- Returns:
- set of scope names
-
getClassLoader
Return current thread context classloader- Specified by:
getClassLoader
in interfaceResourceLoader
- Returns:
- Current thread context classloader
-
getClients
Return set of clients- Specified by:
getClients
in interfaceIScope
- Returns:
- Set of clients bound to scope
- See Also:
-
getConnections
Deprecated.Get a connection iterator. You can call remove, and the connection will be closed.- Specified by:
getConnections
in interfaceIScope
- Returns:
- Iterator holding all connections
-
getClientConnections
Get all current connections. You can call remove, and the connection will be closed.- Specified by:
getClientConnections
in interfaceIScope
- Returns:
- Set containing all connections
-
lookupConnections
Deprecated.Lookup connections.- Specified by:
lookupConnections
in interfaceIScope
- Parameters:
client
- object- Returns:
- Set of connection objects (read-only)
-
lookupConnection
Lookup connection for a given client.- Specified by:
lookupConnection
in interfaceIScope
- Parameters:
client
- object- Returns:
- connection object
-
getContext
Return scope context. If scope doesn't have context, parent's context is returns, and so forth.- Specified by:
getContext
in interfaceIScope
- Returns:
- Scope context or parent context
-
getContextPath
Return scope context path- Specified by:
getContextPath
in interfaceIScope
- Specified by:
getContextPath
in interfaceScopeMXBean
- Returns:
- Scope context path
-
getCreationTime
public long getCreationTime()Return the timestamp the object was created.- Specified by:
getCreationTime
in interfaceIStatisticsBase
- Returns:
- the timestamp in milliseconds since midnight, January 1, 1970 UTC.
-
getDepth
public int getDepth()return scope depth- Specified by:
getDepth
in interfaceIBasicScope
- Specified by:
getDepth
in interfaceIScopeStatistics
- Specified by:
getDepth
in interfaceScopeMXBean
- Overrides:
getDepth
in classBasicScope
- Returns:
- Scope depth
-
getHandler
Return scope handler or parent's scope handler if this scope doesn't have one.- Specified by:
getHandler
in interfaceIScope
- Returns:
- Scope handler (or parent's one)
-
getMaxClients
Deprecated.Return maximum number of clients concurrently connected to the scope.- Specified by:
getMaxClients
in interfaceIScopeStatistics
- Specified by:
getMaxClients
in interfaceScopeMXBean
- Returns:
- number of clients
-
getMaxConnections
public int getMaxConnections()Return maximum number of concurrent connections to the scope.- Specified by:
getMaxConnections
in interfaceIScopeStatistics
- Specified by:
getMaxConnections
in interfaceScopeMXBean
- Returns:
- number of connections
-
getMaxSubscopes
public int getMaxSubscopes()Return maximum number of concurrently existing subscopes.- Specified by:
getMaxSubscopes
in interfaceIScopeStatistics
- Specified by:
getMaxSubscopes
in interfaceScopeMXBean
- Returns:
- number of subscopes
-
getParent
Return parent scope- Specified by:
getParent
in interfaceIBasicScope
- Overrides:
getParent
in classBasicScope
- Returns:
- Parent scope
-
getPath
Return scope path calculated from parent path and parent scope name- Specified by:
getPath
in interfaceIBasicScope
- Specified by:
getPath
in interfaceIScopeStatistics
- Specified by:
getPath
in interfaceScopeMXBean
- Overrides:
getPath
in classBasicScope
- Returns:
- Scope path
-
getResource
Return resource located at given path- Specified by:
getResource
in interfaceResourceLoader
- Parameters:
path
- Resource path- Returns:
- Resource
-
getResources
Return array of resources from path string, usually used with pattern path- Specified by:
getResources
in interfaceResourcePatternResolver
- Parameters:
path
- Resources path- Returns:
- Resources
- Throws:
IOException
- I/O exception
-
getScope
Return child scope by name -
getScopeNames
Return child scope names iterator- Specified by:
getScopeNames
in interfaceIScope
- Returns:
- Child scope names iterator
-
getServiceHandler
Return service handler by name- Specified by:
getServiceHandler
in interfaceIServiceHandlerProvider
- Parameters:
name
- Handler name- Returns:
- Service handler with given name
-
getServiceHandlerNames
Return set of service handler names. Removing entries from the set unregisters the corresponding service handler.- Specified by:
getServiceHandlerNames
in interfaceIServiceHandlerProvider
- Specified by:
getServiceHandlerNames
in interfaceScopeMXBean
- Returns:
- Set of service handler names
-
getServiceHandlers
Return map of service handlers. The map is created if it doesn't exist yet.- Returns:
- Map of service handlers
-
getServiceHandlers
Return map of service handlers and optionally created it if it doesn't exist.- Parameters:
allowCreate
- Should the map be created if it doesn't exist?- Returns:
- Map of service handlers
-
getStatistics
Return statistics informations about the scope.- Specified by:
getStatistics
in interfaceIScope
- Returns:
- statistics
-
getTotalClients
Deprecated.Return total number of clients connected to the scope.- Specified by:
getTotalClients
in interfaceIScopeStatistics
- Specified by:
getTotalClients
in interfaceScopeMXBean
- Returns:
- number of clients
-
getTotalConnections
public int getTotalConnections()Return total number of connections to the scope.- Specified by:
getTotalConnections
in interfaceIScopeStatistics
- Specified by:
getTotalConnections
in interfaceScopeMXBean
- Returns:
- number of connections
-
getTotalSubscopes
public int getTotalSubscopes()Return total number of subscopes created.- Specified by:
getTotalSubscopes
in interfaceIScopeStatistics
- Specified by:
getTotalSubscopes
in interfaceScopeMXBean
- Returns:
- number of subscopes created
-
handleEvent
Handles event. To be implemented in subclasses.- Specified by:
handleEvent
in interfaceIEventHandler
- Overrides:
handleEvent
in classBasicScope
- Parameters:
event
- Event to handle- Returns:
- true on success, false otherwise
-
hasChildScope
Check whether scope has child scope with given name- Specified by:
hasChildScope
in interfaceIScope
- Specified by:
hasChildScope
in interfaceScopeMXBean
- Parameters:
name
- Child scope name- Returns:
- true if scope has child node with given name, false otherwise
-
hasChildScope
Check whether scope has child scope with given name and type- Specified by:
hasChildScope
in interfaceIScope
- Specified by:
hasChildScope
in interfaceScopeMXBean
- Parameters:
type
- Child scope typename
- Child scope name- Returns:
- true if scope has child node with given name and type, false otherwise
-
hasContext
public boolean hasContext()Check if scope has a context- Specified by:
hasContext
in interfaceScopeMXBean
- Returns:
- true if scope has context, false otherwise
-
hasHandler
public boolean hasHandler()Check if scope or it's parent has handler- Specified by:
hasHandler
in interfaceIScope
- Specified by:
hasHandler
in interfaceScopeMXBean
- Returns:
- true if scope or it's parent scope has a handler, false otherwise
-
hasParent
public boolean hasParent()Check if scope has parent scope- Specified by:
hasParent
in interfaceIBasicScope
- Specified by:
hasParent
in interfaceScopeMXBean
- Overrides:
hasParent
in classBasicScope
- Returns:
- true if scope has parent scope, false otherwise`
-
init
public void init()Initialization actions, start if autostart is set to true.- Specified by:
init
in interfaceScopeMXBean
-
uninit
public void uninit()Uninitialize scope and unregister from parent. -
isEnabled
public boolean isEnabled()Check if scope is enabled- Returns:
- true if scope is enabled, false otherwise
-
getEnabled
public boolean getEnabled()Here for JMX only, uses isEnabled()- Specified by:
getEnabled
in interfaceScopeMXBean
- Returns:
true
if scope is enabled,false
otherwise
-
isRunning
public boolean isRunning()Check if scope is in running state- Returns:
- true if scope is in running state, false otherwise
-
getRunning
public boolean getRunning()Here for JMX only, uses isEnabled()- Specified by:
getRunning
in interfaceScopeMXBean
- Returns:
true
if scope is in running state,false
otherwise
-
registerServiceHandler
Register service handler by name- Specified by:
registerServiceHandler
in interfaceIServiceHandlerProvider
- Parameters:
name
- Service handler namehandler
- Service handler
-
removeChildScope
Removes child scope- Specified by:
removeChildScope
in interfaceIScope
- Parameters:
scope
- Child scope to remove
-
removeChildren
public void removeChildren()Removes all the child scopes- Specified by:
removeChildren
in interfaceIScope
-
setAutoStart
public void setAutoStart(boolean autoStart) Setter for autostart flag- Specified by:
setAutoStart
in interfaceScopeMXBean
- Parameters:
autoStart
- Autostart flag value
-
setChildLoadPath
Setter for child load path. Should be implemented in subclasses?- Specified by:
setChildLoadPath
in interfaceScopeMXBean
- Parameters:
pattern
- Load path pattern
-
setContext
Setter for context- Parameters:
context
- Context object
-
setDepth
public void setDepth(int depth) Set scope depth- Specified by:
setDepth
in interfaceScopeMXBean
- Parameters:
depth
- Scope depth
-
setEnabled
public void setEnabled(boolean enabled) Enable or disable scope by setting enable flag- Specified by:
setEnabled
in interfaceScopeMXBean
- Parameters:
enabled
- Enable flag value
-
setHandler
Setter for scope event handler- Parameters:
handler
- Event handler
-
setName
Setter for scope name- Specified by:
setName
in interfaceScopeMXBean
- Parameters:
name
- Scope name
-
setParent
Setter for parent scope- Parameters:
parent
- Parent scope
-
setPersistenceClass
Set scope persistence class- Specified by:
setPersistenceClass
in interfaceScopeMXBean
- Parameters:
persistenceClass
- Scope's persistence class- Throws:
Exception
- Exception
-
start
public boolean start()Starts scope- Specified by:
start
in interfaceScopeMXBean
- Returns:
- true if scope has handler and it's start method returned true, false otherwise
-
stop
public void stop()Stops scope- Specified by:
stop
in interfaceScopeMXBean
-
toString
-
unregisterServiceHandler
Unregisters service handler by name- Specified by:
unregisterServiceHandler
in interfaceIServiceHandlerProvider
- Specified by:
unregisterServiceHandler
in interfaceScopeMXBean
- Parameters:
name
- Service handler name
-
getServer
Return the server instance connected to this scope.- Returns:
- the server instance
-
dump
public void dump() -
registerJMX
protected void registerJMX() -
unregisterJMX
protected void unregisterJMX() -
from
Allows for reconstruction via CompositeData.- Parameters:
cd
- composite data- Returns:
- Scope class instance
-
hashCode
public int hashCode()Description copied from class:BasicScope
Hash code is based on the scope's name and type- Overrides:
hashCode
in classBasicScope
- Returns:
- hash code
-
equals
Description copied from class:BasicScope
Equality is based on the scope's name and type.- Overrides:
equals
in classBasicScope
- Parameters:
obj
- object
-