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:
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:
{
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
Thanks!
Thanks a lot!
Scrapebox Auto Approve List - March 9, 2011
Scrapebox List…
[...]Scrapebox List[...]…
Barnevelder Chicken - March 10, 2011
Buttercup Chicken…
[...]Recommended Link List[...]…
cap - March 10, 2011
Double strollers…
[...]the time to read or visit the content or sites we have linked to below the[...]…
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 [...]…
pictures of sarcoidosis - March 11, 2011
sarcoidosis disease…
[...]below you’ll find the link to some sites that we think you should visit[...]…
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[...]…
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[...]…
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……
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[...]…
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….
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!…
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[...]…
Nucash - March 21, 2011
Ledlights Nucash.nl Fantastico…
[...]Het energie verbruik van een lamp wordt afgegeven in licht en warmte[...]…
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[...]…
the diet solution program - March 31, 2011
the diet solution program…
Thanks for the excellent blog post….
Approved - April 1, 2011
…
[...]below that are definitely worth checking out[...]…
golf prints - April 3, 2011
richard chorley golf…
Thanks for such an excellent page, bookmarked, ill visit soon!…
laptop power supply - April 4, 2011
laptop charger…
Thanks for such an excellent page, bookmarked, ill visit soon!…
Anonymous - April 5, 2011
Upholstery Cleaning London…
[...]below you’ll find the link to some sites that we think you should visit[...]…
Dremel Stylus - April 6, 2011
Dremel Stylus…
Bookmarked your site, so I can visit frequently, thank you!…
Hunstanton - April 6, 2011
Hunstanton…
Trackback, I have linked to your site, thank you!…
market place - April 7, 2011
market place…
Trackback, I have linked to your site, thank you!…
Leave a Reply