A simple CORBA client

In order to access the services offered by the server SoilCORBA, a CORBA client needs to be developed. In Java, CORBA clients can be implemented as applets or as applications. Although both methods provide similar results, they are implemented in different ways. We will implement our CORBA client as an application. Figure 11-10 shows the Java implementation of a simple CORBA client. The task of this client is to connect to the SoilCORBA server and use one of its services. The service used provides the current value of soil depth parameter.

1 import java.util.Properties;

2 public class CORBAClient {

3 public CORBAClientp {}

4 public static void main(String[] args) {

5 //create an instance of the client

6 CORBAClient corbaClient - new CORBAClient();

7 Properties soilProp = new Properties();

8 soilProp.put("org.omg.CORBA.ORBClass", "com.visigenic.vbroker.orb.ORB");

9 org.omg.CORBA.ORB orb - org.omg.CORBA.ORB.init((String [])null,soilProp);

10 //connect to SoilCORBA server

11 SoilCORBAInterface soil-

12 SoilCORB AInterfaceHelper.bind(orb,

13 "http://128.227.103.134:1015/SoilServer.iorM);

14 //print value of soil depth

15 System.out.println("Soil depth value is: "+soil.getSoilDepth());

Figure 11-10. The implementation of a simple CORBA client in Java.

Line 1 makes available the behavior of class Properties that is needed in lines 7 and 8. Line 2 defines the class CORBAClient, and line 3 defines a default constructor for the class. Lines 4 through 16 define the method main that initializes the class environment and creates an instance of the class itself in line 6. An object of type Properties is created in line 7 to hold the information that Visigenic CORBA technology is used in this case. Line 9 initializes the ORB. Lines 11, 12, and 13 bind the ORB to the IOR of the object located in the server. Therefore, a proxy of the server object is created (see Section 4.2, The Proxy pattern, in Chapter 7) in the client application and the communication bridge between server and client is established. The proxy object is object soil. Note that the server's IP (Internet Protocol) number and the number of the port used are the same as the ones defined in the server application. If the client and server applications use different IP and/or port numbers, then the communication bridge cannot be established and therefore the client and the server will not be able to communicate with one another. Proxy soil will make available to the client application the behavior of the server object. Line 15 uses the proxy to obtain the value of soil depth, which is provided as a service by the server object.

0 0

Post a comment