Home arrow Java & J2EE arrow Using RMI with Apache Jserv

Using RMI with Apache Jserv

One of the greatest advantages which Jserv brings to Apache is ability to leverage the large number of API's available to Java. Remote Method Invocation (RMI) delivers several significant benefits to the servlet solution. The primary benefit of using RMI with servlets is that it significantly expands the variety of datasources which Apache can serve to the browser. Furthermore, RMI's simplifies code on the client side of the RMI connection (the servlet), and also allows for load distribution.

TABLE OF CONTENTS:
  1. Using RMI with Apache Jserv
  2. Design the Remote Interface
  3. Create the client program (the servlet)
  4. Conclusion
By: Richard Yumul
Rating: starstarstarstarstar / 5
January 21, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

One of the greatest advantages which Jserv brings to Apache is ability to leverage the large number of API's available to Java. Remote Method Invocation (RMI) delivers several significant benefits to the servlet solution. The primary benefit of using RMI with servlets is that it significantly expands the variety of datasources which Apache can serve to the browser. Furthermore, RMI's simplifies code on the client side of the RMI connection (the servlet), and also allows for load distribution.

For example, if you wanted a servlet to access a database through JDBC, you would start off with importing the java.sql package into your servlet. Then your servlet would have to manage handling the database connection, preparing and executing SQL statements, as well as managing the result sets. This adds a lot of complexity to your servlet, as not only does it have to handle logic & return appropriate responses to the browser, it is also bogged down managing communications with the database.


Servlet <== JDBC ==> Database
With RMI, an abstraction layer is added between the data source and the servlet. This layer, the RMI Service (or server tier), provides an simplified interface to the client, handling all of the internals of communicating with the database.

Servlet <== Remote Interface ==> RMI Service <== JDBC ==> Database
So, instead of having to manage the database communications in your servlet, RMI hides all the that from your servlet behind its remote interface.

With RMI, the server tier can be anything, as long as it implements the defined remote interface. The service could even be hosted on a different machine with a different operating system. The client will not care if the server tier stores its data in a database, LDAP server, or even text files. Your Linux Apache-Jserv box could be pulling data from an application server on a Solaris box.

Example

Using RMI with Apache Jserv is fairly straight-forward, and the procedure in this example pretty much follows the RMI examples which can be found in the JDK documentation or Sun's tutorial. The steps include:

  1. Design the remote interface
  2. Implement the remote interface
  3. Compile the classes, create the stub and skeleton classes
  4. Create the client program (in this case, the servlet)
  5. Deploy

In the following example, we will create a simple email address book. The server will store it's data in a Hashtable. Of course, the data in the server will disappear when the server is stopped, but that's okay for this example's purposes. For a more robust server, the address book data could be stored in a database, LDAP server, or any other type of data storage. The servlet (client) will use the address book service through RMI.

There are three packages in our example. The first one, is the directory.* package. It holds the remote interface class, as well as the Entry class, a data structure representing an directory record. The server package will contain the implementation of the remote interface. The client package contains the servlet which talks to the server implementation via RMI.



 
 
>>> More Java & J2EE Articles          >>> More By Richard Yumul
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

JAVA & J2EE ARTICLES

- More Java Bugs Lead to More Attacks
- Oracle's Java One Brings News, Surprises
- Oracle Patches Java Runtime Environment
- Apple Syncs Java Update with Oracle
- Spring 3.1 Java Development Framework Compat...
- Jelastic Java PaaS Availability and Pricing ...
- NetBeans 7.1 Released, Supports JavaFX 2
- SolarWinds Releases Newest Version of Java M...
- Free Monitoring Tool for Java Apps on Heroku
- Heroku Adds JCloud Platform Support, Java 7 ...
- Java SE 8 Speculation in Full Swing
- Java SE 7 Now Available
- New JVM Language and Java Reporting Tool
- Java 7 Release Update and New Eclipse Toolkit
- The Best Java Netbeans IDE Plugins

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: