我试图做一个用java实现的corba程序,它同时是另一个java程序和另一个客户端的服务器,所以我需要一个可以在单独的线程中运行的非阻塞orb (我在我的课Orb_run): 但我有一个问题,当instanciating Orb_run,我必须提供一个ORB对象,但如果我在ORB上调用init方法它将创建一个新的bocking对象这里是我的服务器的代码,Corba non blocking orb
public class machine {
static int uid = 1;
etat_machine etat;
static ORB orb;
static int token_uid = 1;
static void server(String[] args, int uid, int token_uid){
try {
//Instanciate Orb obj
//orb = ORB.init(args, null);
//Instancier Orb_run
Orb_Run orb_run = new Orb_Run(orb);
POA poa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate();
machineImpl machine = new machineImpl(poa, uid, jeton_uid);
// create the object reference
org.omg.CORBA.Object mach = poa.servant_to_reference(machine);
try {
String m1_ref = orb.object_to_string(mach);
String refFile = "m1.ref";
PrintWriter out = new PrintWriter(new FileOutputStream(refFile));
out.println(m1_ref);
out.close();
}
catch (IOException ex) {
System.err.println(
"Impossible d'ecrire la reference dans m1.ref");
System.exit(1);
}
System.out.println("Le serveur m1 est pret ");
// wait for requests
orb_run.run();
System.exit(0);
}
catch (Exception e) {
System.out.println(e);
}
//Client
public static int client(int token_uid){
orb.init();
// Orb_Run orb_run = new Orb_Run(orb);
String ior = null;
try {
String ref = "m2.ref";
FileInputStream file = new FileInputStream(ref);
BufferedReader in = new BufferedReader(new InputStreamReader(file));
ior = in.readLine();
file.close();
} catch (IOException ex) {
System.err.println("Impossible de lire fichier : '" +
ex.getMessage() + "'");
System.exit(1);
}
org.omg.CORBA.Object obj = orb.string_to_object(ior);
if (obj == null) {
System.err.println("Erreur sur string_to_object() ");
throw new RuntimeException();
}
machine machine = machineHelper.narrow(obj);
if (machine == null) {
System.err.println("Erreur sur narrow() ");
throw new RuntimeException();
}
System.out.println("avant appel traitement_message ");
jeton_uid = machine.traitement_message();
System.out.println("le uid ds le jeton mnt"+ jeton_uid);
return jeton_uid;
}
}
我使用这个类开始无阻塞ORB在一个单独的线程:
public class Orb_Run extends Thread {
public ORB orb_;
public Orb_Run(ORB o) {
orb_=o;
}
public void run() {
System.out.println("Le serveur est pret");
orb_.run();
} } }
所以,如果你有一些关于如何做到这一点的提示,它会很棒。
谢谢。
这是程序的服务器方面。客户方面是什么样的? – 2011-03-22 23:51:49
我添加了客户端方面和其中在另一个线程中启动orb的类,我很困惑是否使用init方法orb = ORB.init(args,null);在另一个线程中启动orb之前? – 2011-03-23 05:39:56
我不认为你需要多次启动ORB。一次应该足够用于整个JVM,包含客户端和服务器代码。我认为。 – 2011-03-24 00:41:06