A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Thursday, May 20, 2010

REVERSE AJAX (DWR)

7:31:00 PM Posted by Satish , , , No comments

It had been a long time, I last worked in DWR. Around one year back at my previous company, I was working in DWR. I used reverse AJAX technique to some part of the application, which was quite impressive. So I started playing around this again to do some new things.

This part of the post is just a basic demonstration of reverse AJAX. The basic idea is to push different messages to different clients.  Let's take a example; there is a page with javascript links to load different shelf's of a ware house in to a div element. Client "A" is viewing shelf "SH-01" and client "B" is viewing shelf "SH-2". In this case client "A" and client "B" should have been pushed with different updates.

Environment set up:

1. Install JDK 1.6 in your system or any platform you want.

2. Install Tomcat 6 followed by JDK installation.

3. Deploy the war file to " webapps" of Tomcat installation directory and start the server.

4. Now you can view the demonstration by entering "http://localhost:8080/DWR" to the browser location bar.

Eclipse setup:

1. To work with the source code, please use eclipse 3.3 or higher version.

2. Download the source code.

3. Create a dynamic web project with name "DWR".

4. Copy the whole content of downloaded "DWR" folder to the workspace "DWR" folder and refresh the workspace.

5. Configure Tomcat to eclipse and add the project to that.

About the application:

The application has got the following components.

1. Event Engine

2. Event Listener

3. Script Session Manager

Event Engine is nothing to do with reverse AJAX. I just created to demonstrate the message pushing technique. Event Engine will get stated when the server starts for the first time. This engine will keep on create the messages and notify all the listeners.

Event Listeners will be listening to all the events generated by the Event Engine and use the Script Session Manager to push the message to respective client.

Script Session Manager is responsible for registration and de-registration the client script sessions. And it is also responsible for message processing and pushing to respective client.

The whole process goes something like this.

1. When you start the server, the event engine will get started with that.(Created a servlet with init block and configured in web.xml to create a event object at startup)

2. Now you can view the demonstration by entering "http://localhost:8080/DWR" to the browser location bar.

3. Select Any parameter from the dropdown.(The application will create a script session at server side.)

4. Now when ever any message for that parameter will get generated, the message will be pushed to the client.

5. You can change the parameter in UI and get the respective updates accordingly.

6. If you close the window without removing the session, the session will get expire after 500ms.

Shared Items:

1. Source Codes or you can pull it from GitHub.

2. War File

3. Java Doc

0 comments:

Post a Comment