Develop CORBA applications using Java

zhaozj2021-02-08  431

General Object Agent Architecture Corba (Common Object Request Broker Architecture) is a solution defined by the Object Management Organization to implement a large number of hardware and software, and CORBA is also an important step towards object-oriented standardization and interoperability. ■ Introduction to CORBA Technical, CORBA is allowed to communicate with each other, regardless of where they exist and who is designed. CORBA1.1 is published by OMG in 1991, which defines an Interface Definition Language (IDL) and an application programming interface (API) that implements interaction between customer objects and server objects in the Object Request Agent (ORB). CORBA2.0 is released in 1994 that specifies the communication rules of ORB between individual suppliers. The CORBA standard is mainly divided into three parts: Interface Definition Language (IDL), Object Request Agent (ORB), and ORB Interoperability Protocol IIOP. ORB is an middleware that establishes a Client / Server relationship between an object. Using ORB, customers can transparently call methods on a service object, which can be locally or on other machines connected through the network. ORB intercepted this call to find an object to implement the service and pass parameters to it, and the call method returns the final result. Customers don't know where the service object is located, what is the programming language and the operating system, and does not know other system parts that are not object interface. Thus, ORB provides interoperability in different machines in a heterogeneous distribution environment, and seamlessly integrates a variety of object systems. When developing traditional Client / Server applications, developers use their own or a recognized standard to define an agreement for communication between devices. The definition of the protocol relies on the implementation of language, network transmission, and many other factors, and the argument of ORB simplifies this process. When using ORB, the protocol is defined using the Interface Definition Language (IDL), and the IDL is independent of language. And ORB provides strong flexibility, which allows programmers to choose the most suitable operating system, execute the environment, and even system each component can also be implemented in different programming languages. More importantly, it allows integration of existing components. In an ORB-based solution, developers can model the legacy system with the same IDL as creating new objects, and they create "Packaging" to deliver information between standardized software bus and legacy system interface. Using CORBA, users can transparently access information, do not need to know what software is existing, what hardware platform is used, and where it is located in the corporate network. As a communication core for object-oriented systems, CORBA has truly interoperability to today's computing environment. ■ Corba and Java's interrelationship CORBA does not mean object request agency (ORB), it is also a very comprehensive distributed object platform. Corba allows Java applications to span networks, language, and operating systems, and provides a set of distributed services, such as distributed self-observations, dynamic discovery, transactions, relationships, security, and naming. Java is not only a language, it is still a dynamic code system, which is a portable virtual machine (JVM) for running objects. Java provides simpler ways for development, management, and release of Client / Server applications. People can publish this app to thousands of users by placing the app on a web server without having to care about its installation and upgrade. Java is also very suitable for the development of the server, which can dynamically move the service code to the most needed. Java will enable CORBA objects to run on various machines such as hosts, network computers to cellular phones, and simplify the code release of large CORBA systems.

Java is an ideal programming language for customers and service objects, Java built-in multi-thread, garbage collection, and error handling make it easy to write robust network objects. These two object models can be supplemented well, and the transparency of the CORBA processing network, the transparency of Java processing, and CORBA provides a distributed structure for the Java portable application environment. ■ Using Java Development CORBA Application Let me briefly introduce the steps to develop CORBA. Developing CORBA applications using Java requires the following five steps: 1. Describe a CORBA object using the OMG IDL below using the IDL Creative Interface (About.IDL). Module About {interface show {string showname ();};}; saves it to show.idl. 2. Compile the interface and generate a CORBA support file. We use the following command to compile this IDL interface: IDLTOJAVA Show.IDL IDLTOJAVA is Sun's IDL compiler, you can download from Sun Site. Because iDLTojava needs to be precompiled before compiling the IDL file, if there is no precompiler on your machine, you can use the following command: idltojava -fno-cpp show.idl will generate the About subdirectory in the current directory, of which It will include some support files. If you are interested, you can look at it, but you must do not modify it.

3. Implement the main () method of the server (ShowServer.java) SHOWSERVER, you can complete the following tasks: (1) Creating an ORB instance (2) Creating a service object instance (implementation of the CORBA About object) and notify ORB (3) Get A CORBA object reference to a named context, registering a new CORBA object (4) in the name context (4) Register the new object in the "About" name (5) Waiting for the new object to implement the server source program: import About.; import org.omg.CosNaming.; import org.omg.CosNaming.NamingContextPackage.; import org.omg.CORBA.; class ShowObject extends _ShowImplBase {public String ShowName () {return "/ nMy name IS Seymour !! / N ";}} public class showserver {public static void main (string args []) {TRY {// created and initialize orb orb = orb.init (args, null); // Create service object and register the ORB ShowObject ShowRef = new ShowObject (); orb.connect (ShowRef); // get the root naming context org.omg.CORBA.Object objRef = orb.resolve_initial_references ( "NameService"); NamingContext ncRef = NamingContextHelper. Narrow (Objref); // Binding objects in NameComponent NC = New NameComponent ("About", "); NameComponent Path [] = {nc}; ncref.rebind (path, showref); // Wait from Client computer Call java.lang.Object sync = new java.lang.object (); synchronized (sync) {sync.wait ();}} catch (exception e) {system.err.println ("error:" e) E.PrintStackTrace (System.out);}}} 4. Implement the application client below to implement the client (ShowClient.java) will complete the following tasks: (1) Create an ORB; (2) Get a pointing to name the context Quote; (3) Find "Show" in the name context and get a reference to the CORBA object; (4) call the SHOWNAME () operation of the object and print the result.

转载请注明原文地址:https://www.9cbs.com/read-911.html

New Post(0)