« WebLogic Scheduling - A polling approach to implement a DB event generator for ALSB | Main | Using LDAP as a user-store for WebLogic Administrators »

Asynchronous Servlet Article Extras - Push Events

This was originally posted on my dev2dev blog December 5th, 2007.

I just finished reading Francesco Marchioni's article entitled Using Asynchronous Servlets to Deal with Hung Threads and thought that I could add some information for those that want to explore this functionality more and see a working example of a chat room built with AJAX.  This is really about implementing virtual push event to web clients.  Starting with WLS 10, there is an out-of-the-box example that ships with WebLogic Server that illustrates using the Abstract Asynchronous Servlet to build a chat room.  In effect, it uses AJAX to create an event push (via a long poll).  So now when a client sends a message to the chat room, all the clients receive the message virtually instantly without constantly polling the server for new messages.  This technique has come to be known as Comet in AJAX terminology.  To read the details of the example, just go to <BEA_HOME>/wlserver_10.0/samples/server/docs/core/index.html and expand the tree as shown below.  To run it, just follow the directions which are very straight-forward.

ChatExample

Also check the javadoc for the AbstractAsynchrounousServlet to get more information about the API.

One neat thing to do is to run the example with both Firefox and IE at the same time and see messages sent by the IE client show up immediately in the Firefox client.  I have the Firebug plug-in installed and you can see how the XmlHttpRequest (XHR) is waiting for new chat messages to come in.  If no new messages arrive in 20 seconds, the AbstractAsynchServlet times out the request.  Then the client issues a new XHR and starts the process again.

firefoxWithFirebug

I've seen some fairly neat examples and demos built with the AbstractAsynchronousServlet in WebLogic Portal such as a dash-board portlet that sends out messages and alerts.  So if you have use-cases that would benefit from having events virtually pushed to web clients, consider using this approach as it is very effective and does not tie up threads on the server.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

james_bayer.jpg

I am a Senior Sales Consultant covering enterprise customers in and around the Chicago area focusing on middleware and internet technologies. My career began as a Java consultant and architect where I experienced the technology shift toward SOA. I enjoy helping customers solve business problems by applying Oracle technology solutions.

About This Entry

This page contains a single entry from the blog posted on December 5, 2007 7:31 PM.

The previous post in this blog was WebLogic Scheduling - A polling approach to implement a DB event generator for ALSB.

The next post in this blog is Using LDAP as a user-store for WebLogic Administrators.

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle