2

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?

1
  • What do you want to do while waiting for that object?
    – tuergeist
    Oct 5, 2012 at 20:36

1 Answer 1

0

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();

}
1
  • Could you give a code sample? I'm not familiar in java threading.
    – adam_gav
    Oct 5, 2012 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.