Search code examples
javacorba

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,

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:

 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.


Solution

  • I don't know of any way to start a non-blocking ORB using the standard APIs in Java. Can you instead spawn a new thread to run the ORB, and then carry on working in the main thread? Or spawn worker threads for the client work, and use the main thread for the ORB?