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 ([email protected]), Nathan Smith ([email protected])
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder patternprivate final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AttributeStoreStorage for scope attributesprivate booleanAuto-start flagprivate final Scope.ConcurrentScopeSetChild scopesprivate final CopyOnWriteArraySet<IClient>Connected clients mapprotected final StatisticsCounterStatistics about connections to the scope.private IContextScope contextprivate longTimestamp the scope was created.private intScope nesting depth, unset by defaultprivate booleanWhether scope is enabledprivate IScopeHandlerScope handlerprotected static org.slf4j.Loggerprotected ObjectNameMbean object name.private booleanWhether scope is runningprivate ConcurrentMap<String,Object> Registered service handlers for this scope.protected final StatisticsCounterStatistics about sub-scopes.private static final intUnset flag constantFields inherited from class org.red5.server.scope.BasicScope
creation, keepDelay, keepOnDisconnect, listeners, name, parent, persistenceClass, persistent, securityHandlers, store, typeFields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIXFields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionScope()Creates a scopeScope(Scope.Builder builder) Creates scope using a Builder -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddChildScope(IBasicScope scope) Add child scope to this scopebooleanconnect(IConnection conn) Connect to scopebooleanconnect(IConnection conn, Object[] params) Connect to scope with parameters.booleancreateChildScope(String name) Create child scope of room type, with the given name.voiddestroy()Destroys scopevoiddisconnect(IConnection conn) Disconnect connection from scopevoiddispatchEvent(IEvent event) Dispatches event (notifies all listeners)voiddump()booleanEquality is based on the scope's name and type.static Scopefrom(CompositeData cd) Allows for reconstruction via CompositeData.intReturn current number of clients connected to the scope.intReturn current number of connections to the scope.intReturn 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 pathlongReturn the timestamp the object was created.intgetDepth()return scope depthbooleanHere for JMX only, uses isEnabled()Return scope handler or parent's scope handler if this scope doesn't have one.intDeprecated.intReturn maximum number of concurrent connections to the scope.intReturn 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 pathbooleanHere 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.intDeprecated.intReturn total number of connections to the scope.intReturn total number of subscopes created.booleanhandleEvent(IEvent event) Handles event.booleanhasAttribute(String name) Whether or not an attribute exists, keyed by the given namebooleanhasChildScope(String name) Check whether scope has child scope with given namebooleanhasChildScope(ScopeType type, String name) Check whether scope has child scope with given name and typebooleanCheck if scope has a contextbooleanCheck if scope or it's parent has handlerinthashCode()Hash code is based on the scope's name and typebooleanCheck if scope has parent scopevoidinit()Initialization actions, start if autostart is set to true.booleanCheck if scope is enabledbooleanCheck if scope is in running statelookupConnection(IClient client) Lookup connection for a given client.lookupConnections(IClient client) Deprecated.protected voidvoidregisterServiceHandler(String name, Object handler) Register service handler by namebooleanremoveAttribute(String name) Remove attribute by namevoidRemoves all the child scopesvoidremoveChildScope(IBasicScope scope) Removes child scopebooleansetAttribute(String name, Object value) Set attribute by namevoidsetAutoStart(boolean autoStart) Setter for autostart flagvoidsetChildLoadPath(String pattern) Setter for child load path.voidsetContext(IContext context) Setter for contextvoidsetDepth(int depth) Set scope depthvoidsetEnabled(boolean enabled) Enable or disable scope by setting enable flagvoidsetHandler(IScopeHandler handler) Setter for scope event handlerfinal voidSetter for scope namevoidSetter for parent scopevoidsetPersistenceClass(String persistenceClass) Set scope persistence classbooleanstart()Starts scopevoidstop()Stops scopetoString()voiduninit()Uninitialize scope and unregister from parent.protected voidvoidUnregisters 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, setSecurityHandlersMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.red5.server.api.scope.IBasicScope
getName, getStore, getType, isConnectionAllowed, isScopeAllowed, isValid, setKeepDelay, setSecurityHandlersMethods inherited from interface org.red5.server.api.event.IEventListener
notifyEventMethods inherited from interface org.red5.server.api.event.IEventObservable
addEventListener, getEventListeners, removeEventListenerMethods 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:
addChildScopein 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:
createChildScopein interfaceIScope- Specified by:
createChildScopein interfaceScopeMXBean- Parameters:
name- child scope name- Returns:
- true on success, false otherwise
-
destroy
Destroys scope- Specified by:
destroyin interfaceScopeMXBean- Throws:
Exception- on error
-
disconnect
Disconnect connection from scope- Specified by:
disconnectin interfaceIScope- Parameters:
conn- Connection object
-
dispatchEvent
Dispatches event (notifies all listeners)- Specified by:
dispatchEventin interfaceIEventDispatcher- Overrides:
dispatchEventin classBasicScope- Parameters:
event- Event to dispatch
-
getAttribute
Get attribute by name- Specified by:
getAttributein 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:
setAttributein 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:
hasAttributein interfaceIScope- Parameters:
name- name- Returns:
- true if it exists, false otherwise
-
removeAttribute
Remove attribute by name- Specified by:
removeAttributein interfaceIScope- Parameters:
name- name- Returns:
- true if removed, false otherwise
-
getAttributeNames
Return attribute names- Specified by:
getAttributeNamesin interfaceIScope- Returns:
- attribute names
-
getAttributes
Return scope attributes- Specified by:
getAttributesin interfaceIScope- Returns:
- attributes
-
getActiveClients
public int getActiveClients()Return current number of clients connected to the scope.- Specified by:
getActiveClientsin interfaceIScopeStatistics- Specified by:
getActiveClientsin interfaceScopeMXBean- Returns:
- number of clients
-
getActiveConnections
public int getActiveConnections()Return current number of connections to the scope.- Specified by:
getActiveConnectionsin interfaceIScopeStatistics- Specified by:
getActiveConnectionsin interfaceScopeMXBean- Returns:
- number of connections
-
getActiveSubscopes
public int getActiveSubscopes()Return number of currently existing subscopes.- Specified by:
getActiveSubscopesin interfaceIScopeStatistics- Specified by:
getActiveSubscopesin interfaceScopeMXBean- Returns:
- number of subscopes
-
getBroadcastScope
Return the broadcast scope for a given name- Specified by:
getBroadcastScopein interfaceIScope- Parameters:
name- name- Returns:
- broadcast scope or null if not found
-
getBasicScope
Return base scope of given type with given name- Specified by:
getBasicScopein interfaceIScope- Parameters:
type- Scope typename- Scope name- Returns:
- Basic scope object
-
getBasicScopeNames
Return basic scope names matching given type- Specified by:
getBasicScopeNamesin interfaceIScope- Parameters:
type- Scope type- Returns:
- set of scope names
-
getClassLoader
Return current thread context classloader- Specified by:
getClassLoaderin interfaceResourceLoader- Returns:
- Current thread context classloader
-
getClients
Return set of clients- Specified by:
getClientsin 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:
getConnectionsin interfaceIScope- Returns:
- Iterator holding all connections
-
getClientConnections
Get all current connections. You can call remove, and the connection will be closed.- Specified by:
getClientConnectionsin interfaceIScope- Returns:
- Set containing all connections
-
lookupConnections
Deprecated.Lookup connections.- Specified by:
lookupConnectionsin interfaceIScope- Parameters:
client- object- Returns:
- Set of connection objects (read-only)
-
lookupConnection
Lookup connection for a given client.- Specified by:
lookupConnectionin 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:
getContextin interfaceIScope- Returns:
- Scope context or parent context
-
getContextPath
Return scope context path- Specified by:
getContextPathin interfaceIScope- Specified by:
getContextPathin interfaceScopeMXBean- Returns:
- Scope context path
-
getCreationTime
public long getCreationTime()Return the timestamp the object was created.- Specified by:
getCreationTimein interfaceIStatisticsBase- Returns:
- the timestamp in milliseconds since midnight, January 1, 1970 UTC.
-
getDepth
public int getDepth()return scope depth- Specified by:
getDepthin interfaceIBasicScope- Specified by:
getDepthin interfaceIScopeStatistics- Specified by:
getDepthin interfaceScopeMXBean- Overrides:
getDepthin classBasicScope- Returns:
- Scope depth
-
getHandler
Return scope handler or parent's scope handler if this scope doesn't have one.- Specified by:
getHandlerin interfaceIScope- Returns:
- Scope handler (or parent's one)
-
getMaxClients
Deprecated.Return maximum number of clients concurrently connected to the scope.- Specified by:
getMaxClientsin interfaceIScopeStatistics- Specified by:
getMaxClientsin interfaceScopeMXBean- Returns:
- number of clients
-
getMaxConnections
public int getMaxConnections()Return maximum number of concurrent connections to the scope.- Specified by:
getMaxConnectionsin interfaceIScopeStatistics- Specified by:
getMaxConnectionsin interfaceScopeMXBean- Returns:
- number of connections
-
getMaxSubscopes
public int getMaxSubscopes()Return maximum number of concurrently existing subscopes.- Specified by:
getMaxSubscopesin interfaceIScopeStatistics- Specified by:
getMaxSubscopesin interfaceScopeMXBean- Returns:
- number of subscopes
-
getParent
Return parent scope- Specified by:
getParentin interfaceIBasicScope- Overrides:
getParentin classBasicScope- Returns:
- Parent scope
-
getPath
Return scope path calculated from parent path and parent scope name- Specified by:
getPathin interfaceIBasicScope- Specified by:
getPathin interfaceIScopeStatistics- Specified by:
getPathin interfaceScopeMXBean- Overrides:
getPathin classBasicScope- Returns:
- Scope path
-
getResource
Return resource located at given path- Specified by:
getResourcein interfaceResourceLoader- Parameters:
path- Resource path- Returns:
- Resource
-
getResources
Return array of resources from path string, usually used with pattern path- Specified by:
getResourcesin 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:
getScopeNamesin interfaceIScope- Returns:
- Child scope names iterator
-
getServiceHandler
Return service handler by name- Specified by:
getServiceHandlerin 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:
getServiceHandlerNamesin interfaceIServiceHandlerProvider- Specified by:
getServiceHandlerNamesin 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:
getStatisticsin interfaceIScope- Returns:
- statistics
-
getTotalClients
Deprecated.Return total number of clients connected to the scope.- Specified by:
getTotalClientsin interfaceIScopeStatistics- Specified by:
getTotalClientsin interfaceScopeMXBean- Returns:
- number of clients
-
getTotalConnections
public int getTotalConnections()Return total number of connections to the scope.- Specified by:
getTotalConnectionsin interfaceIScopeStatistics- Specified by:
getTotalConnectionsin interfaceScopeMXBean- Returns:
- number of connections
-
getTotalSubscopes
public int getTotalSubscopes()Return total number of subscopes created.- Specified by:
getTotalSubscopesin interfaceIScopeStatistics- Specified by:
getTotalSubscopesin interfaceScopeMXBean- Returns:
- number of subscopes created
-
handleEvent
Handles event. To be implemented in subclasses.- Specified by:
handleEventin interfaceIEventHandler- Overrides:
handleEventin classBasicScope- Parameters:
event- Event to handle- Returns:
- true on success, false otherwise
-
hasChildScope
Check whether scope has child scope with given name- Specified by:
hasChildScopein interfaceIScope- Specified by:
hasChildScopein 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:
hasChildScopein interfaceIScope- Specified by:
hasChildScopein 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:
hasContextin interfaceScopeMXBean- Returns:
- true if scope has context, false otherwise
-
hasHandler
public boolean hasHandler()Check if scope or it's parent has handler- Specified by:
hasHandlerin interfaceIScope- Specified by:
hasHandlerin 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:
hasParentin interfaceIBasicScope- Specified by:
hasParentin interfaceScopeMXBean- Overrides:
hasParentin 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:
initin 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:
getEnabledin 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:
getRunningin interfaceScopeMXBean- Returns:
true
if scope is in running state,false
otherwise
-
registerServiceHandler
Register service handler by name- Specified by:
registerServiceHandlerin interfaceIServiceHandlerProvider- Parameters:
name- Service handler namehandler- Service handler
-
removeChildScope
Removes child scope- Specified by:
removeChildScopein interfaceIScope- Parameters:
scope- Child scope to remove
-
removeChildren
public void removeChildren()Removes all the child scopes- Specified by:
removeChildrenin interfaceIScope
-
setAutoStart
public void setAutoStart(boolean autoStart) Setter for autostart flag- Specified by:
setAutoStartin interfaceScopeMXBean- Parameters:
autoStart- Autostart flag value
-
setChildLoadPath
Setter for child load path. Should be implemented in subclasses?- Specified by:
setChildLoadPathin 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:
setDepthin interfaceScopeMXBean- Parameters:
depth- Scope depth
-
setEnabled
public void setEnabled(boolean enabled) Enable or disable scope by setting enable flag- Specified by:
setEnabledin interfaceScopeMXBean- Parameters:
enabled- Enable flag value
-
setHandler
Setter for scope event handler- Parameters:
handler- Event handler
-
setName
Setter for scope name- Specified by:
setNamein interfaceScopeMXBean- Parameters:
name- Scope name
-
setParent
Setter for parent scope- Parameters:
parent- Parent scope
-
setPersistenceClass
Set scope persistence class- Specified by:
setPersistenceClassin interfaceScopeMXBean- Parameters:
persistenceClass- Scope's persistence class- Throws:
Exception- Exception
-
start
public boolean start()Starts scope- Specified by:
startin interfaceScopeMXBean- Returns:
- true if scope has handler and it's start method returned true, false otherwise
-
stop
public void stop()Stops scope- Specified by:
stopin interfaceScopeMXBean
-
toString
-
unregisterServiceHandler
Unregisters service handler by name- Specified by:
unregisterServiceHandlerin interfaceIServiceHandlerProvider- Specified by:
unregisterServiceHandlerin 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:BasicScopeHash code is based on the scope's name and type- Overrides:
hashCodein classBasicScope- Returns:
- hash code
-
equals
Description copied from class:BasicScopeEquality is based on the scope's name and type.- Overrides:
equalsin classBasicScope- Parameters:
obj- object
-