`
lee79
  • 浏览: 106754 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Efficient Java RMI Hessian

阅读更多
New Protocol Offers Simple, Efficient Java RMI

Burlap/Hessian is an alternative remote object invocation and Web services protocol that's available as an open source Java framework. Learn how it enables simpler, more efficient Java RMI. 
he Burlap/Hessian protocol is an alternative remote object invocation and Web services protocol supplied as an open source Java framework through Caucho Technology. If you want POJO (Plain Old Java Objects)-based object distribution, efficient serialization, distributed Java objects that hardly need a Web container, maximal ease of use, and a minimal learning curve, then you should give Burlap/Hessian a serious look. Although primarily a Java remote object invocation protocol, it offers stable implementations for C++, C#, Python, and PHP as well.

I first ran across Burlap/Hessian while working with the Spring framework. Its exceptional simplicity and efficiency inspired me to write this article. I begin with an explanation of how the protocol works, follow that with a demonstration for establishing a Hessian-based distributed architecture, and close with some practical suggestions for how to use the protocol.

Burlap/Hessian Architecture
Burlap and Hessian are peer specifications of the same conceptual protocol. The major difference between the two is the implementation of the serialization mechanism. Burlap serializes objects over the Web using XML; Hessian serializes objects using a proprietary (very compact) binary format. According to its authors, the protocol's dull "textile" names reflect its boring simplicity—which I find to be anything but boring.

Burlap/Hessian remote objects are just ordinary Java objects that implement some interfaces. They don't require special proxy, home, or remote classes. One of the inherent benefits of this object-and-interface model is that it promotes the good object-oriented design practice of design by interface. Design by interface mandates that client objects depend on abstractions and never on concrete classes.

Furthermore, the Burlap/Hessian protocol fully leverages the host environment's Web container capabilities. Hessian server is nothing more than a servlet that can dispatch Burlap or Hessian serialized objects via the Web. Hessian remote objects are configured in a web.xml file (as examples will demonstrate shortly).

As previously mentioned, Burlap/Hessian serializes Java objects using a proprietary serialization mechanism. The serialization process is completely transparent to the application (i.e., you do not need to implement any special interfaces to make objects serializable). Burlap/Hessian serialization is very efficient, and the produced serialized object snapshots (either XML or binary) are very compact.

 


 
Application Development in a Hessian-Based Distributed Architecture
This section demonstrates the typical steps involved in establishing a Hessian-based distributed architecture. The sample scenario involves two applications: one for inventory management and the other for order management. The inventory management app is a standalone J2EE application that enables its users to track and manage their parts inventory over the Web. This example takes a plain Java object (InventoryTracker) and exposes it to the ordering management application that needs inventory lookup services.

Step 1. Enable server components for the remote invocation
The first step in making inventory-tracking objects available remotely via Hessian is to make sure that objects of interest implement some plain Java interfaces. If the object you plan to expose remotely does not implement any interfaces, you need to extract the appropriate business interface from it, and implement that interface. This step is actually the only requirement that Hessian imposes on your server-side objects.

[Hint: If you want to expose the server objects but you cannot make any changes to them, you can apply the Adapter design pattern. Expose the Adapter object that implements the needed interface and then have it delegate the remote method invocations to the actual business component.]

As previously stated, this example exposes the plain Java object InventoryTracker. This object tracks the item inventory, and the order management application can use it to verify if the items are available. The following code makes InventoryTracker implement the ItemAvailabilityTracker interface:


public class PartsTracker implements ItemAvailabilityTracker{
     
    /**
     * Default constructor
     *
     */
    public PartsTracker() {
        
    }//end constructor
    
    /** Purely fabricated business method that verifies if the refurbished part is 
     *  available on the inventory.
     * @param partID
     * @return boolan - true if the part ID is not empty, null or longer than 5 digits
     *                  (invented part numbering standard)
     */
    public boolean isPartAvailable( String partID ) {

The following is the ItemAvailabilityInterface:


public interface ItemAvailabilityTracker {
    
    /** Method verifies if the part is available on the inventory
     * 
     * @param partID
     * @return true if available
     */
    public boolean isPartAvailable( String partID );

Step 2. Configure the server component for the remote invocation (over the Web)
In order to make the ItemAvailabilityTracker service available over the Web, the server object and the interface it implements have to be registered with the Hessian Servlet (org.caucho.Hessian.HessianServlet) in the web.xml file of the existing inventory management Web application.

Using the standard Servlet parameter settings in the web.xml file, specify the service implementation object (parameter: home-class) and the interface (parameter: home-api) of the service that is going to be accessible by the Java clients:


  <display-name>Sample application for Hessian</display-name>
  <description>
     Sample host application for Hessian remoting
  </description>
  <servlet>
   <servlet-name>invoker</servlet-name>
   <servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
    <init-param>
      <param-name>home-class</param-name>
      <param-value>com.acme.inventory.PartsTracker</param-value>
    </init-param>
    <init-param>
      <!— This interface name will be requested from client's HessianProxyFactory—>
      <param-name>home-api</param-name>
      <param-value>com.acme.inventory.ItemAvailabilityTracker</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <url-pattern>/invoker</url-pattern>
    <servlet-name>invoker</servlet-name>
  </servlet-mapping>

The Burlap/Hessian protocol fully leverages the Web container capabilities of the host environment.

As you can see, the Hessian server is nothing more than a servlet that can dispatch either Burlap or Hessian serialized objects via the Web. As the service provider, you can choose whether to have a special-purpose Web application for the remote services or to have an already functional Web application expose the remote objects.

Step 3. Invocation on the client
In order to invoke the objects remotely, the client application needs to have a Burlap or Hessian jar in the classpath, as well as in the interface for the service being invoked. In this case, the application needs the interface com.acme.inventory.ItemAvailabilityTracker. The following code demonstrates the typical steps required to obtain the object remotely and to invoke its services:


   String url = "http://localhost:8080/inventory/invoker";

   HessianProxyFactory factory = new HessianProxyFactory();
   ItemAvailabilityTracker tracker = (ItemAvailabilityTracker)   
                                  factory.create(ItemAvailabilityTracker.class, url);

     if ( tracker.isPartAvailable( itemID ) ) {
            
         System.out.println( "Item " + itemID + " ordered." );
        
     }else {
            
         System.out.println( "Item " + itemID + " not available for ordering." );
            
    }//end else

It is actually a very simple interaction. The client code needs to know the URL of the Hessian servlet. It will use this URL along with the interface class to obtain the interface implementation from the HessianProxyFactory.

As you probably noticed, the only actual coupling point between the clients' application code and the Burlap- or Hessian-specific classes is through the HessianProxyFactory. Compared with EJB or even RMI, Hessian's client dependency on the API is quite minimal, and if you use an Inversion of Control (IoC) container such as Spring, your client code will effectively have no dependencies on the framework.

The most attractive aspect of the Burlap or Hessian client-to-server interaction is that it is accomplished in a true Web services fashion. The client effectively locates the remote object (as a URL) over HTTP (or HTTPS), and from that point it interacts with the object in a true POJO fashion.

 


 
Suggested Practical Uses for Burlap/Hessian
The following are practical implementations for Burlap/Hessian that can benefit your development today:

 

  • With Spring Framework
    If you develop enterprise applications using the Spring framework, Burlap and Hessian are already available to you through the framework in a completely transparent fashion. Spring does not require your application to use a particular remoting protocol, since the framework transparently injects the remote dependencies. In this scenario, I recommend using the Burlap/Hessian protocol to take full advantage of Hessian's performance, simple Web application deployment model, and ease of use. With Spring, switching from the Burlap or the Hessian protocol to a more conservative JSR-endorsed protocol such as RMI is a matter of changing configuration.
  •  

  • For Localized Object Remoting
    Some developers may take issue with using a Java distributed computing framework that is not endorsed by the official Java specification. However, if you have to perform distributed computing between just a few applications, Hessian may be the practical way to go. You would save a significant amount of money that you would otherwise spend on EJB training, development, administration, and maintenance. Moreover, Hessian's lightweight architecture and mild—almost non-existent—coupling with the application code will keep your applications from becoming strategically dependent on this proprietary framework.
  •  

  • Federation of Portable Devices
    The authors of the Burlap/Hessian protocol have proposed using it for small devices such as cell phones. This is a rather interesting proposal, and I think it warrants serious consideration. Its small deployment footprint (it can be deployed with only a few core classes), efficient serialization algorithm, and simple infrastructural requirement make Burlap/Hessian a good candidate for a remote protocol implementation in small devices.
  •  

     

    Edmon Begoli is a software architect with 10 years of professional experience on large commercial and public software projects. He currently works for a large public institution.
    分享到:
    评论

    相关推荐

      基于JAVA RMI的聊天室

      **基于JAVA RMI的聊天室** Java Remote Method Invocation(RMI)是Java平台提供的一种用于在分布式环境中调用远程对象的方法。在这个“基于JAVA RMI的聊天室”项目中,开发者利用RMI技术构建了一个简单的多用户...

      java RMI技术实现的网络聊天室

      Java RMI(Remote Method Invocation)技术是Java平台中用于分布式计算的一种机制,它允许一个Java对象调用远程计算机上的另一个Java对象的方法。在本案例中,“java RMI技术实现的网络聊天室”是一个使用RMI构建的...

      javaRMI反序列化漏洞验证工具

      Java RMI(Remote Method Invocation,远程方法调用)是一种Java技术,允许在分布式环境中执行远程对象的方法。这个技术的核心是序列化和反序列化过程,它使得对象可以在网络上进行传输。然而,这个特性也可能引入...

      java RMI实现代码

      Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种分布式计算技术,它允许在不同的Java虚拟机之间进行远程对象的调用。RMI使得开发者可以像调用本地对象一样调用网络上的对象,极大地简化了...

      java rmi java rmi

      根据提供的文件信息,我们可以深入探讨Java RMI(Java Remote Method Invocation)的相关知识点,包括其概念、原理、体系结构以及一个具体的示例。 ### RMI的概念 RMI是一种Java技术,它允许开发者创建分布式应用...

      java_rmi.rar_RMI java_java.rmi

      Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种分布式计算技术,它允许Java对象在不同的网络环境中进行交互,就像它们在同一个进程内一样。RMI是Java在分布式系统领域的核心特性,极大地...

      JavaRMI快速入门

      Java Remote Method Invocation(Java RMI)是Java编程语言中用于在网络间进行远程对象调用的技术。它是Java平台的标准部分,允许程序员在分布式环境中调用对象的方法,就像它们在同一台计算机上一样。Java RMI对于...

      java rmi 参考文档

      ### Java RMI (Remote Method Invocation) 概念与实践 #### 一、Java RMI简介 Java RMI(Remote Method Invocation)是一种允许调用不同Java虚拟机(JVM)上方法的机制。这些JVM可能位于不同的机器上,也可能在同一...

      java RMI简单Demo

      Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种分布式计算技术,它允许在不同网络节点上的Java对象之间进行透明的交互。在Java RMI中,一个对象可以调用另一个位于不同JVM(Java虚拟机)...

      JavaRMI超棒书

      ### Java远程方法调用(Java RMI)核心概念与应用详解 #### 一、Java RMI简介 Java远程方法调用(Java Remote Method Invocation,简称Java RMI)是一种用于实现远程对象之间通信的技术,它是Java平台的一个核心...

      RMI.rar_Java RMI_java.rmi_java.rmi.Remot_remote

      Java RMI(远程方法调用)是Java编程语言中的一项核心技术,自JDK 1.1版本起就被引入,用于构建分布式系统。RMI允许Java对象在不同的Java虚拟机(JVMs)之间进行交互,仿佛这些对象是在同一台机器上一样。这种技术的...

      Java RMI 简单示例

      Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种用于分布式计算的技术,它允许一个Java对象调用另一个在不同 JVM(Java虚拟机)上的对象的方法。这个简单的示例展示了如何创建一个基本的...

      JAVA RMI.rar_Java RMI_ME_RMI java_rmi

      Java Remote Method Invocation (RMI) 是Java平台中用于构建分布式应用程序的一种重要技术。RMI允许Java对象在不同的Java虚拟机(JVM)之间调用方法,从而实现了远程对象的透明访问。这个RAR文件"JAVA RMI.rar"包含...

      JavaRMI.pdf

      Java RMI(Remote Method Invocation)是Java编程语言中用于实现远程过程调用的一种技术。它允许运行在客户机上的程序调用位于远程服务器上的对象的方法,从而实现分布式计算。RMI的核心思想是通过接口隐藏底层网络...

      javaRMI完整版.pdf

      Java RMI 完整版 Java Remote Method Invocation(RMI)是一种分布式对象技术,允许使用 Java 编写分布式对象,不同的 Java 虚拟机(JVM)之间进行对象间的通讯。这使得应用程序(Application)可以远程调用方法,...

      JAVA RMI简单例子

      Java RMI(Remote Method Invocation,远程方法调用)是Java平台提供的一种分布式计算技术,它允许在不同的Java虚拟机之间进行方法调用,仿佛这些方法都在本地对象上执行一样。这个"JAVA RMI简单例子"旨在帮助我们...

      Java RMI中文规范

      Java RMI(Remote Method Invocation,远程方法调用)是Java平台中用于构建分布式对象系统的关键技术。它允许Java应用程序在不同Java虚拟机(JVM)之间进行远程方法调用,这些虚拟机可能位于同一台计算机或网络上的...

      java rmi HelloWorld版(源码)

      Java RMI,全称为Remote Method Invocation,是Java平台上的一个标准API,用于实现分布式计算,使得在不同Java虚拟机(JVM)上的对象能够互相调用方法。这个"java rmi HelloWorld版(源码)"的压缩包文件提供了一个...

      JAVA RMI

      **JAVA RMI(远程方法调用)详解** Java RMI(Remote Method Invocation)是Java平台上的一个核心特性,它允许Java程序在不同的JVM(Java虚拟机)之间进行分布式计算,实现了对象间的远程调用。RMI使得开发者可以像...

      Rmi.rar_Java RMI_RMI java_java RMI 线程_rmi

      Java RMI(Remote Method Invocation)是Java平台提供的一种分布式计算技术,它允许一个Java对象调用网络另一端的Java对象的方法,仿佛它们在同一个进程中执行。这个教程“Rmi.rar”显然包含了关于如何使用Java RMI...

    Global site tag (gtag.js) - Google Analytics