Você está na página 1de 13

Object 1

The Common Object Request Broker Architecture (CORBA) is a standard developed by the Object
Management Group (OMG) to provide interoperability among distributed objects. CORBA is the
world’s leading middleware solution enabling the exchange of information, independent of
hardware platforms, programming languages, and operating systems. CORBA is essentially a
design specification for an Object Request Broker (ORB), where an ORB provides the mechanism
required for distributed objects to communicate with one another, whether locally or on remote
devices, written in different languages, or at different locations on a network.
In this CORBA Programming tutorial, we will learn how to create :
• Simple Remote Object.
• Server to instantiate (create ) and bind a remote object.
• Client to invoke remotely an object
You need to install the Java Development Kit ( JDK ) as well as a programming editor ( IDE ) such
as Eclipse. For more details of how to install JDK and Eclipse, Use the following tutorial:
Java Programming : Creating a simple java project using Eclipse
The structure of the files for the projects created using Eclipse throughout this tutorials is shown
below:

1. Server Side
1 Let’s create a new Java Project using Eclipse ( or NetBeans or other editor you prefer), and call it
: CorbaAdditionServer-> Click Finish once done
2 Under the project CorbaAdditionServer, Create a new file called Addition.idl. Copy the code
below into the new file.
/** * * @author imed */module AdditionApp{ interface Addition { long add(in
long a,in long b); oneway void shutdown(); };};

3 Open your CMD console, Change directory ( cd ) to src folder within the project location. The
location of your project can be known through clicking: Select the project CorbaAdditionServer,
click : File -> Properties
cd C:\Users\imed\workspace\CorbaAdditionServer\src
4 Compile the idl file using the idlj command as below:
idlj -fall Addition.idl
You will see that inside the src folder, new directory called AdditionApp is created with a number
of Java files inside.

5 Right click on the src folder and select Refresh


6 Under the project CorbaAdditionServer, Create a new Class called AdditionObj. Copy the
code below into the new class.
/** * * @author imed */import AdditionApp.*;import org.omg.CosNaming.*;import
org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import
org.omg.PortableServer.*;import org.omg.PortableServer.POA;import
java.util.Properties; class AdditionObj extends AdditionPOA { private ORB orb;
public void setORB(ORB orb_val) { orb = orb_val; } // implement add()
method public int add(int a, int b) { int r=a+b; return r; } //
implement shutdown() method public void shutdown()
{ orb.shutdown(false); }}

7 Under the project CorbaAdditionServer, Create a new Class called StartServer. Copy the code
below into the new class.
/** * * @author imed */import AdditionApp.*; import org.omg.CosNaming.*;import
org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import
org.omg.PortableServer.*;import org.omg.PortableServer.POA;import
java.util.Properties; public class StartServer { public static void
main(String args[]) { try{ // create and initialize the ORB //// get
reference to rootpoa & activate the POAManager ORB orb = ORB.init(args,
null); POA rootpoa =
POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate(); // create servant and register it
with the ORB AdditionObj addobj = new AdditionObj();
addobj.setORB(orb); // get object reference from the servant
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(addobj); Addition
href = AdditionHelper.narrow(ref); org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService"); NamingContextExt ncRef =
NamingContextExtHelper.narrow(objRef); NameComponent path[] =
ncRef.to_name( "ABC" ); ncRef.rebind(path, href);
System.out.println("Addition Server ready and waiting ..."); // wait for
invocations from clients for (;;){ orb.run(); } } catch
(Exception e) { System.err.println("ERROR: " + e);
e.printStackTrace(System.out); } System.out.println("HelloServer
Exiting ..."); }}

8 Open a new windows of CMD console, type in the following command to start the ORB
start orbd -ORBInitialPort 1050
9 Under Eclipse now, click on the project CorbaAdditionServer, then Click Run -> Run
Configuration as shown below:

10 Make sure you select the StartServer for the CorbaAdditionServer.


If it does NOT show up, Double click on Java Application

11 Click on Arguments and type in the following arguments inside the Program arguments. Click
Apply once done:
-ORBInitialPort 1050 -ORBInitialHost localhost
12 That’s all for the server, it should be running.

Client Side.
1 Let’s create a new Java Project using Eclipse and call it : CorbaAdditionClient-> Click Finish
once done
2 Right click on AdditionApp Package under CorbaAdditionServer and click Copy

3 Right click on src Package under CorbaAdditionClient and click Paste


4 Under the project CorbaAdditionClient, Create a new Class called StartClient. Copy the code
below into the new class.
/** * * @author imed */import AdditionApp.*; import org.omg.CosNaming.*;import
org.omg.CosNaming.NamingContextPackage.*;import org.omg.CORBA.*;import
java.io.*;import java.util.*; public class StartClient { /** * @param
args the command line arguments */ public static void main(String[] args)
{ try { ORB orb = ORB.init(args, null);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); Addition
addobj = (Addition) AdditionHelper.narrow(ncRef.resolve_str("ABC"));
Scanner c=new Scanner(System.in); System.out.println("Welcome to the
addition system:"); for(;;){
System.out.println("Enter a:"); String aa = c.nextLine();
System.out.println("Enter b:"); String bb = c.nextLine();
int a=Integer.parseInt(aa); int b=Integer.parseInt(bb);
int r=addobj.add(a,b); System.out.println("The result for
addition is : "+r);
System.out.println("-----------------------------------"); } }
catch (Exception e) { System.out.println("Hello Client exception: " +
e); e.printStackTrace(); } } }

5 Click on Run -> Run Configuration, Make sure you select the StartClient for the
CorbaAdditionClient.
6 Click on Arguments, then under the Program arguments, type in the following :
-ORBInitialPort 1050 -ORBInitialHost localhost

7 Click Apply, then Run. That’s all for the client, it should be running.

Object 2

About Author

by Imed Bouchrika
Latest Comments
1. Nov 25 2013
Shreyas H J
Hello, Thanks for the above program which helped me a lot in executing and understanding
how CORBA works. Thanks again
Reply

2. Nov 25 2013
Karthik S H
Thanks. It was of great use. Nice work.
Reply

3. Nov 26 2013
Imed Bouchrika
Note that the IDL compiling should be done on client, the same way as done on the server
side.
Reply

• Nov 27 2013
SHreyas H J

Yeah we did Thank you!


Reply

• Mar 30 2015
steve
“idjl ” command not recognized at CMD .Can you please help solve the issue?
Reply

4. Apr 21 2014
derrick
i liked it but am using netbeans and i got lost on step 11 for the server where it required to
add arguments?????? i failed to understand it exactly tho my programm is running.
Reply
5. Jun 03 2014
Sagar
thnku for this article
Reply

6. Jun 03 2014
Sagar mal shankhala
thank you for this article
Reply

7. Jun 06 2014
Widura Wijenayake
Thanks lot, this was really helpful
Reply

8. Jul 11 2014
gihan tharnga
hehe nice works thankz lot its very clear tutoraial thank again
Reply

9. Jul 29 2014
Rajesh
Can any one Explain me the code
Reply

10. Dec 10 2014


GI
i have this error, i don’t know why? can u help me pls
déc. 10, 2014 10:02:25 PM
com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl
Avertissement: “IOP00410201: (COMM_FAILURE) Connection failure: socketType:
IIOP_CLEAR_TEXT; hostname: localhos; port: 1050”
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
at
com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemE
xception.java:2200)
at
com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemE
xception.java:2221)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.
(SocketOrChannelConnectionImpl.java:223)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.
(SocketOrChannelConnectionImpl.java:236)
at
com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(Socket
OrChannelContactInfoImpl.java:119)
at
com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaCli
entRequestDispatcherImpl.java:185)
at
com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.
java:136)
at
com.sun.corba.se.impl.resolver.BootstrapResolverImpl.invoke(BootstrapResolverImpl.java:
99)
at
com.sun.corba.se.impl.resolver.BootstrapResolverImpl.resolve(BootstrapResolverImpl.java:
132)
at
com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.jav
a:47)
at
com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.jav
a:47)
at
com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.jav
a:47)
at com.sun.corba.se.impl.orb.ORBImpl.resolve_initial_references(ORBImpl.java:1169)
at com.StartServer.main(StartServer.java:29)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:127)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:640)
at java.nio.channels.SocketChannel.open(SocketChannel.java:184)
at
com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(DefaultSocketFact
oryImpl.java:78)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.
(SocketOrChannelConnectionImpl.java:206)
… 11 more
ERROR: org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed:
No
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
at
com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemE
xception.java:2200)
at
com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemE
xception.java:2221)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.
(SocketOrChannelConnectionImpl.java:223)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.
(SocketOrChannelConnectionImpl.java:236)
at
com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(Socket
OrChannelContactInfoImpl.java:119)
at
com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaCli
entRequestDispatcherImpl.java:185)
at
com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.
java:136)
at
com.sun.corba.se.impl.resolver.BootstrapResolverImpl.invoke(BootstrapResolverImpl.java:
99)
at
com.sun.corba.se.impl.resolver.BootstrapResolverImpl.resolve(BootstrapResolverImpl.java:
132)
at
com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.jav
a:47)
at
com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.jav
a:47)
at
com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.jav
a:47)
at com.sun.corba.se.impl.orb.ORBImpl.resolve_initial_references(ORBImpl.java:1169)
at com.StartServer.main(StartServer.java:29)
Caused by: java.nio.channels.UnresolvedAddressException
at sun.nio.ch.Net.checkAddress(Net.java:127)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:640)
at java.nio.channels.SocketChannel.open(SocketChannel.java:184)
at
com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(DefaultSocketFact
oryImpl.java:78)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.
(SocketOrChannelConnectionImpl.java:206)
… 11 more
HelloServer Exiting …
Reply

• May 04 2015
Nata
Hi, you maybe forgot to run the following command :
start orbd -ORBInitialPort 1050
before to run the server corba
Reply

• Dec 12 2015
mohammed
change localhost by 127.0.0.1
-ORBInitialPort 1050 -ORBInitialHost 127.0.0.1
i have the same problem but when i change to 127.0.0.1 it work’s fine
Reply

• Nov 17 2016
Wassilm
a wldi kifch sala7t waldih adhaya !!!
Reply

11. Dec 21 2014


candra
i just want to know, is that work with the latest JDK ?
Reply

12. Dec 22 2014


Senthilkumar
Thanks, Please extend to java server and C++ client which will be more language
independent. Thanks once again
Reply

13. Feb 09 2015


ali yaghooti
thank you.
its very helpful.
Reply

14. Feb 19 2015


Tugce Saritas
Thank you so much the tutorial really helped a lot !
Reply

15. May 19 2015


jossk
Very Very Good Tutorial
Extremely simple and practical
Reply

16. Jul 15 2015


Jinesh Joseph
Thanks…This article is very helpful
Reply

17. Sep 10 2015


nishant
really useful. thanks a lot.
if possible, pls provide one example with server client in diff languages so as to understand
the real purpose of corba
Reply

18. Nov 02 2015


Shmilfke
Is there anywhere I can download the whole project?
Reply

19. Mar 22 2016


anand
Than You Imed Bouchrika. Its helped me to executing CORBA Request node usage in iib
also.
20.

Você também pode gostar