Overview: creating a distributed application in JBuilder

Distributed objects are objects that can be accessed remotely. This means that a distributed object can be used like a regular object, but from any machine on the network. The physical location of the object is not critical to the user of the object.

CORBA provides the mechanisms by which objects transparently make requests and receive responses. The CORBA ORB is an application framework that provides interoperability between objects, built in (possibly) different languages, running on (possibly) different machines, in heterogeneous distributed environments.

JBuilder includes a set of visual tools for creating 100% Pure Java distributed applications, applets, and JavaBeans for the enterprise. JBuilder supports CORBA through the VisiBroker ORB. Outline: creating a CORBA application in JBuilder provides an overview of the steps required to create a distributed application using CORBA.

JBuilder supports RMI through the 100% Pure Java standard. RMI provides the mechanisms by which objects transparently make requests and receive responses. RMI is the application framework that provides interoperability between objects running on different Java virtual machines (VM). Outline: creating an RMI application in JBuilder provides an overview of the steps required to create a distributed application using RMI.

JBuilder Client/Server also includes InterClient, a tool for developers who want to create Java-based client-server applications. Java developers should be able to seamlessly swap RDBMS back ends underneath their JDBC applications. InterClient provides a small footprint, easy-to-maintain RDBMS (InterBase) as the back end to JDBC applications. An InterBase back end is an ideal solution because it's small, economical, and conforms to the same SQL standards as the JDBC.

If you are new to distributed applications, a good source for information and examples is http://www.omg.org/news/begin.htm, the OMG's CORBA for Beginners Web page.

If you would like more information on the differences, advantages, and disadvantages of each approach to distributed computing, a good source for information is Part 4 of the Orfali and Harkey book "Client/Server Programming with JAVA and CORBA".

Some remote object terminology follows. For other object terminology, see the Glossary.

This overview contains the following topics:

Outline: creating a CORBA application in JBuilder

The following steps outline how to use JBuilder's distributed objects features to create a CORBA application. For a tutorial recreating one of the JBuilder sample projects, see Tutorial: creating distributed applications in CORBA.

  1. Define the interface for the CORBA object.

    The interface is used to generate interface definitions and client stubs and server skeletons. To support the distribution of objects implemented in a variety of programming languages, an Interface Definition Language (IDL) file is used to define the services offered by a particular distributed object. CORBA then defines a wire protocol (Internet InterORB Protocol, IIOP) for making requests to an object and for the object to respond to the application making the request. The options for defining the interface are IDL, Java, and Java-to-IDL.

  2. Compile the CORBA interface definition file (IDL or Java).

    Compile the interface definition file with the Build command. When the interfaces are compiled, a Java client can transparently invoke an IDL object that resides on a remote server. Compiling the interface definition file generates client stubs, server skeletons, and various helper files. These files stuff information into an IIOP message that can be sent over the wire.

    The generated files are read-only and are generated to your OUTPATH/Generated Source directory.

    Select Build|Build to compile the entire project, or right-click on the IDL or Java file and select Build to compile only the interfaces.

  3. Implement the CORBA interface.

    You must provide an implementation for the CORBA interface file. The implementation is done in Java. To help you get started with the implementation, some example files are created when the interface definitions are compiled. The example files have a file name of the format _example*.*

    Some example implementation files are located in the sample directories found beneath the JBuilder/samples/visibroker/samples/ directory of your JBuilder installation.

  4. Create a CORBA server.

    A CORBA server needs to be created to make the CORBA object available to the ORB (Object Request Broker). This is necessary so that remote clients can access the object. You can create a simple server by selecting File|New, then selecting CORBA Server from the VisiBroker tab. Enter the appropriate information. A new file called MyCORBAServerClass1.java, by default, will be added to the project. Edit the server code to throw exceptions as applicable.

  5. Create the client.

    The client can be either a Java applet or an application. You should be able to bind to the remote object in the client. Edit the client code to catch exceptions as applicable.

    In the JBuilder/samples/visibroker/samples/ subdirectories of your JBuilder installation are several sample CORBA applications. See the Bank application for an example of how to create the client.

  6. Compile the Java files by selecting Build|Build.

  7. Deploy the application.

    Use the Deployment Wizard, or see the deployment topic in the User's Guide for more information, or see Deployment in the "Tutorial: creating distributed applications in CORBA".

Running a CORBA application

This topic briefly discusses how to run a CORBA application. For more information, look for documentation updates on www.borland.com/techpubs/jbuilder/.

  1. Run the OsAgent by selecting Tools|VisiBroker Smart Agent. This option is toggled on when there is a check mark to the left, and is toggled off when there is not a check mark to the left. The OsAgent is the object location service. The client finds the server by using OsAgent and the server advertises services by using OsAgent-it's how they find each other. For more information, see Building the Example Programs in the "Tutorial: creating distributed applications in CORBA".

  2. Start the CORBA Server by running MyCORBAServerClass1.java (or whatever you've named it). Running this file invokes the virtual machine and offers other special features. For command line options and more information, see "Commands" in the VisiBroker for Java Reference Guide, at http://www.visigenic.com/techpubs/htmlhelp/vbj30/ref/frames/vbj_p.htm.

    To run Server.java, right-click on the file in the Navigation pane, then select Build.

  3. Run the client on the same machine as the server or on another machine on the same subnet as the server. To connect to a server on a different subnet, or if you encounter problems running the client application, refer to The VisiBroker for Java GateKeeper Guide at http://www.visigenic.com/techpubs/#VBJLink.

Outline: creating an RMI application in JBuilder

This topic presents the steps to create a simple distributed application in JBuilder using Java RMI. The application referenced here is located in the jbuilder/samples/borland/samples/rmi/simple directory of your JBuilder installation. For a tutorial recreating one of the JBuilder sample projects, see Tutorial: creating a distributed application with Java RMI.

  1. Create an interface.

    The interface created for this example is SimpleRMIInterface.java. It contains only one method which takes no arguments and returns an object of type java.util.Date. Note two things about this interface:

    See the online JDK documentation (in the java.rmi section) for a complete list of exceptions that can be thrown.

  2. Create a class that implements the interface.

    In this example, the implementation is found in SimpleRMIImpl.java. This class must extend java.rmi.UnicastRemoteObject and must implement the interface you created in the previous step. In this example, the only method that needs to be implemented is getDate(), which returns the current date and time on the system. Note two things about the constructor:

    This call informs the RMI registry that this object is available with the name given in "String name". Other than that, this object simply implements all the methods declared in the interface.

  3. Create a server that creates an instance of the "impl" class.

    In this example, the server class is SimpleRMIServer.java. In this case, the server is pretty simple. It does two things:

    The SimpleRMIImpl object takes care of registering the object with the RMI registry. After this code is run, the object will be available to remote clients as "rmi://<your server here>/SimpleRMIImpl instance". This is how the client connects to it in the next step.

  4. Create a client that connects to the server object using Naming.lookup().

    In this example, the client class is SimpleRMIClient.java. The client first installs a new RMI Security Manager (see previous step), then uses the static method Naming.lookup() to get a reference to the remote object. Note that the client is using the interface to hold the reference and make method calls. You should make sure you've created your interface before you try to build the client, or you'll get "class not found" errors when you try to compile your client.

  5. Compile these classes by selecting Build|Make from the menu.

  6. Run the RMI interface compiler on your implementation class. To run the compiler, right-click on the SimpleRMIImpl file, select Java source properties, then check the Generate RMI Stubs/Skeletons field. This class will be compiled into stubs and skeletons.

    This step generates some additional Java classes. They're stubs and skeletons used by RMI; you don't have to worry about what's in them.

    Any errors detected during the build process will be reported in the compiler output window.

  7. Start the RMI registry by selecting Tools|RMI Registry from the menu. The RMI Registry provides a client with references to remote objects. The RMI Registry is toggled on when there is a check mark to its left, and toggled off when there is no check mark.

At this point, you're done with development; you've built all the code you need to run this example. Next, set up the environment so that you can run the application.

  1. Start your RMI server program.

    Run the SimpleRMIServer from the project. This starts the server running. The server then creates an instance of SimpleRMIImpl and makes it known to the RMI server as "SimpleRMIImpl instance".

  2. Run your client program.

    Run SimpleRMIClient. The program will ask the RMI registry for a reference to "SimpleRMIImpl instance". After it has this reference, the client can invoke any methods declared in the SimpleRMIInterface interface as if the object were a local object.

Next you might want to look at Tutorial: creating a distributed application with Java RMI and try to create a distributed version of the classic "Hello World" program using Java RMI. The completed application can be found in the JBuilder/doc/java/guide/rmi/examples/hello directory of your JBuilder installation.