Handling application stop event in tomcat based red5 compilations



As you would know red5 is a media server package, which runs on top or other server cores  like Tomcat and Jetty.  There are few minor differences , hence in the way both compilations handle events and behaviors. The one we will be talking about here is specifically the “appStop” event. The “appStop” is suppose to fire off whenever the application stops/shuts down. The anomaly here is that on a tomcat based red5 compilations (which is the default one) the “appStop” does not fire up. This is because the is no straight forward  ”hook” / “point of entry” to determine when the server core stops. Hence we need to create a “Shutdown Hook” to handle the server/application shutdown by ourself.

The best way to do this is to create a internal / private class in your Application class source.  Sample:

/* ShutDown Hook for Red5 Application */
class ShutdownHook extends Thread
{
Application app;

public ShutdownHook(Application app)
{
this.app = app;
}

public void run()
{
// do something here
}
}

Next we relate it to our Application class by the “addShutdownHook” method. This method is not something for red5 only. Its the most common way to intercept and handle your java application shutdown. So in the Application class appStart() method we can add:

public boolean appStart(IScope app)
{

Runtime.getRuntime().addShutdownHook(new ShutdownHook(this));

return true;
}

We add it to the appStart() method to make sure it is called only once.
Note how we pass the reference to the Application class itself to the constructor “ShutdownHook”. Now by defining the properties as “protected” or “public” you can access then when the application/server is shutting down and do any cleanup jobs that you may have.

Popularity: 12% [?]




December 5, 2009   Posted in: Java, Red5

24 Responses

  1. Tibor Botos - August 16, 2010

    Thanks!

  2. Kfir Ozer - November 29, 2010

    Thanks a lot! :)

  3. Scrapebox Auto Approve List - March 9, 2011

    Scrapebox List…

    [...]Scrapebox List[...]…

  4. Barnevelder Chicken - March 10, 2011

    Buttercup Chicken…

    [...]Recommended Link List[...]…

  5. cap - March 10, 2011

    Double strollers…

    [...]the time to read or visit the content or sites we have linked to below the[...]…

  6. Grado Sr80 review - March 10, 2011

    Steve’s Super Site…

    [...] You can leave a reply, or trackback from your own personal website. Learn much more from the original source: Geeked Up: « Tech weblog Share and [...]…

  7. pictures of sarcoidosis - March 11, 2011

    sarcoidosis disease…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  8. Computer Telephone Support - March 11, 2011

    Website Tips…

    [...]is unrelated to my site but I still like to check it out. I recommend visiting it[...]…

  9. get a six pack fast - March 11, 2011

    Did you know Jolie broke up with him?…

    [...]below you will find the link to a couple sites we think you should visit[...]…

  10. Taylor Armstrong - March 12, 2011

    Taylor Armstrong States It’s An Excellent Post Cool…

    Brilliant story thought I would track-back to this keep up the great work……

  11. Cruises From Charleston SC - March 13, 2011

    Cruises Leaving Charleston…

    [...]the sites listed below are about some other topics that we though might be valuable for you[...]…

  12. Magniwork - March 19, 2011

    Magniwork…

    Love your blog first of all, what a great post, we are trying to write about similar subjects, so this article has really inspired me! Let’s hope I form some ideas and make a great post. Thanks for the help, Bookmarked….

  13. wartrol review - March 19, 2011

    Thanks……

    Thanks for the marvelous posting! I actually enjoyed reading it, you will be a great author.I will make certain to bookmark your blog and definitely will come back someday. I want to encourage continue your great writing, have a nice day!…

  14. small business marketing - March 21, 2011

    Fat Burning Furnace Review…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  15. Nucash - March 21, 2011

    Ledlights Nucash.nl Fantastico…

    [...]Het energie verbruik van een lamp wordt afgegeven in licht en warmte[...]…

  16. champignons - March 30, 2011

    Did you know Jolie broke up with him?…

    [...]below you will find the link to a couple sites we think you should visit[...]…

  17. the diet solution program - March 31, 2011

    the diet solution program…

    Thanks for the excellent blog post….

  18. Approved - April 1, 2011

    [...]below that are definitely worth checking out[...]…

  19. golf prints - April 3, 2011

    richard chorley golf…

    Thanks for such an excellent page, bookmarked, ill visit soon!…

  20. laptop power supply - April 4, 2011

    laptop charger…

    Thanks for such an excellent page, bookmarked, ill visit soon!…

  21. Anonymous - April 5, 2011

    Upholstery Cleaning London…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  22. Dremel Stylus - April 6, 2011

    Dremel Stylus…

    Bookmarked your site, so I can visit frequently, thank you!…

  23. Hunstanton - April 6, 2011

    Hunstanton…

    Trackback, I have linked to your site, thank you!…

  24. market place - April 7, 2011

    market place…

    Trackback, I have linked to your site, thank you!…

Leave a Reply