Creating Client/server programs with CORBA

Source: Internet
Author: User
Tags integer

If you're looking for a way to connect a client to a server using an object-oriented approach, you have two main choices: DCOM and CORBA. DCOM is a Microsoft solution and is useful when you write code for a Windows system. In this article, we'll look at using CORBA to solve distributed application problems.

CORBA Overview:

In a common object-oriented program written in C + + or Java, the program contains the classes that all applications need. Compilers compile and connect these objects, and when you initialize the objects with the new statement, they are created in the memory of the application and are executed as a simple process.

CORBA is a technology that allows a client program to invoke an object belonging to a server that can be a machine running on the same machine or thousands of miles away. In its most basic phase, CORBA is very simple-instantiating an object in your processing memory space instead of what you do in the usual program, you can instantiate the object on either network server. The methods that invoke this object and the parameters that these methods need to pass are sent to the server in a format packaged as a network package. This function is actually running on the server, and the result is passed over the network to the caller.

The advantage of this scenario is that the server can serve as an efficient, shared resource Center in which server-based CORBA objects can access the server's databases and other services. Of course, its disadvantage is speed. The number of calls per second is strictly limited by network speed to ensure that other technologies transmit data over the network, so CORBA is not alone. DCOM, even the socket, has to endure the same delay.

The special aspect of CORBA is that it is convenient to invoke the Orb (Object Request Broker), and the Orb handles and operates the connection between the client and the server. In the following example we will use Inprise visibroker ORB. With visibroker,client and server using a service called Osagent, Osagent connects the client with a standard port (usually 14000). Osagent can be used as a directory to help the client orb to find the object it is looking for.

Setting up a simple CORBA client and server in Java is very simple, and we're going to see a few examples of snippets to show the process, and in the next section we'll explain how the code works, and we'll start with the keyword "install".

Installation

With the example code in the document, in addition to the Visibroker orb you need to download sun JDK1.1, you can download the SDK from http://java.sun.com/products/jdk/1.1/index.html. We used JDK1.1 instead of 1.2 to avoid an orb clash with JAVA2. You can get Visibroker orb from http://www.inprise.com/visibroker/. First install the SDK, then install the orb.

Example code

To create a CORBA server and have the client access it, you decide what the server class is going to do before you start. In this example we're going to use a very simple server class that has a private integer variable in which a method will add the integer variable, and another method will allow the client to access the correct value of the variable, and the following is the interface description of the class:

//Counter.idl
module Counter{
interface Count
{
void increment();
long getCounter();
};
};

This class is named Count, and its two methods are increment and Getcounter, and this class is contained in a template called counter, as long as you want the template to contain several different classes, Put this IDL code in a file called Counter.idl name.

In order to use this IDL file, you need to Idl2java to run it, which will create the class that the client and server will use, The client class produced by Idl2java is called a helper and is named Counthelper.java,client with the helper class to invoke the function of the server, Idl2java the resulting server class is called Implbase and is named _ Countimplebase.java, you will perform these server Extensions Implbase methods.

Note: When you use the Counterhelper.java class directly in the client, the code executed in the client when you invoke a Counter interface method is _st_counter.java. This class invocation stub sends the data to the server and returns the correct data, which communicates with the server-side skeleton (_sk_counter.java, inheritance, and _counterimplbase.java).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.