简体   繁体   English

Corba非阻塞球

[英]Corba non blocking orb

Im trying to do a Corba program implemented with java that is at the same time a server for another java program and a client for another , so i need a non blocking orb which can be run in a separate thread (i have it in my class Orb_run) : but i have a problem when instanciating Orb_run , i have to provide an ORB object ,but if i call init method on the orb it will create a new bkocking object here's my server's code, 我试图用java实现一个Corba程序,同时是另一个java程序的服务器和另一个java程序的客户端,所以我需要一个非阻塞的orb,它可以在一个单独的线程中运行(我在课堂上有它) 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;
    }

} }

I'm starting a non-blocking orb in a seperate thread using this class: 我正在使用这个类在一个单独的线程中启动一个非阻塞的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();
   }    }                                                                                      }

So if you have some tips on how to do it , it will be great . 所以,如果你有一些关于如何做的提示,它会很棒。

thanks. 谢谢。

Just don't execute the orb_run.run(); 只是不要执行orb_run.run();

Since this method is for blocking the current threads.... 由于此方法用于阻止当前线程....

I don't know of any way to start a non-blocking ORB using the standard APIs in Java. 我不知道如何使用Java中的标准API启动非阻塞ORB。 Can you instead spawn a new thread to run the ORB, and then carry on working in the main thread? 你可以生成一个新线程来运行ORB,然后继续在主线程中工作吗? Or spawn worker threads for the client work, and use the main thread for the ORB? 或者为客户端工作生成工作线程,并使用ORB的主线程?

Still in Java 7 the ORB.run() method actually performs an infinite wait; 仍然在Java 7中,ORB.run()方法实际上执行无限等待; working thread run independent from ORB.run() . 工作线程独立于ORB.run()运行。 So there is no need to call it at all and you have an excellent non-blocking ORB. 因此,根本不需要调用它,并且您具有出色的非阻塞ORB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM