Various ramblings-on, mostly about Red5

15 Apr 09 Java book recommendations

I see this question quite a lot, “What books should I read to learn Java”. I have a set of books I like to recommend, books that have made me a better developer. So without further adieu..

Effective Java

Java concurrency in practice

For Red5 development I also recommend:

Spring in Action

Professional Apache Tomcat 6

Lastly, you can usually pick these books up even cheaper if you click on the “used” section on Amazon.

Heres a snapshot of two of my shelves of books.

Tags: , , , , , ,

23 Mar 09 Spring lifecycle and Red5

I just fixed a huge bug in Red5 (r3574) and I am shocked that no one noticed it (the bug) before I did. The problem occured when the server was shutdown via JVM exit or our shutdown scripts. The Spring destroy and DisposableBean hooks were not being executed as would be expected. I’m sure there were at least a few people who thought their apps were cleaning up properly via their “destroy-method” bean attributes, like I did. Below you will find my test application, should you want to test it yourself. Enjoy… 

Example project:

Tags: , , , ,

30 Jan 09 Red5 and Hibernate

So many of you want to use an ORM layer with Red5, I get direct emails all-the-time! Please look at Carl’s tutorial instead.

Tags: , , , ,

18 Jan 09 Spring configs and Red5 applications

This is just a quick post to let you all know about a problem Carl and I ran into with one of his example applications for red5. The application seemed to start and there where no errors in the logs, even at TRACE level for com, net, and org; it seemed that Spring or Red5 were swallowing whatever error or misconfiguration was occurring. The final resolution was found by replacing config sections with those from the oflaDemo example, one-by-one; which is what we often tell readers of the mailing list. So here is the section that silently fails

<bean id="web.scope" class="org.red5.server.WebScope" init-method="register"

and here is the version that works

<bean id="web.scope" class="org.red5.server.WebScope" init-method="register">
    <property name="server" ref="red5.server" />
    <property name="parent" ref="global.scope" />
    <property name="context" ref="web.context" />
    <property name="handler" ref="web.handler" />
    <property name="contextPath" value="${webapp.contextPath}" />
    <property name="virtualHosts" value="${webapp.virtualHosts}" />

Tags: , ,

01 Oct 08 Accessing parameters

I recall seeing a question from a user about accessing servlet parameters from their Red5 application, so I have created a small demo which shows how to not only access sevlet parameters from Red5 apps but the other way around as well.

Retrieve a servlet context parameter from inside a Red5 application (AppContext -> Servlet)

1. Grab a reference to the application context

ApplicationContext appCtx = getContext().getApplicationContext();

2. Get the servlet context

ServletContext ctx = ((XmlWebApplicationContext) appCtx).getServletContext();

3. Get the context parameter

String param = ctx.getInitParameter("myparam");

Retrieve an application context parameter from a inside a servlet (Servlet -> AppContext)

1. Get the servlet context

ServletContext ctx = getServletContext();

2. Grab a reference to the application context

ApplicationContext appCtx = ctx.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);

3. Get the bean holding the parameter

MyBean bean = appCtx.getBean("mybean");
String param = bean.getParameter("myparam");

Sample project files:


Unzip the demo and create a new directory named parameterdemo in your red5/webapps directory, then restart your server.

Open your browser and go here: http://localhost/parameterdemo/myservlet?paramName=myparam

You should see “Hello World”

To test the Red5 application you will need to create a Flex or Flash application that connects to: rtmp://localhost/parameterdemo

Then simply call “getParameter” passing a parameter name you want the value of. The name must match a context param in the web.xml file.

Tags: , , , , ,

28 Sep 08 Tomcat connectors

In Red5, you have pretty much full access to manipulate the embedded Tomcat engine via Spring. With that being said I would like to give details on how to change the http connector between two available options; there are several other options, but I’ll only be covering NIO and BIO. First a quick explanation of these two options:

  • BIO – Blocking Input / Output, this has been around since the beginning of internet time. It uses one thread per socket connnection to handle requests.
  • NIO – Non-blocking Input / Output, this has been available in the JDK since 1.4. It uses a single thread to handle many socket connections.
In most cases, you should find NIO to be much faster and more able to handle a lot more connections than BIO will. The default connector was set to NIO until today when I switched it to BIO to prevent problems with Unix-based systems (OSX / Linux).
The configuration of Tomcat in Red5 for HTTP, RTMPT, and RTMPS is nearly identical so you may apply the configuration items below to any of the embedded servers. To configure with a BIO connector, locate the connector section and change the constructor arg value:

<property name=”connector”>
  <bean class=”org.apache.catalina.connector.Connector”>
    <constructor-arg type=”java.lang.String” value=”org.apache.coyote.http11.Http11Protocol” />
    <property name=”port”><value>80</value></property>
    <property name=”redirectPort”><value>443</value></property>
    <property name=”enableLookups”><value>false</value></property>

To use the NIO connector simply change the constructor arg as shown below:

<property name=”connector”>
  <bean class=”org.apache.catalina.connector.Connector”>
    <constructor-arg type=”java.lang.String” value=”org.apache.coyote.http11.Http11NioProtocol” />
    <property name=”port”><value>80</value></property>
    <property name=”redirectPort”><value>443</value></property>
    <property name=”enableLookups”><value>false</value></property>

Tags: , , , , , , , ,

30 Aug 08 Hibernate Transactions with BTM

I recently had the worst time trying to get JTA transactions to play nice in Hibernate configured via Spring. There is a lot of information out there on bits-n-pieces of the individual technologies but nothing seemed to show the whole picture, so I would like to provide the community with a working example. The code is not “perfect” but it demonstrates how to get this stuff working in harmony. A junit test, mssql scripts, and all the configs are included. I also set this up to use a composite key, since the project I worked on used a great deal of them and info was not easy to come by.
One of the libraries I used called BTM was instrumental in getting this to work (thanks Ludovic!), you will find this a lot easier to use than JOTM. There is a huge gotcha when using XA transactions with MSSQL, you have to install a dll and run some scripts to get it enabled and that info may be found here. I’m not sure if you have to do anything special in MySQL but I doubt it :)

The example comes as a zipped Eclipse project available here.

Tags: , , , , , ,

Fatal error: Call to undefined function akismet_counter() in C:\xampp\htdocs\paulgregoireblog\wp-content\themes\googlechrome\footer.php on line 9