//----------------------------------------------------------------------------- void BaseHelper::init(CosNaming::NamingContext_ptr nc_p) { //in this method, we take a look at the Naming Service to //see if the channel has been created before. if not, //we go ahead and create it and then register it with the CORBA //naming service namingContext_m = CosNaming::NamingContext::_duplicate(nc_p); if(CORBA::is_nil(namingContext_m.in())){ ACSErrTypeCORBA::CORBAReferenceNilExImpl ex(__FILE__, __LINE__, "BaseHelper::init"); ex.setVariable("namingContext_m"); throw ex; } //Common name sequence. This little object defines the name of //channel as registered with the CORBA Naming Service. CosNaming::Name name(1); name.length(1); //name of the channel name[0].id = CORBA::string_dup(channelName_mp); //channel kind name[0].kind = CORBA::string_dup(getChannelKind()); try { //use the naming service to get our object CORBA::Object_var ec_obj = namingContext_m->resolve(name); if(CORBA::is_nil(ec_obj.in())){ ACSErrTypeCORBA::FailedToResolveServiceExImpl ex(__FILE__, __LINE__, "BaseHelper::init"); throw ex; } //narrow it notifyChannel_m = CosNotifyChannelAdmin::EventChannel::_narrow(ec_obj.in()); if(CORBA::is_nil(notifyChannel_m.in())){ ACSErrTypeCORBA::NarrowFailedExImpl ex(__FILE__, __LINE__, "BaseHelper::init"); ex.setNarrowType("CosNotifyChannelAdmin::EventChannel"); throw ex; } } catch(CosNaming::NamingContext::NotFound ex) { //create it createNotificationChannel(); } initCalled_m = true; }
//----------------------------------------------------------------------------- void BaseHelper::attachChannelToNS() { //sanity check. If we cannot access the naming service, there is //no point whatsoever in continuing. if(CORBA::is_nil(namingContext_m)){ ACSErrTypeCORBA::CORBAReferenceNilExImpl ex(__FILE__, __LINE__, "BaseHelper::attachChannelToNS"); ex.setVariable("namingContext_m"); throw ex; } //name for our channel CosNaming::Name name(1); name.length(1); name[0].id = CORBA::string_dup(channelName_mp); name[0].kind = CORBA::string_dup(getChannelKind()); //really bind the reference here namingContext_m->rebind(name, notifyChannel_m.in()); }
//----------------------------------------------------------------------------- bool Helper::resolveNotifyChannel() { //commented out as per Rodrigo Amestica's request. //should be uncommented once a couple of ACS logging system SPRs get completed. //ACS_TRACE("Helper::resolveNotifyChannel"); CosNaming::Name name(1); name.length(1); name[0].id = CORBA::string_dup(channelAndDomainName_m.c_str()); name[0].kind = getChannelKind(); try { if(CORBA::is_nil(namingContext_m)) { ACS_SHORT_LOG((LM_ERROR,"Helper::resolveNotifyChannel Naming Context bad for the '%s' channel!", channelName_mp)); //This error is bad enough that we can thrown an exception CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Helper::resolveNotifyChannel"); throw err.getCORBAProblemEx(); return false; } CORBA::Object_var obj = namingContext_m->resolve(name); if(CORBA::is_nil(obj.in()) == true) { ACS_SHORT_LOG((LM_ERROR,"Helper::resolveNotifyChannel Notify Channel object bad for the '%s' channel!", channelName_mp)); //Hmm...can this really happen? In theory this would end up being a NotFound exception CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Helper::resolveNotifyChannel"); throw err.getCORBAProblemEx(); return false; } notifyChannel_m = CosNotifyChannelAdmin::EventChannel::_narrow(obj.in()); } catch(CosNaming::NamingContext::NotFound ex) { ACS_SHORT_LOG((LM_TRACE,"Helper::resolveNotifyChannel - this is expected when a channel is being created.")); //This is actually expected when creating a new channel, but still return false. return false; } catch(const CORBA::SystemException &ex) { ACS_SHORT_LOG((LM_ERROR, "Helper::resolveNotifyChannel CORBA System exception caught for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Helper::resolveNotifyChannel"); err.setMinor(ex.minor()); err.setCompletionStatus(ex.completed()); err.setInfo(ex._info().c_str()); throw err.getCORBAProblemEx(); return false; } catch(...) { ACS_SHORT_LOG((LM_ERROR, "Helper::resolveNotifyChannel Unknown exception caught for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Helper::resolveNotifyChannel"); throw err.getCORBAProblemEx(); return false; } if (CORBA::is_nil(notifyChannel_m)) { ACS_SHORT_LOG((LM_ERROR,"Helper::resolveNotifyChannel Notify channel bad for the '%s' channel!", channelName_mp)); CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Helper::resolveNotifyChannel"); throw err.getCORBAProblemEx(); return false; } //All went OK, so return true. return true; }