Archive

Archive for April, 2009

Atmosphere 0.1 GA available with Twitter, Flickr and Chat sample

After couple of weeks collecting feedback from the newly created community (THANKS!), Atmosphere 0.1 GA is now available with support for Glassfish 1/2/3, Weblogic 9.x and up, Tomcat 4/5/6, Jetty 4/5/6/7, Grizzly 1.9.x, Winstone, etc.

IMG_2481.JPG

All of the above containers are supported out-of-the-box, e.g. you download our web.xml template, set your servlet-mapping, and you ready to write a portable Comet application. Based on the container you are running on, Atmosphere will auto-detect their native Comet API and uses it, or fake it if not found (like Tomcat 4). The only one “container” that doesn’t work is…Servlet 3.0 Async proposal! Why? Because Servlet 3.0 Async is not enabled by default (strange decision ;-)) so you must either annotate your Servlet to tell the container you want to use async features, or you add a special element in web.xml. But since it requires the Servlet 3.0 DTD, Atmosphere cannot support 3.0 Async as an application using a web.xml targeted for 3.0 will not deploy in Servlet 2.5 Container (the majority of them!). Yes, that’s bad (to not say that suck..I did try all kind of hack without success!)! So if you want to use Atmosphere with Servlet 3.0, your application will not be portable..unless you switch your web.xml…NOT! Hopefully I can make the Servlet team change their decision as this is really really bad for any framework that want to support 3.0 and existing native Comet implementation.

Atmosphere 0.1 natively supports:

  • GlassFish (Grizzly Comet)
  • Weblogic Async Servlet (9.x and up)
  • Tomcat AIO (Tomcat 6, JBoss Web)
  • Jetty Continuation
  • And emulate Comet on any others Servlet Container supporting the Spec version 2.3 and up

How to get started? Read this simple intro (or just drop Atmosphere CPR under WEB-INF/lib) or download one of our samples

What’s next? Before 0.2 release my plan is to write a complete tutorial which demonstrate all the Atmosphere powerful features. Even now, it is crystal clear than writing a Comet application is much more easy and fast than using any native implementation, including the upcoming Servlet 3.0. So start today using it!

As usual, feedback appreciated by either sending your questions to users@atmosphere.dev.java.net or by tweeting us!

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

var pageTracker = _gat._getTracker(“UA-3111670-3”);
pageTracker._initData();
pageTracker._trackPageview();

technorati:

Advertisements
Categories: Uncategorized

Extending the Grizzly HTTP Runtime VII: Cluster/load balance GrizzlyAdapter using Apache

With the release of Grizzly 1.9.11, it is now possible to cluster/load balance your GrizzlyAdapter using Apache!

IMG_0448.JPG

As I described in the previous entry on the topic(I,II,II,IV, V, VI), it is quite simple to embed Grizzly using its’ extension point: GrizzlyAdapter:

        GrizzlyWebServer ws = new GrizzlyWebServer("/var/www");
        try{
            ws.addGrizzlyAdapter(new GrizzlyAdapter(){  
                
                public void service(GrizzlyRequest request, GrizzlyResponse response){
                    try {
                        response.getWriter().println("Grizzly is so cool!!!");
                    } catch (IOException ex) {                        
                    }
                }
            });
            ws.start();
        } catch (IOException ex){
            // Something when wrong.
        }

Now let’s assume you want to add clustering/load balancing support to your GrizzlyAdapter. To add such support, let’s use Apache 2 and mod_jk. To install mod_jk and Apache, just install mod_jk module (see here for an example):


LoadModule jk_module /usr/apache2/httpd/modules/mod_jk.so
JkWorkersFile /etc/apache2/conf/worker.properties
# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send all grizzly/ requests to Grizzly
JkMount /grizzly/* worker1


The add in your /etc/apache2/worker.properties


# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost.localdomain
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300

With the above, we are telling Apache to forward (via mod_jk) all requests starting with /grizzly to …. GrizzlyWebServer! How? Let’s take the previous example and add support for mod_jk:

        GrizzlyWebServer ws = new GrizzlyWebServer("/var/www");
        try{
            ws.addGrizzlyAdapter(new GrizzlyAdapter(){  
                
                public void service(GrizzlyRequest request, GrizzlyResponse response){
                    try {
                        response.getWriter().println("Grizzly is so cool!!!");
                    } catch (IOException ex) {                        
                    }
                }
            });
            ws.enableProtocol(PROTOCOL.AJP);
            ws.start();
        } catch (IOException ex){
            // Something when wrong.
        }

Just compile, java -jar …That’s it! Now any blog talking about mod_jk clustering/load balancing configuration can be used with your GrizzlyAdapter. As an example, take a look at this one

For any questions, post them to users@grizzly.dev.java.net or tweet us here.

_uacct = “UA-3111670-1”;
urchinTracker();

technorati:

Categories: Uncategorized

Atmosphere 0.1-ALPHA2 released with support for any WebServer (WebSphere,WLS, etc.), and Servlet 3.0 Async

Second release (thanks for the feedback so far!), this time with support for any WebServer and the few one that support the Servlet 3.0 Async API.

IMG_2439.JPG

What’s new since our last release? First, if the WebServer you deploy on support the Servlet 3.0 Async specification, the Atmosphere runtime will detect it and will run using those API. Note that your AtmosphereHandler doesn’t have to use the new API to keep portability with other WebServer that aren’t yet supporting those API. Second, if the WebServer you deploy on doesn’t support Comet, the Atmosphere runtime will emulate Comet support by optimally blocking threads when needed. So it means GlassFish v1, Jetty 4/5, Tomcat4/5, BEA’s WLS, WebSphere etc. can now be used with Atmosphere. Finally, the Broadcaster now support custom thread pool (ExecutorService), which you can configure from your AtmosphereHandler:

    public AtmosphereEvent
            onMessage(AtmosphereEvent event) throws IOException {
        HttpServletRequest req = event.getRequest();
        HttpServletResponse res = event.getResponse();

        event.getBroadcaster().setExecutorService(
                    Executors.newCachedThreadPool());
        if (event.isResuming()) {
            String script = BEGIN_SCRIPT_TAG + "window.parent.app.listen();\n" + END_SCRIPT_TAG;

            res.getWriter().write(script);
            res.getWriter().flush();
        } else {
            res.getWriter().write(event.getMessage().toString());
            res.getWriter().flush();
        }
        return event;
    }

Using a thread pool when broadcasting messages can save your life and greatly improve scalability of your application!

Ready to write your first AtmosphereHandler? Download the latest release from here. As usual, feedback appreciated by either sending your questions to users@atmosphere.dev.java.net or by tweeting us!

var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src='” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));

var pageTracker = _gat._getTracker(“UA-3111670-3”);
pageTracker._initData();
pageTracker._trackPageview();

technorati:

Categories: Uncategorized