我正在尝试做一个用java实现的Corba程序,它同时是另一个java程序的服务器和另一个java程序的客户端,所以我需要一个可以在单独的线程中运行的非阻塞orb(我有它在我的类(class) Orb_run 中): 但是我在实例化 Orb_run 时遇到问题,我必须提供一个 ORB 对象,但是如果我在 orb 上调用 init 方法,它将创建一个新的 bkocking 对象,这是我的服务器代码,
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;
}
}
我正在使用此类在单独的线程中启动一个非阻塞球体:
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();
} } }
因此,如果您有一些关于如何执行此操作的提示,那就太好了。
谢谢。
最佳答案
我不知道有什么方法可以使用 Java 中的标准 API 启动非阻塞 ORB。您是否可以生成一个新线程来运行 ORB,然后继续在主线程中工作?或者为客户端工作生成工作线程,并为 ORB 使用主线程?
关于java - Corba 非阻塞球体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5397697/