codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Home » JAVA » Article

CORBA Technology

Article by: Krunal Patel (8/4/2004)
Bookmark us now! Add to Favourites
Email a friend! Tell a friend
Summary: CORBA defines an architecture for distributed objects. The basic CORBA paradigm is that of a request for services of a distributed object. Everything else defined by the OMG is in terms of this basic paradigm.
Viewed: 13470 times Rating (23 votes): 
 4.3 out of 5
  Rate this Article   Read Comments   Post Comments

CORBA Technology



CORBA, for those who haven't heard of it before, stands for Common Object Request Broker Architecture. This architecture allows clients to invoke methods of objects running on remote servers. The idea is nothing new - many developers will have come across similar systems such as RPC (remote procedure call), or Java's own RMI (remote method invocation). The difference between these and CORBA is that CORBA is much more interoperable with other platforms - a C++ object running on a Wintel system can communicate with a Java object on a Unix box. Developers don't need to know what language a CORBA service is written in, or even where it is physically located. This makes CORBA systems very versatile - one can change the location of a CORBA object, and then re-register with a nameserver. Clients that look up the service can then find its new location, and then continue to make requests. Java makes it easy to integrate support for CORBA into applications and applets, thanks to the introduction of Java IDL in JDK1.4.2

Interface Definition Language (IDL)

Developers use the Interface Definition Language (IDL) to describe the interface to a CORBA object. An IDL schema can then be used to generate Java code for the client and server that will use the object. The same IDL schema could be used to generate either a client or server in C++, Ada, or any other language that supports CORBA. You don't write your implementation of a CORBA service in IDL - so you can continue to write in pure Java code if you so wish.

Let's start by taking a look at a sample IDL schema, to give you an idea what I'm talking about. The following schema shows a very simple CORBA service, which allows clients to get and store the name associated with an email address. For the purposes of this example, we won't worry about modifying or deleting an existing user.

Select All Code


Listing 1-0 AddressBook.idl
We start by declaring a module for our address book system (modules can be mapped to Java packages). Inside the module, we declare our interfaces and the exceptions they can raise. Since its such as simple system, the methods of the interface will only return a string, but we can create more complex return values if needed. As well as returning values, we accept as input two strings for our record_user method. As you can see, IDL really isn't to hard to pick up.

Once you've written your interface using IDL, you can then begin to write client and servers in the language of the choice. We'll choose Java for now, but there's no reason why the client or the server couldn't be written in another language. Provided you have an interface in IDL format, you could write code that interacts with the object it describes.

From IDL to Java
Converting an IDL schema into Java source code is quite straightforward. Sun provides a free tool, idltojava, that creates the source code for you. This tool is currently distributed separately to JDK 1.2, but is freely available for members of the Java Developer Connection.

idltojava -fno-cpp AddressBook.idl
Based on the name of your IDL schema's module, a package will be generated that contains skeleton source code for your CORBA client and server, as well a second package to cover our two exceptions. The following is a list of the files it creates for us

\address_book_system\
_address_bookStub.java
address_book.java
address_bookHolder.java
address_bookHelper.java
address_bookPackage
_address_bookImplBase.java

address_bookPackage\
unknown_user.java
unknown_userHelper.java
unknown_userHolder.java
user_exists.java
user_existsHelper.java
user_existsHolder.java
As you can see, there are a lot of files! Fortunately, we only need three to implement a complete CORBA client and server. The first file is a servant, which serves the requests made by clients. The second is a server, which will accept requests, and the third is a standalone application which will issue requests.

Implementing a CORBA Servant

Under CORBA, a servant is responsible for handling service requests. When we ran the idltojava tool, an abstract class was created that handles most of the hard work for us. All we need to do is create an AddressBookServant class, that implements the _address_bookImplBase. It will contain the code for our three methods described in the IDL schema.

Select All Code


The servant class maintains a list of people's email addresses, and stores this information inside a Hashtable. When the CORBA server receives a request, it will call upon the name_from_email, email_from_name, and record_user methods of the servant to fulfill the request.

Writing a CORBA server

Writing a CORBA server is pretty straightforward. We need to create an ORB (object-request-broker), and register our servant with it. We'll also notify a nameserver of our ORB, so that CORBA clients can access our address book. Once we've registered, CORBA clients will be able to look for our interface, and send requests through our ORB to the servant object.

Select All Code


Writing a CORBA client

Now that we have a finished server, we need to write a client to show that the server works. Our client is very simple. It looks up our AddressBook service through a naming service, and then sends requests in response to commands made by the user. The client also traps exceptions thrown by the AddressBook service, in the event that a user's details doesn't exist or that a duplicate is being inserted into the system.

Select All Code


Putting it all together
Now that we have a CORBA server and a CORBA client, the next step is to have the client connect to the server. If you've already compiled the source code, then you're ready to begin. Otherwise, download the source code (available as a .ZIP file), and extract it to its own directory.

Next, you need to do the following :

Start the nameservice that comes with JDK1.4.2
Start the server
Start the client
Start the nameservice that comes with JDK1.4.2
If your Java installation directory is in the path, you can type the following from your prompt

tnameserv -ORBInitialPort 2000
The port parameter is necessary for Unix users who aren't logged it as root. Windows users can omit the parameter. If you do specify a port parameter, make sure you do so for the client and server as well.

Start the server
All of the examples are part of the address_book_system package. Some users have reported problems running the examples. Make sure that the current directory is in the classpath, and then go to the directory where you've compiled the examples, or where you've unzipped them. Next, start the server

java address_book_system.AddressBookServer
-ORBInitialPort 2000
-ORBInitialHost myhost
The port parameter is optional (but needed if you've specified a port for your nameservice). You'll also need to specify the hostname if you run the server on a different machine to the nameservice (omit it if running everything locally).

Start the client
You'll need to go to the directory where the examples are stored. Make sure that the nameservice and server are already running, and then start the client

java address_book_system.AddressBookClient -ORBInitialPort 2000
-ORBInitialHost myhost
The port parameter is optional (but needed if you've specified a port for your nameservice). You'll also need to specify the hostname if you run the client on a different machine to the nameservice (omit it if running everything locally).

Running the client
The client is capable of invoking all the methods defined in our IDL. It can record new users, look up an email address, and look up a name. While the demonstration is relatively simple, it does show how easy it is to write clients that interact with services on remote systems. This demo is a standalone application, but you could just as easily write an applet that implemented the same functionality.

1- Add user
2- Look up email
3- Look up name
4- Exit

Command :1
Name: Krunal Patel
Email: krunal@nexuscomputers.com
1- Add user
2- Look up email
3- Look up name
4- Exit

Command :2
Name:
Krunal Patel
Email of Krunal Patel is krunal@nexuscomputers.com


Summary

CORBA technology offers developers many benefits over other techniques for distributed computing, but its most compelling is the ease with which developers can create distributed services that are platform independent. Once a service is described by an IDL schema, the developer can choose to implement either client or server (or both) in Java. Being able to use Java is an attractive option, because Java brings platform portability - but its nice to know that one can also connect a C++ module to Java. CORBA allows developers to connect objects together, and developers can still choose the versatility and familiarity of Java.

A further advantage is that CORBA services can be moved throughout the network or intranet. Java 1.4.2 includes a nameservice, which allows ORBs to register (or bind) their services. This means that services can be moved from system to system as needed, and that clients don't need to be aware of the physical location of the service. CORBA is a powerful technology for distributed computing, and the introduction of support for CORBA in JDK1.4.2 offers developers greater freedom when they create distributed systems.






CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'CORBA Technology'
RELATED ARTICLES
Java MP3 Player
by David Barron
A fully functioning MP3 Player with complete source code available for download
A simple way to JTable
by Kanad Deshpande
Many face trouble while dealing with JTable. Here is simplest way to handle JTable.
ID Verification using JSP
by Nouman Rashid
One of the most important parts of web development is to make sure that only authorized users get access to certain areas of the site. This tutorial takes a look at various steps involved in making JSP pages which validate a user ID and password from a MS Access database which contains the username and password.
Java Native Interface (JNI)
by Kanad Deshpande
Java Native Interface (JNI) is one of the intersting interface by java By using Java Native Interface (JNI) you can operate with other applications and libraries.
Understanding Hibernate ORM for Java/J2EE
by Saritha.S.V
Hibernate is the most popular and most complete open source object/relational mapping solution for Java environments.Hibernate's goal is to relieve the developer from 95 percent of common data persistence related programming tasks.
Login codes with JSP,JavaBean from mySQL database
by Prakash
my problem is can i have the code to login with the username and password using JSP and JavaBean/Servlets from mySQL database.When the user enters the username and password in the login page then it will go to the requested site.How to do it?
Java Speech Synthesizer
by David Barron
Small and simple. Type a sentence and press enter and your computer will speek to you.
simple Java Development Environment
by David Barron
Program in JAVA with ease, using this development environment, or adapt it to your own needs.
Turn EJB components into Web services
by Krunal J Patel
Web services have become the de facto standard for communication among applications. J2EE 1.4 allows stateless Enterprise JavaBeans (EJB) components to be exposed as Web services via a JAX-RPC (Java API for XML Remote Procedure Call) endpoint, allowing EJB applications to be exposed as Web services. This article presents a brief introduction to JAX-RPC, outlines the steps for exposing a stateless session bean as a Web service, and provides the best practices for exposing EJB components as Web services
CORBA Technology
by Krunal Patel
CORBA defines an architecture for distributed objects. The basic CORBA paradigm is that of a request for services of a distributed object. Everything else defined by the OMG is in terms of this basic paradigm.








Recent Forum Threads
•  VxWorks Windriver Tornado Ver2.2 For 68K
•  SoftIce Driver Suite 3.0.1
•  metrowerks codewarrior 9.0
•  Mapinfo.Professional.v7.0
•  GardenGraphics DynaSCAPE Professional 3.02
•  Embroidery Great Notions 2004 part01-74
•  EFI_BEST_COLORPROOF_V5.0
•  AViD.SOFTiMAGE.XSi.V4.2.CD1-NNiSO
•  AUTOFX.PHOTOGRAPHIC.EDGES.6.0.CD1


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2014