Notes to CBuilder and Corba Talk

By: Charles Calvert

Abstract: These are notes to Charlie Calvert's introductory talk to C++Builder and CORBA

Introduction to CBuilder and CORBA

Overview
Main Points
Distributed Architectures
CORBA and the OMG
What is an ORB?
Working with the SmartAgent
BOA
Proxies
Demos
Instancing
Threading
Simple CORBA Client
Counting the objects
Getting IDL from the Type Library
VisiBroker Manager
Interface Repository
OAD
Working with the OAD
Registering a Server
Repository IDs
More on Registering Servers
Dynamic Invocation
Trader Services
Calling a CBuilder CORBA Object from Java
Calling a Delphi Object from CBuilder
Calling a CBuilder Object from Delphi

Overview

  1. My name is Charlie Calvert. My web site: http://users.aol.com/charliecal or http://www.borland.com/techvoyage or http://community.borland.com
  2. This is an introductory talk on CORBA.
  3. I'll show you how to create CORBA applications and call CORBA servers
  4. The talk includes examples of using CBuilder to talk to Delphi and JBuilder CORBA servers

Main Points in today's Talk

  1. What is a distributed architecture? What is an ORB?
  2. How do I create CORBA clients and servers?
  3. What is an Interface Repository, and how do I use it?
  4. What are static and dynamic binding and how do I use them?
  5. How can I call Java and Delphi CORBA servers?

What is a Distributed Architecture?

  1. It's a codified way to call functions remotely.
  2. We've seen computing progrees from applications to DLLs to RPCs
  3. Our power as programmers is reaching not across a single machine, but across entire networks.
  4. CORBA is object oriented and interface based. Its a humungous VCL or OWL spread out across a network.
  5. You end up with objects living on the network. "The network is the computer"
  6. The point is to make a network appear intelligent just as we think of computers as being intelligent.
  7. CORBA and DCOM are just buffed up versions of the web. They are the super hero versions of CGI or ISAPI.
  8. Unlike the Web, CORBA doesn't rely on HTML, and it is truly Object Oriented.
  9. A "remote" server can be on your own machine or on another machine.

The Origins of CORBA

  1. The CORBA specification was created by the OMG: Object Management Group
  2. CORBA: Common Object Request Broker Architecture
  3. A number of big companies came together to form the OMG.
  4. Big companies have an investment in MACs, PCs and UNIX boxes and they want them to work together.
  5. Unlike COM, it is cross platform and works on UNIX.
  6. They also want to compete more effectively against Bill Gates
  7. Finally, it must work 24 hours a day, 7 days a week, 365 days a year.
  8. To accomplish these goals, they created CORBA.

What is an ORB?

  1. An ORB is an Object Request Broker
  2. ORBS need to be installed on both the client and server
  3. You can find the ORB in the VBrokerBin directory
  4. There is more than one file involved, but notice in particular ORB_BR.DLL
  5. The ORB on the client uses a variation on TCP called IIOP to talk to a smart agent located somewhere on the local network
  6. The Smart Agent locates the ORB running on the server
  7. Picture

Working with the Smart Agent

  1. The Smart Agent (capital S, capital A) is located in the same directory as ORB_B.DLL, and the threaded version of that file, called ORB_BR.DLL.
  2. The Smart Agent is called OSAGENT.EXE, but we Borlanders call it a Smart Agent. That's the official name.
  3. When the Samart Agent is loaded into memory, it broadcasts a message across the network looking for available servers
  4. It keeps a list of those servers, and when the client needs to connect, it hooks the client up to the server
  5. You can have multiple Smart Agents on a system, so if one goes down, others can take its place
  6. The smart agents on a network talk to one another, so they share information.
  7. Once the Smart Agent has hooked up with the ORB on the server it talks to the ORB via the BOA.

Working with the Basic Object Adapter

  1. The Basic Object Adapter is known as the BOA
  2. The BOA is the object the server uses to register itself with the Smart Agent.
  3. During the registration process it tells the BOA that it is ready and active.
  4. The BOA passes that information on to the Smart Agent

Servers and Clients use Proxies

  1. Since the client can't talk directly to the server, it has to use a proxy
  2. This proxy is called a stub.
  3. The stub fakes up the calls to the server's methods, and then uses the ORB to actually tell the server about the request.
  4. The server can't directly receive calls from the client, so it uses a Proxy.
  5. This proxy is called a skeleton
  6. The skeleton makes calls into the real implementation on the server
  7. Its the ORB's job to pass method calls and marshall data back and forth between the stub and the skeleton.

Demos

Creating a simple Simple CORBA Server

  1. Demo first how to build a simple CORBA Object
  2. Then show how to build a database server.
  3. Show the Stub and Skeleton in the _TLB file
  4. CBuilder talking to Java via CORBA

Instancing

Instance-per-client

A new CORBA Object instance is created for each client connection. The instance persists as long as the connection is open. When the client connection closes, the instance is freed.

Shared Instance

A single instance of the CORBA object handles all client requests. Because the single instance is shared by all clients, it must be stateless. This means that clients cant use the IProvider interface to communicate with providers in the CORBA data module.

Threading

Single-threaded

Each data module instance is guaranteed to receive only one client request at a time. Instance data is safe from thread conflicts, but global memory must be explicitly protected.

Multithreaded

Each client connection has its own dedicated thread. However, the data module may receive multiple client calls simultaneously, each on a separate thread. Both global memory and instance data must be explicitly protected against thread conflicts.

Creating a Simple CORBA Client

  1. You can get a server by copying the CreateInstance class function for the CORBAFactory in your TLB file:
  2. var
      MyObject: IMyObject;
      S: WideString;
    begin
      MyObject := TMyObjectCORBAFactory.CreateInstance('IDL:MyObject:1.0');
      MyObject.GetName(S);
      ShowMessage(S);
    end;
    
  3. Place CorbInit in the client program
  4. You get an EEFACE error when the server is not running and you ask for it with the client.

Counting the clients

You can count the number of clients your server has by simply overriding the constructor and destructor for you object and keeping count of the number of times it is called. See the CORBATest1 sample to see how this works.

The Interface Repository

Getting IDL from a Type Library

  1. In some of the following examples you will need IDL files.
  2. You may want to convert a COM library into CORBA IDL so you can call your server from a non-CBuilder client.
  3. Here is the command to convert a COM typelibrary into CORBA IDL: tlibimp -c- -p- -j+
  4. Or you can simply write the IDL yourself by hand

Using the VisiBroker Manager

  1. The VisiBroker Manager gives you a visual front end for managing CORBA Objects
  2. It is a separate product, not part of the standard VisiBroker. You can download it from the web.
  3. To start the VisiBroker Manager, you must first load the Smart Agent and the Location server.
  4. The location manager is in the ToolsVBmanagerBin directory. It is called LocServ.exe

Using the Interface Repository

  1. To load the Interface Repository, type: irep MyName, where MyName is the name of your instance of the repository
  2. If you want, you can also pass in an IDL file, and an optional switch to run in console mode.
  3. irep MyIR MyFile.IDL
  4. Switch back to VBM and press refresh to see what is the references to your repository
  5. Switch to the Interface Repository page in the VM and press Refresh to see further listings
  6. To load a file into the repository, type: idl2ir -ir MyIR StdVCL.IDL, where MyIR is the name of your repository, and StdVCL.IDL is the name of an IDL file.

Starting Objects Automatically

What is OAD?

  1. Use the Object Activation Daemon to load objects automatically
  2. So far we have always had to launch the server by hand. This is how to do it automatically

Working with OAD

  1. To use the OAD, you need to set the VBROKER_ADM and or VBROKER_IMPL_PATH in the registry or environment
  2. For instance, you might write at the command prompt: Set VBROKER_ADM=c:VisigenicVBrokerAdm
  3. By default, CBuilder installs VBROKER in the Program FilesBorland directory
  4. You can now type OAD to start the Object Activation Daemon

Registering a Server with the OAD: Part I

  1. Use the OadUtil program to register a file with the Daemon
  2. To register a file, you need to know its Repository ID and the name of the object that supports your interface

Finding the Repository ID

  1. Turn to the _TLB file for your server project.
  2. Look in the initialization section for a call like the following:
  3. CORBAInterfaceIDManager.RegisterInterface(IMyObject, 'IDL:MyObject:1.0');
  4. The repository ID in this example is 'IDL:MyObject:1.0'

Registering a Server with OAD: Part II

  1. Here is the line to register your object:
  2. oadutil reg -r IDL:MyObject:1.0 -o TMyObjectCORBAFactory -cpp MyObjectServer.exe -p unshared
  3. You will probably have to type in the entire path to the executable.
  4. This example is from Charlie's CORBATest2 example program that accompanies these materials.
  5. You can now go to VBM, turn to the Implementation Repositories page, and see your object.
  6. Click the browse button to get details such as the path to the exe.

Calling the Server from the Client Dynamically

  1. You can call the server from the client dynamically.
  2. Use CORBAInit, and the Repository ID to make the call:
  3. Here is a wild quess as to how it should look:
    procedure TForm2.Button2Click(Sender: TObject);
    var
      Unknown: IUnknown;
      MyObject: IMyObject; // Where is TAny????
      S: WideString;
    begin
      Unknown:= CORBABind('IDL:MyObject:1.0');
      if Unknown <> nil then begin
        MyObject := Unknown as IMyObject;
        MyObject.GetName(S);
        ShowMessage(S);
      end;
    end;
    
    

Miscellaneous Issues - Things To Do

Trader Servers

  1. You can use Trader services to advertise objects, or search out objects
  2. Its like a marketplace where Objects can be found type of name

Calling a CBuilder CORBA Object from Java

  1. Choose File New in JBuilder
  2. Turn to the Application pages
  3. Opt to create a New Application from IDL.
  4. When prompted, add the IDL from your CBuilder application to your project.
  5. Click the Lightening bolt and then Generate buttons in the Application Wizard.
  6. Run the client

Set the name field in your InterfaceBean to an empty string:

public class MyInterfaceBean {
  private java.util.ResourceBundle res = java.util.ResourceBundle.getBundle("GetBCBTemp.MyServer.client.ClientResources");
  private boolean bInitialized = false;
  private MyServer.MyInterface _myInterface;
  private String name = ""; // This is the puppy you need to change!

Calling a Delphi Object from CBuilder

  1. Delphi does not ship with an IDLTOPAS.exe file
  2. As a result, they define a single interface that never changes called a CorbaFactory. It supports a method called CreateInstance.
  3. You can import this interface using the standard BCB "Use CORBA Object" wizard.
  4. Use the Delphi factory to Create an Instance of your object, then call it as usual.

A simple Delphi IDL file produced by the Type Library Editor:

module RomeCorbaServer1
{
  interface IRomeObject;

  
  interface IRomeObject
  {
    wstring GetName(in wstring InData);
  };
  
  interface RomeObjectFactory
  {
    IRomeObject CreateInstance(in string InstanceName);
  };

};

Here is code to call the Delphi Interfaces:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  iRomeObject = romeObjectFactory->CreateInstance("Sam");
  WideString S1 = "Sam";
  WideString S = iRomeObject->GetName(S1);
  ShowMessage(S);
}

Calling a CBuilder Object from Delphi

  1. Delphi does not ship with an IDLTOPAS.exe file
  2. As a result, you can do dynamic binding between Delphi and CBuilder.
  3. To do this, first load the CBuilder IDL file in to the Interface Repository
  4. irep MyRepository TempServer.idl
  5. This creates a repository called MyRepository and loads TempServer.idl into it.

The Delphi Code for attaching to a CBuilder Interface

uses
  CorbaObj, CorbInit;

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  DynamicFactory: TAny;
begin
  DynamicFactory := Orb.Bind('IDL:MyServer/MyInterface:1.0');
  Edit1.Text := DynamicFactory.Square(3);
end;

Server Response from: ETNASC03