CORBA callback problem in POA approach
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Tuesday, August 27, 2002 10:56 PM

i am using CORBA POA and implemented the server and client. For notification , i am using callback. For that i am giving the client reference to the server. But using this reference i can not invoke the client. here are client,server and idl file. What is wrong in the code? Please let me know the answer ASAP. ---------------------- idl ------------------- module HelloApp { interface HelloCallback { void callback(in string message); }; interface Hello { string sayHello(in HelloCallback objRef, in string message); }; }; ---------   More>>

i am using CORBA POA and implemented the server and
client. For notification , i am using callback. For
that i am giving the client reference to the server.
But using this reference i can not invoke the client.
here are client,server and idl file.


What is wrong in the code? Please let me know the
answer ASAP.


---------------------- idl -------------------


module HelloApp
{


interface HelloCallback

{
void callback(in string message);
};


interface Hello

{
string sayHello(in HelloCallback objRef, in string message);
};


};




---------------------- server -------------------


import HelloApp.*;

import org.omg.CosNaming.*;

import org.omg.CosNaming.NamingContextPackage.*;

import org.omg.PortableServer.*;

import org.omg.PortableServer.POA;

import java.util.Properties;



class HelloServant extends HelloPOA

{

public String sayHello(HelloCallback callobj, String msg)

{

try

{

System.out.println("CLIENT CALLED THE SERVANT ..... ");



callobj.callback(msg); // this does not work

return "
Hello world !!
";

}catch(Exception e)

{

e.printStackTrace();

}

return "EXCEPTION";

}

}




public class HelloServer
{


static POA rootPOA = null;

static ORB orb = null;

public static void main(String args[])

{

try{

// create and initialize the ORB

orb = ORB.init(args, null);


// create servant and register it with the ORB

HelloServant helloRef = new HelloServant();


org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");

org.omg.CosNaming.NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);


rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));

rootPOA.the_POAManager().activate();

rootPOA.activate_object(helloRef);


org.omg.CosNaming.NameComponent[] path = ncRef.to_name("Hello");

ncRef.rebind(path,rootPOA.servant_to_reference(helloRef));


// 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);

}

}

}





---------------------- client -------------------


import HelloApp.*;

import org.omg.CosNaming.*;

import org.omg.CosNaming.NamingContextPackage.*;

//import org.omg.CORBA.*;



class HelloCallbackServant extends HelloCallbackPOA

{

public void callback(String notification)

{

System.out.println(notification);

}

}


public class HelloClient

{

public static void main(String arg[])

{

try{


org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(arg, null);


// Get the root naming context

org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");


NamingContext ncRef = NamingContextHelper.narrow(objRef);

NameComponent nc = new NameComponent("Hello", "");

NameComponent path[] = {nc};


Hello helloRef = HelloHelper.narrow(ncRef.resolve(path));


HelloCallbackServant helloCallbackRef = new HelloCallbackServant();


org.omg.PortableServer.POA rootPOA = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));

org.omg.CORBA.Object obj = rootPOA.servant_to_reference(helloCallbackRef);

HelloCallback callback = helloCallbackRef._this(orb);


//orb.connect(callback);


// call the Hello server object and print results

String hello = helloRef.sayHello(callback,"
test..
"); // here we are giving the client reference to the server.

System.out.println(hello);


} catch (Exception e)
{

System.out.println("ERROR : " + e) ;

e.printStackTrace(System.out);

}

}

}


   <<Less

Re: CORBA callback problem in POA approach

Posted By:   Pedro_Toto  
Posted On:   Friday, September 13, 2002 10:18 AM

Hi,

I got the exact same problem and found the solution (for me anyway, but I believe it should work for you) here (it's in japanese, but self-explanatory).

Basically, in order to wait for incoming calls, you should replace:

// 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);
}

with

try {
orb.run();
} catch (Exception e) {
e.printStackTrace();
}

NB: this should be placed in both server AND client files.


Hope this helps.

cheers, Pedro.
About | Sitemap | Contact