Search |
||
Extending the Grizzly HTTP RuntimePosted by jfarcand on July 3, 2008 at 8:52 PM PDT
Project Grizzly provides developers with a simple and consistent mechanism for extending the functionality of the Grizzly HTTP Runtime and for bridging existing HTTP based technologies like JRuby-on-Rail, Grail, Servlet, the Bayeux Protocol or any http based protocol. There is three important classes to know when you want to extend (and embed):
Sound complicated? Not at all! Let's describe some really simple examples. First, let's create a WebServer that serve static resources: Now let's write a very simple GrizzlyAdapter that return an html page when a static resource is not found. Now let's add Servlet support to our WebServer (note that the Grizzly's Servlet support is limited in term of functionalities..no deployment support, all done programatically) Well, why not adding two Servlet support Easy, it is (to speak like Yoda). Now let's go back to basic, which is to serve static resources. Let's assume we want to delay the request processing when we are under load, using an AsyncFilter. Let's assume for now that all requests will be suspended 10 seconds before they get executed by the GrizzlyAdapter. This is cool, is it? Now let's add Servlet to the picture: Miam Miam! OK now let do something really really complicated :-). Let's add Comet into the picture. Naa not enough complicated. Let's add the Bayeux Protocol (cometd) but also be able to serve static resources and Servlet. Wow. With just a couple of line we were able to create a Web Server that supports the Bayeux Protocol, a single Servlet and static resources. Now you can do things much more complicated, like writing complex and powerful GrizzlyAdapter, and call it GlassFish v3 :-). v3 is a good example of how easy it is to build really powerful HTTP extension using the Grizzly extensible point like the GrizzlyAdapter. Want to give it a try? Download the Grizzly HTTP extension, add it to your classpath, and look at the GrizzlyWebServer API. Now if you want to do things more complicated liked adding JMX support, monitoring, etc, then read that old blog serie and look at the now infamous SelectorThread documentation :-). If you have question, just stop by users@grizzly.dev.java.net...we have more and more peoples shaking the Grizzly those days!
technorati: grizzly web server embedded »
Related Topics >>
Glassfish Comments
Comments are listed in date ascending order (oldest first)
Submitted by aberrant on Tue, 2008-07-08 11:32.
Hi Jean-Francois,
I wanted to play around with your examples, but I was having issues. It seems that GrizzlyWebServer is in com.sun.grizzly.http.embed but the grizzly-servlet-webserver-1.8.1.jar has no com.sun.grizzly.http.embed package. Did I misunderstand and download the wrong jar?
Thanks,
Collin
Submitted by jfarcand on Tue, 2008-07-08 11:36.
Salut. I've just re-uploaded the 1.8.1 jars to see if that will make a difference. Wait 10 minutes and you should be able to use it. Let us know on users@grizzly.dev.java.net if that doesn't. Thanks for you interest! -- Jeanfrancois
Submitted by aberrant on Tue, 2008-07-08 13:31.
I found the embed package. It turns out it's in the 1.8.2-SNAPSHOT packages.
Submitted by xpan on Mon, 2009-08-10 23:52.
Hi Jean-Francois,
I have a problem with manage threads using Grizzly --
I wrote a http server like follows:
GrizzlyWebServer gws = new GrizzlyWebServer(PORT);
//set thread number
ws.setCoreThreads(100);
// Add a GrizzlyAdapter
gws.addGrizzlyAdapter(new GrizzlyAdapter()
public void service(GrizzlyRequest req, GrizzlyResponse res){
// some computationally intensive code
...
);
// Start Web server
gws.start();
// Count total thread....
while (true) {
Thread.sleep(5000);
System.out.println("total threads: " + Thread.getAllStackTraces().size());
}
After starting the server, I sent many requests to it and then the server printed out something like:
total threads: 56
...
total threads: 145
Even after I close the client, the number of active threads still remain as high as 145 !!
Where did I do wrong?! and how do I fix this? Any help is appreciated. Thank you in advance.
Shawn
xpan@cdmtech.com
|
||
|
|