We received a bug about can not receive any notification but the notification channel can be built successfully. After a long investigation, we found this issue was caused by the network environment.

Let’s do more check on this issue, why we don’t know whether objects in IROs is running well or not.

I downloaded the famous “hello world” sample from internet and did some modification to test this issue.

The source code are listed below:

echo.idl

#ifndef __ECHO_IDL__
#define __ECHO_IDL__

interface Echo
{
    string echoString(in string mesg);
};

#endif // __ECHO_IDL__

client.cpp

#include <iostream>
#include "echoC.h"
using namespace std;

static void hello(Echo_ptr e)
{
      CORBA::String_var src = (const char*) "Hello!";
      CORBA::String_var dest = e->echoString(src);
      cerr << "I said, \"" << (char*)src << "\"." << endl
            << "The Echo object replied, \"" << (char*)dest <<"\"." << endl;
}

int main(int argc, char* argv[]) {
      try {
            // initialize orb
            CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
            // check arguments
            if (argc != 2) {
                  cerr << "Usage: exe object reference" << endl;
                  throw 1;
            }
            // Obtain reference from servant IOR
            cout<<"............."<<"string_to_object"<<endl;
            CORBA::Object_var obj = orb->string_to_object(argv[1]);
            cout<<"............."<<"narrow"<<endl;
            Echo_var echoref = Echo::_narrow(obj);
            cout<<"............."<<"narrow done"<<endl;
            if( CORBA::is_nil(echoref.in()) ) {
                  cout << "Can't narrow reference to type Echo (or it was nil)." << endl;
                  return 1;
            }
            cout<<"ssssssssss"<<endl;
            if(echoref.in()->_non_existent())
            {
                cout<<".........."<<"_non_existent"<<endl;
                return 1;
            }
            cout<<".........."<<"asdasd"<<endl;
            for (CORBA::ULong count=0; count<10; count++)
                  // communicate with servant
                  hello(echoref);
            orb->destroy();
      }
      catch(CORBA::COMM_FAILURE&) {
            cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
                  << "object." << endl;
      }
      catch(CORBA::SystemException&) {
            cerr << "Caught a CORBA::SystemException." << endl;
      }
      catch(CORBA::Exception&) {
            cerr << "Caught CORBA::Exception." << endl;
      }
    catch(...) {
            cerr << "Caught unknown exception." << endl;
      }

      return 0;
}

servant.cpp

#include <iostream>
#include "echoS.h"
using namespace std;

class Echo_i : public POA_Echo,
public PortableServer::RefCountServantBase
{
public:
      inline Echo_i() {}
      virtual ~Echo_i() {}
      virtual char* echoString(const char* mesg)
        throw ( CORBA::SystemException)
        ;
};

char* Echo_i::echoString(const char* mesg)
    throw ( CORBA::SystemException)
{
      cerr << "Upcall " << mesg << endl;
      return CORBA::string_dup(mesg);
}

//////////////////////////////////////////////////////////////////////
int main(int argc, char** argv)
{
      try {
            // initialize ORB
            CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
            // find RootPOA
            CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
            PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
            // create servant object and activate it
            Echo_i* myecho = new Echo_i();
            PortableServer::ObjectId_var myechoid = poa->activate_object(myecho);
            // Obtain a reference to the object, and print it out as a
            // stringified IOR.
            obj = myecho->_this();
            CORBA::String_var sior(orb->object_to_string(obj));
            cerr << (char*)sior << endl;
            myecho->_remove_ref();
            // find and activate POAManager
            PortableServer::POAManager_var pman = poa->the_POAManager();
            pman->activate();
            orb->run();
      }
      catch(CORBA::SystemException&) {
            cerr << "Caught CORBA::SystemException." << endl;
      }
      catch(CORBA::Exception&) {
            cerr << "Caught CORBA::Exception." << endl;
      }
      catch(...) {
            cerr << "Caught unknown exception." << endl;
      }
      catch(...) {
            cerr << "Caught unknown exception." << endl;
      }
      return 0;
}

At first, we should compile the idl into C source code, the command line should be

tao_idl –Sc echo.idl

Then we compile the server and the client

g++ -o server.exe -I/opt/tao/linux/ix86/tao_1.4.1_2/include -L/opt/tao/linux/ix86/tao_1.4.1_2/lib -L$OTHERLIBS -llinux -lTAO_PortableServer -lTAO_ObjRefTemplate -lTAO_Valuetype -lTAO_IORInterceptor -lTAO_Messaging -lTAO_IORTable -lTAO_Strategies -lTAO -lACE echoC.cpp echoS.cpp servant.cpp
g++ -o client.exe -I/opt/tao/linux/ix86/tao_1.4.1_2/include -L/opt/tao/linux/ix86/tao_1.4.1_2/lib -L$OTHERLIBS -llinux -lTAO_PortableServer -lTAO_ObjRefTemplate -lTAO_Valuetype -lTAO_IORInterceptor -lTAO_Messaging -lTAO_IORTable -lTAO_Strategies -lTAO -lACE echoC.cpp client.cpp

Now we are going to do the test :

start the server.exe and got the IOR, then kill the server process.

./client.exe IOR:010000000d00000049444c3a4563686f3a312e3000000000010000000000000078000000010102001b00000063646c696e6730382e6368696e612e6e736e2d6e65742e6e657400001fed00001b00000014010f00525354cde2ce4a142701000000000001000000010000000002000000000000000800000001000000004f415401000000140000000198d60001000100000000000901010000000000
.............string_to_object
.............narrow
.............narrow done
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Caught a CORBA::SystemException.

The result indicate that:

  • string_to_object: convert a object from a string, it only build a stub at the client side, no networking interactive.
  • narrow: copy object, down-cast object, no networking interactive.
  • _non_existent: connect to server and check.

if you want to know whether the IOR works or not, you should invoke “_non_existent”.

More information, please refer to TAO source code.


Jeason Zhao (沈胜衣,斛律光) ------雪饮再现,一个人的江湖
我知道我是谁,我是沈胜衣,默默的活着,就像空气。