Netprog: CORBA Intro1 CORBA Common Object Request Broker Architecture.
MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming
description
Transcript of MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming
![Page 1: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/1.jpg)
MSc Course in Advanced Distributed Systems
Session 2.2: Practical CORBA Programming
http://info.comp.lancs.ac.uk/msc/ads/index.htm
![Page 2: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/2.jpg)
Resources
• three problems: Echo, Time and Notifier
• http://www.comp.lancs.ac.uk/~leek/msc2004/ has problem specifications
• There are 3 problems, Echo, File and Chat
• we will now look at the Echo example in some detail to get you started...
![Page 3: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/3.jpg)
The Echo files (online)
Echo.idl produces (mainly)...– EchoInterface.java. The IDL interface represented as a Java
interface.
– _EchoInterfaceImplBase.java. It implements the
FileInterface.java interface – _EchoStub.java. The Stub.
• Client.java. The Client Implementation
• Server.java. The Server Implementation
![Page 4: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/4.jpg)
Echo.idl
//// Echo.idl//
/// Put the interface in a module to avoid global namespace pollution
module Exercise{ // A very simple interface interface EchoServer { // Return the given string string echo(in string s); };};
![Page 5: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/5.jpg)
server.java 1 (of 2)// server.java, stringified object reference versionimport java.io.*;import org.omg.CORBA.*;
class EchoServant extends _EchoImplBase { public String echo(String s) {
return s; }}public class server {
public static void main(String args[]) {
try{ // create and initialize the ORB ORB orb = ORB.init(args, null);
// create servant and register it with the ORB EchoServant echoRef = new EchoServant(); orb.connect(echoRef);
![Page 6: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/6.jpg)
server.java 2 (of 2)// stringify the EchoRef and dump it in a file String str = orb.object_to_string(echoRef); String filename = System.getProperty("user.home")+ System.getProperty("file.separator")+"EchoIOR"; FileOutputStream fos = new FileOutputStream(filename); PrintStream ps = new PrintStream(fos); ps.print(str); ps.close();
// wait for invocations from clients java.lang.Object sync = new java.lang.Object(); synchronized (sync) { sync.wait(); }
} catch (Exception e) { System.err.println("ERROR: " + e); e.printStackTrace(System.out);}
}}
![Page 7: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/7.jpg)
client.java 1 (of 2)
// client.java, stringified object reference version
import java.io.*;
import org.omg.CORBA.*;
public class client
{
public static void main(String args[])
{
try{
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// Get the stringified object reference and destringify it.
String filename = System.getProperty("user.home")+
System.getProperty("file.separator")+"echoIOR";
BufferedReader br = new BufferedReader(new FileReader(filename));
![Page 8: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/8.jpg)
client.cpp 2 (of 2)
String ior = br.readLine();
org.omg.CORBA.Object obj = orb.string_to_object(ior);
Echo echoRef = EchoHelper.narrow(obj);
// call the Echo server object and print results
String echo = echoRef.echo("Hello, World");
System.out.println(echo);
} catch (Exception e) {
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
}
}
}
![Page 9: MSc Course in Advanced Distributed Systems Session 2.2: Practical CORBA Programming](https://reader036.fdocuments.in/reader036/viewer/2022082517/56813b34550346895da40376/html5/thumbnails/9.jpg)
Running the application
Follow the instructions on the web site to download the pre-compiled classes.
• running– run the server first: ‘java server’– then run the client: ‘java server’