[omniORB] Naming Server--COMM-FAILURE
Hai Wang
wangh@Teltec.DCU.IE
Tue, 29 Jun 1999 17:08:41 +0100
Date sent: Tue, 29 Jun 1999 16:42:13 +0100 (GMT)
From: David Riddoch <djr@uk.research.att.com>
To: Hai Wang <wangh@teltec.dcu.ie>
Copies to: omniorb-list@uk.research.att.com
Subject: Re: [omniORB] Naming Server--COMM-FAILURE
> On Tue, 29 Jun 1999, Hai Wang wrote:
>
> > Hi David,
> > Sorry to disturb you again, I tried to compare the "IOR"s
> > of the object reference from the server side and the client side.
> > although two values are different in stringified version, they are the same
> > in Catior version. Hence, I assume the object reference in the client is the
> > one registered by the server side with Naming service. But when the
> > object reference calls on its member function the COMM-FAILURE
> > still is thrown. Do you have any idea where the problem should be?
>
> Two questions:
>
> 1) Are you killing the server and restarting it (unlikely, I know)
No,
>
> 2) Does it work if you pass the stringified IOR directly to the client,
> without using the naming service?
No, I tried it before, That's why I change to use the naming server.
Hai
My Client and object implementation is briefed as follows
----------------------------------------------------------------------
/------------------------------------------------------------------------
//
// Client Implementation
//
//-----------------------------------------------------------------------
-//
CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv,
"omniORB2");
CORBA::BOA_ptr boa = orb->BOA_init(argc, argv,
"omniORB2_BOA");
try
{
CORBA::Object_ptr obj = getObjectReference(orb);
Hello(orb ,obj);
}
catch(CORBA::COMM_FAILURE& ex)
{
cerr << "Caught system exception COMM_FAILURE, unable
to contact the"
<<"object." <<endl;
}
catch(omniORB::fatalException& ex)
{
cerr << "Caught omniORB2 fatalException. This indicates a bug
is caught "
<< "within omniORB2.\nPlease send a bug report.\n"
<< "The exception was thrown in file: " << ex.file() << "\n" << "
line: " << ex.line() << "\n" << "The
error message is: " << ex.errmsg() << endl;
}
catch(...)
{
cerr << "Caught a system exception." << endl;
}
//----------------------------Client
End----------------------------------//
}
return nRetCode;
}
static
CORBA::Object_ptr
getObjectReference(CORBA::ORB_ptr orb)
{
CosNaming::NamingContext_var rootContext;
try {
// Obtain a reference to the root context of the Name service:
CORBA::Object_var initServ;
initServ = orb->resolve_initial_references("NameService");
CORBA::String_var tmp = orb->object_to_string(initServ);
cerr << "IOR of Init Server ==\n" << (char *)tmp <<endl;
// Narrow the object returned by resolve_initial_references()
// to a CosNaming::NamingContext object:
rootContext = CosNaming::NamingContext::_narrow(initServ);
if (CORBA::is_nil(rootContext))
{
cerr << "Failed to narrow naming context." << endl;
return CORBA::Object::_nil();
}
}
catch(CORBA::ORB::InvalidName& ex) {
cerr << "Service required is invalid [does not exist]." << endl;
return CORBA::Object::_nil();
}
// Create a name object, containing the name test/context:
CosNaming::Name name;
name.length(2);
name[0].id = (const char*) "test"; // string copied
name[0].kind = (const char*) "my_context"; // string copied
name[1].id = (const char*) "MConsumer";
name[1].kind = (const char*) "Object";
// Note on kind: The kind field is used to indicate the type
// of the object. This is to avoid conventions such as that used
// by files (name.type -- e.g. test.ps = postscript etc.)
CORBA::Object_ptr obj;
try {
// Resolve the name to an object reference, and assign the
reference
// returned to a CORBA::Object:
obj = rootContext->resolve(name);
}
catch(CosNaming::NamingContext::NotFound& ex)
{
// This exception is thrown if any of the components of the
// path [contexts or the object] aren't found:
cerr << "Context not found." << endl;
return CORBA::Object::_nil();
}
catch (CORBA::COMM_FAILURE& ex) {
cerr << "Caught system exception COMM_FAILURE, unable to
contact the "
<< "naming service." << endl;
return CORBA::Object::_nil();
}
catch(omniORB::fatalException& ex) {
throw;
}
catch (...) {
cerr << "Caught a system exception while using the naming
service."<< endl;
return CORBA::Object::_nil();
}
return obj;
}
void Hello(CORBA::ORB_ptr orb, CORBA::Object_ptr obj)
{
Metering::Consumer_var consumerRef =
Metering::Consumer::_narrow(obj);
if(CORBA::is_nil(consumerRef))
{
cerr << "Hello: cannot invoke on a nill object reference.\n"
<< endl;
return;
}
CORBA::String_var tmp = orb->object_to_string(consumerRef);
cerr << "IOR of consumerRef is: \n" << (char*)tmp <<endl;
CORBA::String_var src = (const char*)"Hello!";
consumerRef->pushStr(src);
}
Server:
//---------------------------------------------------------------//
// Server Implementation //
//---------------------------------------------------------------//
CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv,
"omniORB2");
CORBA::BOA_ptr boa = orb->BOA_init(argc, argv,
"omniORB2_BOA");
MConsumer_i* consumerObj = new MConsumer_i();
consumerObj->_obj_is_ready(boa);
{
Metering::Consumer_ptr consumerRef = consumerObj-
>_this();
CORBA::String_var tmp = orb-
>object_to_string(consumerRef);
cerr << "IOR of consumerRef is : " << endl << (char*)tmp
<<endl;
if(!bindObjectToName(orb, consumerRef))
{
return 1;
}
}
boa->impl_is_ready(0,1);
// Tell the BOA we are ready.
//--------------------Server End----------------------------//
}
return nRetCode;
}
static
CORBA::Boolean
bindObjectToName(CORBA::ORB_ptr orb, CORBA::Object_ptr obj)
{
// NEW CODES
Metering::Consumer_ptr testRef =
Metering::Consumer::_narrow(obj);
CORBA::String_var tmp = orb->object_to_string(obj);
cout << endl;
cout << "BEFORE Resolve refernce :" << endl;
cout << (char *) tmp << endl;
CosNaming::NamingContext_var rootContext;
try {
// Obtain a reference to the root context of the Name service:
CORBA::Object_var initServ;
initServ = orb->resolve_initial_references("NameService");
// Narrow the object returned by resolve_initial_references()
// to a CosNaming::NamingContext object:
rootContext = CosNaming::NamingContext::_narrow(initServ);
if (CORBA::is_nil(rootContext))
{
cerr << "Failed to narrow naming context." << endl;
return 0;
}
}
catch(CORBA::ORB::InvalidName& ex) {
cerr << "Service required is invalid [does not exist]." << endl;
return 0;
}
try {
// Bind a context called "test" to the root context:
CosNaming::Name contextName;
contextName.length(1);
contextName[0].id = CORBA::string_dup ("test"); // string
copied
contextName[0].kind = CORBA::string_dup ("my_context"); //
string copied
// Note on kind: The kind field is used to indicate the type
// of the object. This is to avoid conventions such as that used
// by files (name.type -- e.g. test.ps = postscript etc.)
CosNaming::NamingContext_var testContext;
try
{
// Bind the context to root, and assign testContext to it:
testContext = rootContext->bind_new_context(contextName);
}
catch(CosNaming::NamingContext::AlreadyBound& ex) {
// If the context already exists, this exception will be raised. //
In this case, just resolve the name and assign testContext // to
the
object returned: CORBA::Object_var tmpobj; tmpobj =
rootContext->resolve(contextName); testContext =
CosNaming::NamingContext::_narrow(tmpobj); if
(CORBA::is_nil(testContext)) {
cerr << "Failed to narrow naming context." << endl;
return 0;
}
}
// Bind the object (obj) to testContext, naming it Echo:
CosNaming::Name objectName;
objectName.length(1);
objectName[0].id = CORBA::string_dup ("MConsumer"); //
string copied
objectName[0].kind = CORBA::string_dup ("Object"); // string
copied
// Bind obj with name Echo to the testContext:
try
{
testContext->bind(objectName,obj);
}
catch(CosNaming::NamingContext::AlreadyBound& ex)
{
testContext->rebind(objectName, obj);
cerr << "Rebind is susessful" << endl;
}
//NEW CODES
try
{
CORBA::Object_var objVar = testContext-
>resolve(objectName);
Metering::Consumer_var consumerRef =
Metering::Consumer::_narrow(objVar);
CORBA::String_var tmp = orb-
>object_to_string(consumerRef);
cout << endl;
cout << "Resolve reference :" << endl;
cout << (char *) tmp << endl;
}
catch (...)
{
cout << "error with resolve reference" << endl;
}
// Note: Using rebind() will overwrite any Object previously bound
//
to /test/Echo with obj. // Alternatively, bind() can be
used, which will raise a //
CosNaming::NamingContext::AlreadyBound exception if the
name
// supplied is already bound to an object.
// Amendment: When using OrbixNames, it is necessary to first
try bind
// and then rebind, as rebind on it's own will throw a
NotFoundexception if
// the Name has not already been bound. [This is incorrect
behaviour -
// it should just bind].
}
catch (CORBA::COMM_FAILURE& ex) {
cerr << "Caught system exception COMM_FAILURE, unable to
contact the "
<< "naming service." << endl;
return 0;
}
catch (omniORB::fatalException& ex) {
throw;
}
catch (...)
{
cerr << "Caught a system exception while using the naming
service."<< endl;
return 0;
}
return 1;
}