A Sip From The Firehose: Friday, November 28, 1997

投稿者: : David Intersimone

概要: Java Distributed Object Computing Part One - CORBA

Friday, November 28, 1997
Eureka, CA

Java Distributed Object Computing Part One - CORBA

I am visiting my parents for the Thanksgiving weekend. After eating several helpings of turkey, stuffing, vegetables and pumpkin pie I knew I needed to work off some of the meal. I could have gone for a walk, gone to the gym, or even played some tennis. Instead I decided to burn some calories by firing up JBuilder Client/Server Suite and spent the rest of the weekend exploring Java distributed object computing with CORBA and RMI (didn't you?).

If you read the transcript of Del's opening keynote at BorCon97 on Information Networks, you would know that distributed object computing is one of the technology focus areas for our strategy. Open, scalable multi-tier applications are usually built using one or more of the industry standards for distributed object computing including Microsoft's DCOM (Distributed Object Component Model), Object Management Group's CORBA (Common Object Request Broker Architecture), and JavaSoft's RMI (Remote Method Invocation). In part one of this column I will focus on Java and CORBA. In part two, I'll cover Java and RMI.

JBuilder Client/Server Suite

JBuilder Client/Server Suite supports building multi-tier Java applications, applets and JavaBeans using CORBA or RMI. JBuilder ships with version 1.1 of the Java VM which includes RMI. JBuilder also ships with Visigenic's VisiBroker for Java 3.0 "Development Version" which supports CORBA 2.0, JavaIDL, and IIOP. We announced JBuilder Client/Server Suite's support for CORBA with a licensing agreement for the Development Version of VisiBroker for Java. Of course you now know that we also announced the definitive agreement to acquire Visigenic (just like in real life sometimes a courtship turns into a marriage). JBuilder Client/Server also includes wizards that simplify the development of CORBA and RMI clients and servers.

CORBA (Common Object Request Broker Architecture)

CORBA is an industry standard managed by the Object Management Group (OMG). It is a multi-vendor (more than 800 vendors), multi-language (C, C++, COBOL, Java, and others), and mult-platform standard. The CORBA/IIOP 2.1 specification is available electronically on the web. If you are new to CORBA, OMG has a great place to start. For a quick overview of CORBA check out Doug Schmidt's article.

CORBA is ideally suited for building distributed applications in heterogeneous environments. CORBA is also useful for building distributed object interfaces on top of existing legacy non-object applications.

CORBA provides for high level language bindings, static and dynamic method invocations, local and remote transparency, built-in security and transactions, polymorphic messaging, and much more. At the base of CORBA is the ORB (Object Request Broker). Think of the ORB like you would a computer's motherboard bus. In a computer many different devices all communicate on the same bus. For CORBA objects that run on any number of client and server machines, the ORB is the middleware that allows all CORBA objects to communicate with each other regardless of whether they are on the same computer, on an intranet, or on the Internet. The ORB receives the call from a client object, finds the object that can handle the request, passes any parameters, invokes the method and returns and results. Internet InterOperable Object (IIOP) is the protocol for communication between CORBA clients and CORBA servers.

The CORBA includes a range of services and facilities that CORBA objects can use. CORBA services include event notification, transactions, naming, security, trading, lifecycles, persistence, concurrency control, relationships, externalization, query service, licensing, time, collections, change management, and properties. CORBA facilities include user interface, information management, systems management, task management and industry specific vertical market facilities. For more information on CORBA services and facilities check out the article by Alan L. Pope.

Interface Definition Language (IDL)

For most developers the starting point for a CORBA application is the Interface Definition Language (IDL). The IDL defines the interfaces that a client object will call and the server object will implement. CORBA IDL is a declarative language supporting C++ style syntax for keywords, preprocessor commands, pragmas, constants, types and methods. An IDL to Java compiler is used to convert the IDL into language specific client stubs and server implementation skeletons.

Visigenic VisiBroker for Java

Visigenic's VisiBroker for Java is the first CORBA 2.0 Object Request Broker (ORB) that is written completely in Java (both the Client and Server). JBuilder Client/Server Suite includes the "Development Version of VisiBroker for Java version 3.0. It includes the VisiBroker for Java ORB, GateKeeper, Smart Agent, Interface Repository Server, Object Location Service, Object Activation Daemon, OSFind, VBJ, Java2IIOP Stub and Skeleton Generator, Java2IDL Compiler and IDL2Java Compiler. Java developers have all the tools required to build and test CORBA applications. Deployment licenses are required for all Visigenic products. VisiBroker is supported on different platforms including Windows 95, Windows NT, Solaris, HP/UX, AIX, IRIX, and MVS.

Available additionally from Visigenic are additional enterprise products for VisiBroker including the Naming Service, Event Service, GUI Administration and Development Tools, SSL Security Service, and VisiBridge for DCOM/CORBA interoperability. For more information go to the Visigenic web site. Visigenic also has a version of Visibroker for C++ developers.

Creating a JBuilder CORBA Application

There are seven common steps to create a JBuilder CORBA application.
    1) Define the interface for the CORBA object in one of two ways:
      a) using IDL
      • use an existing IDL file - add the IDL file to the project. Select the node and edit the IDL file to define the interfaces.
      • create a new IDL file - use the IDL File Wizard by selecting File|New. Select the CORBA tab and double-click the IDL icon to bring up the Generate IDL File Wizard
      b) using Java
      • use the Java IIOP wizard - use the Java IIOP Wizard to create a new Java interface that can generate client stubs and server skeletons. To bring up the Java IIOP Wizard, select File|New, select the CORBA tab and double-click the Java IIOP icon to bring up the Generate Java IIOP file wizard.

      The following Visigenic VisiBroker example shows an IDL file for a bank account management application that has interfaces for managing bank accounts and retrieving account balances:

      // Bank.idl module Bank { interface Account { float balance(); }; interface AccountManager { Account open(in string name); }; };

    2) Use the CORBA Settings Wizard (choose Tools|CORBA Settings) to compile the interface definition file producing Java source files containing the client stubs, server skeletons, CORBA helper files and example implementation files (look for files named _example*.*). An example implementation generated for the Account interface follows.

    package visibroker.samples.bank;
    /**
    Java Class Bank._example_Account
    Source File Bank/_example_Account.java
    IDL Source File C:/JBuilder/samples/visibroker/samples/bank/Bank.idl
    IDL Absolute Name ::Bank::Account
    Repository Identifier IDL:Bank/Account:1.0
    IDL definition:
        interface Account {
          float balance();
        };
    */
    public class _example_Account extends Bank._AccountImplBase {
      /** Construct a persistently named object. */
      public _example_Account(java.lang.String name) {
        super(name);
      }
      /** Construct a transient object. */
      public _example_Account() {
        super();
      }
      /**
      Operation: ::Bank::Account::balance.
        float balance();
      */
      public float balance() {
        // implement operation...
        return 0;
      }
    }
    

    3) Implement the CORBA interface - The next step is to add the Java code for the implementation of your object(s) methods. You can start with the example files that were created by the wizard or you can just type in new source code. An example implementation for the Account interface and the balance method follows:

    package visibroker.samples.bank;
    public class AccountImpl extends Bank._AccountImplBase {
      public AccountImpl(float balance) {
        _balance = balance;
      }
      public float balance() {
        return _balance;
      }
      private float _balance;
    }
    

    4) Create a CORBA server application - A CORBA server application is needed to make the CORBA object available to the ORB so that remote clients can access the object. You can use the Generate CORBA Server Wizard (Wizards|Generate CORBA Server) to build a simple server. The generated server code might look like:

    package visibroker.samples.bank;
    public class Server {
      public static void main(String[] args) {
        // Initialize the ORB.
        org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
        // Initialize the BOA.
        org.omg.CORBA.BOA boa = orb.BOA_init();
        // Create the account manager object.
        Bank.AccountManager manager = 
          new AccountManagerImpl("BankManager");
        // Export the newly create object.
        boa.obj_is_ready(manager);
        System.out.println(manager + " is ready.");
        // Wait for incoming requests
        boa.impl_is_ready();
      }
    }
    

    5) Create the client application - it's time to create the user interface (if it has one) for the client application. Your client could be a Java command mode application, GUI application or applet housed in an HTML document. Use JBuilder's visual designer and JavaBeans Component Library (JBCL) to create a user interface that uses the CORBA object(s) interfaces. JBuilder Client/Server Suite comes with several sample CORBA applications (see the JBuilder/samples/visibroker/samples/ folders). A simple command mode client application might look like the following:

    package visibroker.samples.bank;
    public class BankClient {
      public static void main(String[] args) {
        // Initialize the ORB.
        org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
        // Locate an account manager object
        Bank.AccountManager manager =
                Bank.AccountManagerHelper.bind(orb, "BankManager");
        // call the account manager and account object methods 20 times
        for (int i=1;i<=20;i++) {
          // use the loop counter as the named account
          String name = Integer.toString(i);
          // Request the account manager to open a named account.
          Bank.Account account = manager.open(name);
          // Get the balance of the account.
          float balance = account.balance();
          // Print out the balance.
          System.out.println
            ("The balance in " + name + "'s account is $" + balance);
        }
        try {
          // wait for a keystroke 
          System.in.read();
        }
        catch (Exception e) {
          System.out.println ("exception occured: " + e);
        }
      }
    }
    

    6) Build the Java project - this will compile all the Java source files creating class files for all project classes including the client and server applications.

    7) Deploy the application - use JBuilder's deployment wizard (Wizards|Deployment Wizard) to help package your application's class files and any other runtime class libraries into JAR or ZIP files for easy deployment of client and server applications.

Running a JBuilder CORBA Application

Once you have created your implemented your defined interfaces, built your client and server applications, compiled and deployed all the right pieces, the next step is to try them out. On each client and server machine you need to first run VisiBroker's SmartAgent, OSAgent.exe. Under Windows 95 just run the OSAgent.EXE. Under Windows NT run OSAgent.EXe with a -C command line option. On each server machine, run your CORBA server application. On any number of client machines, run your client application. VisiBroker's SmartAgent will route client object requests to one of the servers you have running.

CORBA Next Steps

Of course there is more to building a robust CORBA application. Visigenic's web site contains a wealth of information including product information, white papers, consulting and training services, events and seminars, partners, and success stories. Their web site also includes a great recommended reading list. Once you try JBuilder Client/Server and Visigenic's VisiBroker for Java I think you agree that the marriage of Visigenic and Borland is a match made in enterprise heaven. See what Visigenic's founder Roger Sippl has to say about the acquisition.

Stay Tuned for Java Distributed Object Computing Part Two - RMI

Do you have any Thanksgiving turkey left? In a second helping of this column we'll take a look at another way to build distributed applications using Java's RMI (Remote Method Invocation).

David Intersimone
davidi@inprise.com


Server Response from: ETNASC03