Discussion:
how get parametre in class server
(too old to reply)
hassan bahi
2011-07-04 15:55:57 UTC
Permalink
file IDL :

interface Data
{
void Etudiant(in string nom , inout long data);
};
file Servant :
import org.omg.CORBA.*; // All CORBA applications need these
classes.
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

class servant extends DataPOA {
private ORB orb;

public servant(ORB orb) {
this.orb = orb;
}

public void Etudiant(String nom, IntHolder data) {
if(data.value==0){
System.out.println("L'etudiant :"+nom+" vient de se
connecter .");

}
else {
System.out.println("L'etudiant : "+nom+" a participé :
"+data.value+" fois");

}
}
}
file server


import org.omg.CORBA.Any;
import org.omg.CORBA.Request;
import org.omg.CORBA.TCKind;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

public class serveur
{
public static void main(String args[])
{
try{
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null);

servant dataRef = new servant(orb);

POA rootpoa =
POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();

org.omg.CORBA.Object ref =
rootpoa.servant_to_reference(dataRef);

Data href = DataHelper.narrow(ref);

String oir = orb.object_to_string(href);
java.io.PrintWriter out = new java.io.PrintWriter(new
java.io.FileOutputStream("c:/dev/Data.ref"));
out.println(oir);
out.close();
wait for invocations from clients
System.out.println("server ready ....");
orb.run();

} catch (Exception e) { System.err.println("ERROR: " + e);
e.printStackTrace(System.out); } }

}

How I can recover the two variables data and nom in the class server
on the client class side I have no problem
thank you in advance
Yakov Gerlovin
2011-07-18 11:49:43 UTC
Permalink
You may provide a callback interface, for example, in the constructor
of servant.
something like
public interface CallBack
{
public void Etudiant_cb(String nom, IntHolder data);
}

'serveur ' will implement this interface and will pass itself as a
parameter to 'servant'
'servant' will store the reference (just like the ORB) and invoke
callback function in 'Etudiant' method.

However, it does not look logically correct, since you're passing call-
related data to the main class. What are you trying to accomplish?
Loading...