Make your own free website on Tripod.com

The Interface Definition Code Comparison

Gopalan Suresh Raj

The Interface

Whenever a client needs some service from a remote distributed object, it invokes a method implemented by the remote object. The service that the remote distributed object (Server) provides is encapsulated as an object and the remote object's interface is described in an Interface Definition Language (IDL). The interfaces specified in the IDL file serve as a contract between a remote object server and its clients. Clients can thus interact with these remote object servers by invoking methods defined in the IDL.

MTS - The IDL file shows that our MTS server implements a dual interface. COM supports both static and dynamic invocation of objects. For the static invocation to work, The Microsoft IDL (MIDL) compiler creates the proxy and stub code when run on the IDL file. These are registered in the systems registry to allow greater flexibility of their use. This is the vtable method of invoking objects. For dynamic invocation to work, COM objects implement an interface called IDispatch. As with CORBA or Java/RMI, to allow for dynamic invocation, there has to be some way to describe the object methods and their parameters. Type libraries are files that describe the object, and COM provides interfaces, obtained through the IDispatch interface, to query an Object's type library. In COM, an object whose methods are dynamically invoked must be written to support IDispatch. The MTS IDL file also associates the IChecking interface with an object class Checking as shown in the coclass block. Also notice that in MTS, each interface is assigned a Universally Unique IDentifier (UUID) called the Interface ID (IID). Similarly, each object class is assigned a unique UUID called a CLasS ID (CLSID). COM gives up on multiple inheritance to provide a binary standard for object implementations. Instead of supporting multiple inheritance, COM uses the notion of an object having multiple interfaces to achieve the same purpose. This also allows for some flexible forms of programming.

The Checking Account Server component has methods for managing a typical Bank Checking Account. Consequently, it has methods to create an account, and credit & debit money from the Account. Consequently, we define different methods like createAccount(), credit(), debit(), getBalance() and getCustomerName().

EJB - Notice that unlike MTS, EJB uses a .java file to define it's remote interface. This interface will ensure type consistency between the EJB client and the EJB Server Object. Every remotable server object in EJB has to extend the javax.ejb.EJBObject class. Similarly, any method that can be remotely invoked in EJB may throw a java.rmi.RemoteException. java.rmi.RemoteException is the superclass of many more RMI specific exception classes. We define an interface called Checking which extends the javax.ejb.EJBObject class. Also notice that all the remote methods like createAccount(), credit(), debit(), getBalance() and getCustomerName() throw a java.rmi.RemoteException.

MTS - IDL Definition

  EJB - Home and Remote Interfaces
[
 uuid (6B6EBD40-01C0-11d3-97EE-006097A7D34F),
 version (1.0)
]
library Bank {
 importlib ("stdole32.tlb");

 /*
  * Checking Interface for business rules
  */

 [
  uuid(6B6EBD41-01C0-11d3-97EE-006097A7D34F),
  dual
 ]
 interface IChecking : IDispatch {
  HRESULT createAccount ([in] int key,
                                    [in] BSTR name,
                                    [in] double startingBalance);

  HRESULT credit ([in] double amount,
                        [in] int key);

  HRESULT debit ([in] double amount,
                       [in] int key);

  HRESULT getBalance ([in] int key,
                               [out, retval] double* balance);

  HRESULT getCustomerName ([in] int key,
                                          [out, retval] BSTR* name);

 }

 /*
  * Checking class
  */

 [
  uuid(6B6EBD42-01C0-11d3-97EE-006097A7D34F)
 ]
 coclass Checking {
  interface IChecking;
 };
}

  Home Interface - CheckingHome.java

package Bank;

import javax.ejb.*;
import java.rmi.*;

public interface CheckingHome extends EJBHome {
 
 Checking create () throws CreateException, RemoteException;
 
}

  Remote Interface - Checking.java

package Bank;

import javax.ejb.*;
import java.rmi.*;

public interface Checking extends EJBObject {
 
  void createAccount (int key,
                              String name,
                              double startingBalance)
     
throws RemoteException;
  void credit (double amount,
                   int key)
throws RemoteException;
  void debit (double amount,
                  int key)
throws RemoteException;
  public double getBalance (int key) throws RemoteException;
  public String getCustomerName (int key) throws RemoteException;
 
}

Bank.idl

CheckingHome.java & Checking.java

 

Back to EJB vs MTS

click here to go to
My Advanced Java / J2EE Tutorial HomePage...

click here to go to
My COM+ / DNA Tutorial HomePage...

click here to go to
My CORBA Tutorial HomePage...

 


Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since May 04,1999.

Last Updated : May 04,'99

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-2000, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site are trademarks of their respective owners.