org.red5.server

## Class ContextLoader

- java.lang.Object
- - org.red5.server.ContextLoader

All Implemented Interfaces:
  ContextLoaderMXBean, ShutdownMXBean, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

    @ManagedResource(objectName="org.red5.server:name=contextLoader,type=ContextLoader",
                     description="ContextLoader")
    public class ContextLoader
    extends Object
    implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean, ContextLoaderMXBean

Red5 applications loader

Author:
  The Red5 Project (red5@osflash.org), Tiago Jacobs (tiago@imdt.com.br), Paul Gregoire (mondain@gmail.com)

### Field Summary

Fields
`protected org.springframework.context.ApplicationContext` `applicationContext` Spring Application context
`protected ConcurrentMap<String,org.springframework.context.ApplicationContext>` `contextMap` Context map
`protected String` `contextsConfig` Context location files
`protected static org.slf4j.Logger` `log`
`protected org.springframework.context.ApplicationContext` `parentContext` Spring parent app context

### Constructor Summary

Constructors
Constructor and Description
`ContextLoader()`

### Method Summary

Methods
`void` `afterPropertiesSet()` Registers with JMX and registers a shutdown hook.
`void` `destroy()` Un-loads or un-initializes the contexts; this is a shutdown method for this loader.
`org.springframework.context.ApplicationContext` `getContext(String name)` Return context by name
`String` `getContextsConfig()`
`org.springframework.context.ApplicationContext` `getParentContext()` Return parent context
`void` `init()` Loads context settings from ResourceBundle (.properties file)
`boolean` `isUseShutdownHook()` Whether or not the shutdown hook is enabled.
`void` `loadContext(String name, String config)` Loads a context (Red5 application) and stores it in a context map, then adds it's beans to parent (that is, Red5)
`protected void` `registerJMX()`
`void` `setApplicationContext(org.springframework.context.ApplicationContext applicationContext)`
`void` `setContextsConfig(String contextsConfig)` Setter for context config name
`void` `setParentContext(org.springframework.context.ApplicationContext parentContext)` Setter for parent application context
`void` `setParentContext(String parentContextKey, String appContextId)` Sets a parent context for child context based on a given key.
`void` `setUseShutdownHook(boolean useShutdownHook)` Enables or disables the shutdown hook.
`void` `shutdown()` Shut server down.
`void` `unloadContext(String name)` Unloads a context (Red5 application) and removes it from the context map, then removes it's beans from the parent (that is, Red5)
`protected void` `unregisterJMX()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### log

    protected static org.slf4j.Logger log

#### applicationContext

    protected org.springframework.context.ApplicationContext applicationContext

Spring Application context

#### parentContext

    protected org.springframework.context.ApplicationContext parentContext

Spring parent app context

#### contextsConfig

    protected String contextsConfig

Context location files

#### contextMap

    protected ConcurrentMap<String,org.springframework.context.ApplicationContext> contextMap

Context map

### Constructor Detail

#### ContextLoader

    public ContextLoader()

### Method Detail

#### afterPropertiesSet

    public void afterPropertiesSet()
                            throws Exception

Registers with JMX and registers a shutdown hook.

Specified by:
  `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
Throws:
  `Exception` - I/O exception, casting exception and others

#### destroy

    public void destroy()
                 throws Exception

Un-loads or un-initializes the contexts; this is a shutdown method for this loader.

Specified by:
  `destroy` in interface `org.springframework.beans.factory.DisposableBean`
Throws:
  `Exception`

#### init

    public void init()
              throws IOException

Loads context settings from ResourceBundle (.properties file)

Specified by:
  `init` in interface `ContextLoaderMXBean`
Throws:
  `IOException`

#### loadContext

    public void loadContext(String name,
                   String config)

Loads a context (Red5 application) and stores it in a context map, then adds it's beans to parent (that is, Red5)

Specified by:
  `loadContext` in interface `ContextLoaderMXBean`
Parameters:
  `name` - Context name
  `config` - Filename

#### unloadContext

    public void unloadContext(String name)

Unloads a context (Red5 application) and removes it from the context map, then removes it's beans from the parent (that is, Red5)

Specified by:
  `unloadContext` in interface `ContextLoaderMXBean`
Parameters:
  `name` - Context name

#### shutdown

    public void shutdown()

Shut server down.

Specified by:
  `shutdown` in interface `ContextLoaderMXBean`
Specified by:
  `shutdown` in interface `ShutdownMXBean`

#### getContext

    public org.springframework.context.ApplicationContext getContext(String name)

Return context by name

Parameters:
  `name` - Context name
Returns:
  Application context for given name

#### setParentContext

    public void setParentContext(String parentContextKey,
                        String appContextId)

Sets a parent context for child context based on a given key.

Specified by:
  `setParentContext` in interface `ContextLoaderMXBean`
Parameters:
  `parentContextKey` - key for the parent context
  `appContextId` - id of the child context

#### registerJMX

    protected void registerJMX()

#### unregisterJMX

    protected void unregisterJMX()

#### setApplicationContext

    public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                               throws org.springframework.beans.BeansException

Specified by:
  `setApplicationContext` in interface `org.springframework.context.ApplicationContextAware`
Parameters:
  `applicationContext` - Spring application context
Throws:
  `org.springframework.beans.BeansException` - Top level exception for app context (that is, in fact, beans factory)

#### setParentContext

    public void setParentContext(org.springframework.context.ApplicationContext parentContext)

Setter for parent application context

Parameters:
  `parentContext` - Parent Spring application context

#### getParentContext

    public org.springframework.context.ApplicationContext getParentContext()

Return parent context

Returns:
  parent application context

#### setContextsConfig

    public void setContextsConfig(String contextsConfig)

Setter for context config name

Specified by:
  `setContextsConfig` in interface `ContextLoaderMXBean`
Parameters:
  `contextsConfig` - Context config name

#### getContextsConfig

    public String getContextsConfig()

Specified by:
  `getContextsConfig` in interface `ContextLoaderMXBean`

#### isUseShutdownHook

    public boolean isUseShutdownHook()

Whether or not the shutdown hook is enabled.

Returns:
  true if enabled, false otherwise

#### setUseShutdownHook

    public void setUseShutdownHook(boolean useShutdownHook)

Enables or disables the shutdown hook.

Parameters:
  `useShutdownHook` - true to enable, false to disable