Search code examples
javacorba

Waiting for object to bind in CORBA Naming Service


I would like to wait for a server to bind himself into the CORBA Naming Service. Firstly I tried to use the following code, which is polling the Naming Service

Object expectedObj = null;
do
{
   try { expectedObj = ncRef.resolve_str("expectedToBeInNameService"); } 
   catch (NotFound e) {}
   Thread.sleep(2000);
} while(expectedObj == null;

My biggest problem is that this blocking. What is the easiest way to wait for it non-blocking?


Solution

  • You could wait in another thread and use a callback to notify the "original" thread or object that the request to the naming service was resolved.

    class WaitThread extends Thread {
        CallBackObj callback;
    
        public WaitThread(CallBackObj callback) {
          this.text = callback;
          // assume CORBA stuff initiated here
        }
    
        public void run() {
          Object expectedObj = null;
          do
          {
             try { expectedObj = ncRef.resolve_str("expectedToBeInNameService"); } 
             catch (NotFound e) {}
             Thread.sleep(2000);
          } while(expectedObj == null;
          callback.notifyMethodExample();
        }
      }
    

    The caller has to implement the interface CallBackObj and will create this thread by

    WaitThread wt = new WaitThread(this);
    wt.start();
    
    
    interface CallBackObj {
     void notifyMethodExample();
    
    }