[Red5devs] New boot process. Wiring up the context and scope tree.

Dominick Accattato daccattato at gmail.com
Wed Apr 5 09:20:27 EDT 2006


Its gonna take me some time to digest this :).  Thanks Luke.

On 4/5/06, Luke Hubbard (luke at codegent.com) <king.selassie at gmail.com> wrote:
>
> Hi Guys,
>
> My recent focus has been on trying to nail the boot / startup process.
> Getting to this point took quite a bit of thinking, and false starts, so
> Im writing this email to document how it works.
> Will try and commit later today, writing this email has taken ages :)
>
> Startup
>
> Standalone ( static main, loads root application context, this kicks off
> inititalization )
>
> ContextSingletonBeanFactoryLocator.getInstance ("red5.xml
> ").useBeanFactory("red5.global");
>
> The reason I do it this way, is that Spring uses this method from within
> ContextLoaderListener to access the child contexts. The red5.xml is loaded
> from the classpath. This works as /conf is on the classpath. The
> ContextSingletonBeanFactoryLocator sets up an internal application context
> holding the available contexts. Sounds a litte confusing, but think of it as
> a context to wire up the context tree and act as a directory to lookup those
> contexts by name. We basically kick off this init in a higher classloader
> before spring gets a chance to do it from the webapp init. This method
> should work with other servlet engines, and j2ee servers. In j2ee this would
> be done in the ear not Standalone.
>
> The context tree look at init time looks like this.
>
> classpath:red5.xml ( this is not root context, but does work like a
> directory for looking up contexts )
> red5.global => /conf/red5-global.xml ( this is the root context, it is the
> parent for all child contexts, so shared resources go in here)
>    |-- red5.net => /conf/red5-net.xml ( context holding all jetty and mina
> services )
>    |-- default.context => /webapps/default-context.xml ( global context,
> to be shared by webapps with default global scope )
>    |-- myvirtualserver.context => Its possible to have separate global
> contexts, this will be useful for hosting.
>
> All the above shares the same classloader and dont have the security
> restrictions that should be imposed on webapps. Like not being able to bind
> to port, or access files outside the sandbox.
>
> Jetty
>
> When jetty loads (from within red5.net) it configures and starts the
> webapps. Inside the web.xml the spring ContextLoaderListener is defined
> with the following servlet context init params.
>
> globalScope => default ( The name of the global scope this webapp will
> have as a parent scope )
> locatorFactorySelector => red5.xml (The context directory)
> parentContextKey => default.context (The parent spring context for this
> webapp)
> contextConfigLocation => /WEB-INF/red5-*.xml (Load the webapp spring
> context)
> log4jConfigLocation => /WEB-INF/log4j.properties
>
> Spring does its magic.. and wires up the webapps context to the default
> context.
> We now have separate spring contexts, with different classloaders arranged
> in a tree structure.
> red5.global < default.context < webapp.context ( note you cant walk down
> the tree only up )
> classloader key: root, webapp
>
> Before moving on, I should note.. /conf/web-default.xml holds a default
> web.xml file which can define things like rtmpt servlets for all webapps,
> welcome files, admin apps, etc.
>
> Scopes
>
> Inside default.context there is global.scope its an instance of
> GlobalScope when it loads it registers itself with red5.server (in
> red5.global). red5.server holds a map of global scopes and mappings from
> host + contextPath > global scopes.
>
> Lets take a look at the WEB-INF directory..
> web.xml ( standard webapp config files, adds listeners etc. )
> red5-web.xml ( holds the webapp context, and scope )
> red5-web.properties ( properties for spring and read by
> jetty.Red5WebappConfigurator )
>
> Inside the webapp context there is webapp.scope an instance of WebScope
> which implements from spring.ServletContextAware. It gets its context
> path, and virtual hosts from red5-web.properties and registers itself with
> the red5.server. Adding mappings for each host + contextPath. Initially I
> did this by inspecting the jetty contexts, just after jetty started, but the
> the problem was the webapps were loading and may not have finished. Plus it
> was a dependency on jetty we didn't need. Now thanks for Chris's suggestion
> we load the config from the same properties file which the web context
> loads. Jetty configuration is done by a custom jetty configuration which has
> been adapted to work with the same file. This just provides a convenience
> for those running the app inside our standalone server. If you wanted to
> deploy inside tomcat, you would have to add the vhosts in two places. In the
> tomcat config and in the red5-web.properties file.
>
> So.. the scope tree now looks like this..
> global.scope (name: default) > webapp.scope (name: test)
> Note we dont have the concept of 1 host = 1 scope. This doesnt mix with
> webapps.
> It is possible to have red5.org/test and red5.org/admin having separate
> global scopes.
>
> Assuming the webapp was on the context path /test with the virtual hosts
> localhost, and red5.org
> red5.server would have the following mappings.
>
> red5.org/test => default
> localhost/test => default
>
> Handling a connection within mina.
>
> Right so now everything should be wired up. When a clients connects to
> rtmp we check red5.server for a matching global. Assume they connected to
> localhost/test/room We would check for red5.server for localhost/test,
> then localhost/, then /.
> Once we have a global scope, we can lookup the child scope for /test/room.
> This might be a web scope or one of its children. After we get the correct
> scope we are pass it all events. It will handle passing to handlers, and
> notifying event listeners.
>
> I think that about covers it, back to coding for me. Talk later.
>
>
> -- Luke
>
>
> _______________________________________________
> Red5devs mailing list
> Red5devs at osflash.org
> http://osflash.org/mailman/listinfo/red5devs_osflash.org
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/red5devs_osflash.org/attachments/20060405/9f4a9c1a/attachment.htm


More information about the Red5devs mailing list