Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the distributed programming method of JavaIDL

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "what is the distributed programming method of JavaIDL". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

JavaIDL introduction

JavaIDL is an extension of CORBA functionality in the Java 2 development platform. With the introduction of JavaIDL in Java 2, the basic functions of service objects can be defined by OMG IDL, and IDL can be mapped to Java language according to the requirements of CORBA specification, so as to develop standard distributed applications with interoperability and connectivity. JavaIDL enables distributed Web-enabled Java applications to call remote services transparently based on the IIOP protocol.

The JavaIDL runtime (Runtime) component includes a fully compatible object request broker, Java ORB, for communication between distributed objects based on the IIOP protocol. The ORB supports transient CORBA objects and transient name servers, and the ORB lifetime is limited by the lifetime of running ORB processes.

In the program design, firstly, the function of the service object to be realized is analyzed systematically, and the IDL interface description file is created to describe the function. Then use the IDL to Java language mapping tool provided by JavaIDL to map the IDL file to the client pile (Stub) file and the server skeleton (Skeleton) file.

In the implemented client application, it includes the functions of referencing the remote object, sending the service function request and parsing the result returned by the service object. Usually, the client application uses the naming service to bind the remote object, and connects the client with the service object through the client ORB to realize the remote invocation of the method.

On the server side, ORB uses the service object skeleton to convert the data format of the call request and parameters, and converts the remote call into the call to the method in the local object. When the method returns, the skeleton converts and encapsulates the calculation result, and returns the result to the client through ORB.

The process of building a CORBA application

The main problem of distributed application design is to determine the relationship between the customer and the service object based on the object level. From its most fundamental function, the service object provides the remote interface, and the client object invokes the remote interface. The client object does not need to know the location and implementation details of the remote CORBA object, nor which ORB is used for the interaction between objects.

According to the basic process of implementation, the implementation of CORBA object service can be divided into two ways: object naming reference and serialized object reference. The process for CORBA to create a distributed application is roughly as follows:

◆ conducts system analysis to determine the functions that the service object needs to achieve.

◆ compiles the IDL interface description file according to the results of system analysis.

◆ compiles the interface description file to generate the skeleton of the service object and the stake of the customer object (optional)

◆ writes client object programs based on the piles of customer objects

◆ writes service object programs based on the skeleton or dynamic request implementation of service objects.

◆ compiles client object and service object programs respectively

◆ starts the service object program

◆ starts the client object program.

Distributed application example

Here is a routine to illustrate the process of building a distributed application:

1. Object function description and system brief Design

A string object is assigned on the service object side, and the client gets the value of the string by calling the service object method. According to the description of the function of the object, use UML to describe the functions that the service object needs to implement:

GetIt (): String []

two。 Service object interface definition

According to the results of system analysis, a service object method description program is written with IDL.

GetMessage.idl:

Module getMessage {interface getIt {string returnObject ();};}

3. Compile getMessage.idl

Idltojava-fno-cpp getMessage.idl

4. Write client programs

/ / introduce the related class library import org.omg.CosNaming.*;import org.omg.CORBA.*;// client object method public class client {public static void main (String args []) {/ / create and initialize ORB ORB orb = ORB.init (args, null); / / get the root naming service context object org.omg.CORBA.Object naming = orb.resolve_initial_references ("NameService"); NamingContext namingContext = NamingContextHelper.narrow (naming) / / parse the object reference NameComponent nc = new NameComponent ("getMessage", "); NameComponent path [] = {nc}; getMessage.getIt method = getMessage-Helper.narrow (namingContext.resolve (path)); / / call the service object method String result=method.returnObject ();}}

5. Write a service object program

/ / introduce relevant class library import org.omg.CosNaming.*;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;// service methods class returnMethod extends _ getMessage-ImplBase {public String getIt () {String result = "How about it"; return result;}} / / server-side methods public class server {public static void main (String args []) {/ / create and initialize ORB ORB orb = ORB.init (args, null) / / create a service object and register it with ORB returnMethod obj=new returnMethod (); orb.connect (returnMethod); / / get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references ("NameService"); NamingContext ncRef = NamingContextHelper.narrow (objRef); / / bind the object reference in naming NameComponent nc = new NameComponent ("getMessage", ""); NameComponent path [] = {nc}; ncRef.rebind (path, objRef) / / wait for a call from the client java.lang.Object sync=new java.lang.Object (); synchronized (sync) {sync.wait ();}

6. Compile server and client programs respectively

a. Compile the server-side program:

Javac getMessage\ server.java

b. Compile the client program:

Javac getMessage\ client.java

7. Run

a. Open a simulation terminal window and start the naming service, where 3388 is the communication port number:

Tnameserv-ORBInitialPort 3388

b. Enter the following command in another window to run the server program:

Java server-ORBInitialPort 3388

c. Enter the following command in another window to run the client program:

Java client-ORBInitialPort 3388

This is the end of the content of "what is the distributed programming method of JavaIDL". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report