Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 

In this exercise, you will add an operation to the stock IDL file, implement it, generate Java code from the IDL file and then compile and run the distributed stock application.

The order in which you will edit these files is the same order that you will follow for normal CORBA application development. These steps are indicated by notes within square brackets at the beginning of each task.

This exercise can be completed using either Sun's Java 2 ORB or Inprise's VisiBroker 3.x for Java. Notes on these products are available:

Prerequisites

Skeleton Code

Tasks


  1. [Modify the IDL file] First edit the IDL file. There is already a definition for the module and interface. The interface, however, does not have any way of setting a price quote of a stock. Within the interface definition, add an operation named setQuote(). It should take an in parameter of type Quote. Remember that these are IDL types, not Java types.

  2. [Run IDL Compiler] At the command line, run the IDL compiler to generate Java code from the IDL file.
    Sun JavaIDL idltojava -fno-cpp stock.idl
    Inprise VisiBroker idl2java stock.idl

  3. [Compile the generated Java code] Now compile the generated Java code using the standard Java compiler. Compile it in the generated StockObjects directory.

    Sun JavaIDL javac *.java
    Inprise VisiBroker vbjc *.java

  4. [Examine the generated Java files] All the files will be generated into the StockObjects directory because the IDL file defines a module StockObjects. (The purpose of each file is described in more detail in the course notes.)

    Look carefully at the file Stock.java - - this is the interface that you will have to implement.

  5. [Create "Impl" Classes] The skeleton code file we have given you, StockImpl.java has most of the implementation you will need. To finish, add a body to the method setQuote().

    Note: Be sure not to confuse the skeleton files that Magelang provides as part of out Magercises with CORBA skeleton files. The Magelang files appear as links at the beginning of the Magercise, and are files that you are to use as a starting point for coding. CORBA skeleton files are generated from IDL files, end with the name ImplBase and are used for creating classes that implement CORBA interfaces.

  6. [Create Server Class] Now look at the file StockServer.java. This class is a java application that starts up the orb, instantiates a StockImpl instance, connects it to the ORB, and prints out a stringified reference to it.

    There is nothing for you to do except look at the file. Look carefully at each line.

  7. [Create Client Class] In the file StockClient.java, you will find code to instantiate the orb, read in a stringified reference to the remote object, and call the getQuote operation on it. Again, there is nothing for you to do except look at the file. Look carefully at each line.

    Note: Most of the Magercises are applications that have separate "server" and "client" portions. The server portions instantiate distributed objects, the client portions use them. This is not a requirement of CORBA programs, any application that is part of a CORBA environment can both instantiate and use distributed objects. The client and server pattern is used by the Magercises for convenience and consistency. Some later Magercises dispense with this convention entirely.

  8. [Compile the program] Now compile the program using the standard Java compiler.

    Sun JavaIDL javac -classpath . *.java
    Inprise VisiBroker vbjc *.java

  9. [Run the Server program]

    The server needs to run as a separate process. In DOS/Windows, you will use the start command. In UNIX, you will use the & (ampersand).

    The Server outputs an IOR (or stringified reference) to a file and to the console for the Stock object it creates. The name of the file is passed as the first argument to the server.

    To run the server, use the normal java command. If you are using VisiBroker, you can use the vbj command instead. vbj is just like java, except it sets up the CLASSPATH variables automatically.

    Putting it all together:
    Sun JavaIDL
    java -cp . StockServer gii.ior
    Inprise VisiBroker
    vbj StockServer gii.ior

  10. [Run the Client program]

    The client reads the stringified object reference of the stock object created by your server. A file containing the stringified object reference is passed as an argument to the client.

    Sun JavaIDL java -cp . StockClient gii.ior
    Inprise VisiBroker vbj StockClient gii.ior

  11. [Kill the Server] Don't forget to kill the server.

Where help exists, the task numbers above are linked to the step-by-step help page.

This exercise has walked you through the steps of writing, compiling, and running a portable CORBA application. Most other exercises will follow a similar pattern.

Solution Source

Demonstration

When you start the server it should output:

Created GII:
IOR:000000000000001b49444c3a53746f636b4f626a6563
74732f53746f636b3a312e30000000000001000000000000
0034000100000000000d36393039636b6e39613234380000
049c00000018afabcafe00000002ee387de1000000080000
000000000000

The value of the IOR string will of course be different.

When you run the client it should output:

Global Industries Incorporated is currently selling at 28.0
Volume is 0

Next Magercise

Magercises

Short Course

Copyright © 1998-1999 MageLang Institute. All Rights Reserved.


[ This page was updated: 3-Dec-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.