Understanding the CORBA Model What is CORBA w
Understanding the CORBA Model
What is CORBA? w The Common Object Request Broker Architecture (CORBA) allows distributed applications to interoperate (application to application communication), regardless of what language they are written in or where these applications reside.
What is CORBA w The CORBA specification was adopted by the Object Management Group to address the complexity and high cost of developing distributed object applications. CORBA uses an object-oriented approach for creating software components that can be reused and shared between applications.
What is CORBA w Each object encapsulates the details of its inner workings and presents a well defined interface, which reduces application complexity. The cost of developing applications is reduced, because once an object is implemented and tested, it can be used over and over again.
What is CORBA w The Object Request Broker (ORB) in Figure 2. 1 connects a client application with the objects it wants to use. The client program does not need to know whether the object implementation it is in communication with resides on the same computer or is located on a remote computer somewhere on the network.
What is CORBA w The client program only needs to know the object's name and understand how to use the object's interface. The ORB takes care of the details of locating the object, routing the request, and returning the result.
Figure 2. 1 Client program acting on an object
The ORB w The ORB itself is not a separate process. It is a collection of libraries and network resources that integrates within end-user applications, and allows your client applications to locate and use objects.
Developing an example application with Visi. Broker w This chapter uses an example application to describe the development process for creating distributed, object-based applications. The code for the example application is provided in the bank_agent. html file under the examples/basic/bank_agent directory where the Visi. Broker for Java package was installed.
Development Process w When you develop distributed applications with Visi. Broker, you must first identify the objects required by the application. You will then usually follow these steps: w Write a specification for each object using the Interface Definition Language (IDL). IDL is the language that an implementer uses to specify the operations that an object will provide and how they should be invoked. In this example, we define, in IDL, the Account interface with a balance() method and the Account. Manager interface with an open()
w In this example, we define, in IDL, the Account interface with a balance() method and the Account. Manager interface with an open() method.
w IDL is the language that an implementer uses to specify the operations that an object will provide and how they should be invoked.
w Use the IDL compiler to generate the client stub code and server POA servant code. Using the idl 2 java compiler, we'll produce client-side stubs (which provide the interface to the Account and the Account. Manager objects' methods) and server-side classes (which provides classes for the implementation of the remote objects).
Write the client program code. w To complete the implementation of the client program, initialize the ORB, bind to the Account and the Account. Manager objects, invoke the methods on these object, and print out the balance.
Write the server object code. w To complete the implementation of the server object code, we must derive from the Account. POA and Account. Manager. POA classes, provide implementations of the interface's methods, and implement the server's main routine.
w Compile the client and server code. To create the client program, compile the client program code with the client stub. To create the Account server, compile the server object code with the server skeleton. w Start the server. w Run the client program.
w Figure 4. 1
Step 1: Defining object interfaces w The first step to creating an application with Visi. Broker is to specify all of your objects and their interfaces using the OMG's Interface Definition Language (IDL). w The IDL can be mapped to a variety of programming languages. The IDL mapping for Java is summarized in the Visi. Broker for Java Reference.
w You then use the idl 2 java compiler to generate stub routines and servant code from the IDL specification. The stub routines are used by your client program to invoke operations on an object. You use the servant code, along with code you write, to create a server that implements the object. The code for the client and object, once completed, is used as input to your Java compiler to produce a client Java applet or application and an object server.
Writing the account interface in IDL w IDL has a syntax similar to C++ and can be used to define modules, interfaces, data structures, and more. IDL sample 4. 1 shows the contents of the Bank. idl file for the bank_agent example. The Account interface provides a single method for obtaining the current balance. The Account. Manager interface creates an account for the user if one does not already exist.
w Bank. idl file provides the Account interface definition: module Bank { interface Account { float balance(); }; interface Account. Manager { Account open(in string name); }; };
Step 2: Generating client stubs and server servants w The interface specification you create in IDL is used by Visi. Broker's idl 2 java compiler to generate Java classes for the client program, and skeleton code for the object implementation. The Java classes are used by the client program for all method invocations. You use the skeleton code, along with code you write, to create the server that implements the objects.
w The code for the client program and server object, once completed, is used as input to your Java compiler to produce the client and server executables classes. These steps are shown in Figure 4. 1. Because the Bank. idl file requires no special handling, it can be compiled with the following command: prompt> idl 2 java Bank. idl w For more information on the command-line options for the idl 2 java compiler, see "Using IDL. "
Files produced by the idl compiler w Because Java allows only one public interface or class per file, compiling the IDL file will generate several. java files. These files are stored in a generated sub-directory called Bank which is the module name specified in the IDL and is the package to which the generated files belong.
The following files are generated w _Account. Manager. Stub. java: Stub code for the Account. Manager object on the client side. w _Account. Stub. java: Stub code for the Account object on the client side.
w Account. java: The Account interface declaration. w Account. Helper. java: Declares the Account. Helper class, which defines helpful utility methods. w Account. Holder. java: Declares the Account. Holder class, which provides a holder for passing Account objects.
w Account. Manager. java: The Account. Manager interface declaration. w Account. Manager. Helper. java: Declares the Account. Manager. Helper class, which defines helpful utility methods. w Account. Manager. Holder. java: Declares the Account. Manager. Holder class, which provides a holder for passing Account. Manager objects.
w Account. Manager. Operation. java: This interface provides declares the method signatures defined in the Account. Manager interface in the Bank. idl file. w Account. Manager. POA. java: POA servant code (implementation base code) for the Account. Manager object implementation on the server side. w Account. Manager. POATie. java: Class used to implement the Account. Manager object on the server side using the tie mechanism.
w Account. Operations. java: This interface provides declares the method signatures defined in the Account interface in the Bank. idl file
w Account. POA. java: POA servant code (implementation base code) for the Account object implementation on the server side. w Account. POATie. java: Class used to implement the Account object on the server side using the tie mechanism.
w For more information about the Helper, Holder, and Operations classes, see the Visi. Broker for Java Reference.
Step 3: Implementing the client w Many of the classes used in implementing the bank client are contained in the Bank package generated by the idl 2 java compiler as shown in the previous example. w The Client. java file illustrates this example and is included in the bank_agent directory. Normally you would create this file.
Client. java w The Client class implements the client application which obtains the current balance of a bank account. The bank client program performs these steps: Initializes the ORB. Binds to an Account. Manager object. Obtains an Account object by invoking open on the Account. Manager object. Obtains the balance by invoking balance on the Account object.
Code sample 4. 1 w Client side programpublic class Client { public static void main(String[] args) {
Binding to the Account. Manager object w Before your client program can invoke the open(String name) method, it must first use the bind() method to establish a connection to the server that implements the Account. Manager object. The implementation of the bind() method is generated automatically by the idl 2 java compiler. The bind() method requests the ORB to locate and establish a connection to the server.
w If the server is successfully located and a connection is established, a proxy object is created to represent the server's Account. Manager. POA object. w An object reference to the Account. Manager object is returned to your client program.
Obtaining an Account object w Next your client class needs to call the open() method on the Account. Manager object to get an object reference to the Account object for the specified customer name.
Obtaining the balance w Once your client program has established a connection with an Account object, the balance() method can be used to obtain the balance. The balance() method on the client side is actually a stub generated by the idl 2 java compiler that gathers all the data required for the request and sends it to the server object.
Account. Manager. Helper. java w This file is located in the Bank package. It contains an Account. Manager. Helper object and defines several methods for binding to the server that implements this object. The bind() class method contacts the specified POA manager to resolve the object. Our example application uses the version of the bind method that accepts an object name, but the client may optionally specify a particular host and special bind options. For more information about Helper classes, see the Visi. Broker for Java Reference
Portion of the Account. Manager. Helper. java file package Bank; public final class Account. Manager. Helper {. . .
Other methods w Several other methods are provided that allow your client program to manipulate an Account. Manager object reference. Many of these are not used in the example client application, but they are described in detail in the Visi. Broker for Java Reference
Step 4: Implementing the server w Just as with the client, many of the classes used in implementing the bank server are contained in the Bank package generated by the idl 2 java compiler. The Server. java file is a server implementation included for the purposes of illustrating this example. Normally you, the programmer, would create this file.
Server. java w This file implements the Server class for the server side of our banking example. The server program does the following: w Initializes the Object Request Broker. w Creates a Portable Object Adapter with the required policies. w Creates the account manager servant object. w Activates the POA manager (and the POA). w Waits for incoming requests.
Server side program public class Server { public static void main(String[] args) {. .
Step 5: Building the example w The examples directory of your Visi. Broker release contains a vbmake. bat for this example and other Visi. Broker examples. w Compiling the example w Windows: Assuming the Visi. Broker distribution was installed in C: vbroker, type the following to compile the example: prompt> C: prompt> cd vbrokerexamplesbasicbank_agent
Compiling the example w Windows: Assuming the Visi. Broker distribution was installed in C: vbroker, type the following to compile the example: prompt> C: prompt> cd vbrokerexamplesbasicbank_agent prompt> vbmake
w The command vbmake is a batch file which runs the idl 2 java compiler and then compiles each file. w If you encounter some problems while running vbmake, check that your path environment variable points to the bin directory where you installed the Visi. Broker software.
Compile the example w UNIX: w Assuming the Visi. Broker distribution was installed in /usr/local, type the following to compile the example: prompt>cd/usr/local/vbroker/examples/basic/bank_ag ent prompt> make java w In this example, make is the standard UNIX facility. If you do not have it in your PATH, see your system administrator.
Step 6: Starting the server and running the example w Now that you have compiled your client program and server implementation, you are ready to run your first Visi. Broker application.
Starting the Smart Agent w Before you attempt to run Visi. Broker client programs or server implementations, you must first start the Smart Agent on at least one host in your local network. The basic command for starting the Smart Agent is as follows: prompt> osagent
ORB Services as NT Services w If you're running Windows NT and you want to start the Smart Agent as an NT Service, you need to register the ORB Services as NT Services during installation. See the Visi. Broker Installation Guide for instructions on installing this product. If the Services were registered, you then are able to start the Smart Agent as an NT Service through the Services Control Panel.
Starting the server w Open a DOS prompt window and start your server by using the following DOS command: prompt> start vbj Server w UNIX: Start your Account server by typing prompt> vbj Server&
Running the client w Windows: Open a separate DOS prompt window and start your client by using the following DOS command: prompt> vbj Client
w UNIX: To start your client program, type prompt> vbj Client w You should see output similar to that shown below (the account balance is computed randomly). w The balance in the account in $168. 38.
- Slides: 54