Exemplo n.º 1
0
//-----------------------------------------------------------------------------
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;
}
Exemplo n.º 2
0
bool Helper::resolveInternalNotificationChannel(){

    ACS_TRACE("Helper::resolveInternalNotificationChannel");
    AcsNCTraceLog::LOG_NC_ChannelCreated_ATTEMPT TS_NC_Attempt(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    TS_NC_Attempt.log();
    ACE_Time_Value start_time = ACE_OS::gettimeofday();
    ACE_Time_Value end_time;
    unsigned long msec = 0;
    int retryNumberAttempts = 20;
    int retrySleepSec = 2;
    bool existNotifyChannel = resolveNotifyChannel();
    if(!existNotifyChannel)
        resolveNotificationFactory();

    while(!existNotifyChannel && retryNumberAttempts >= 0){
        try{
            createNotificationChannel();
            end_time = ACE_OS::gettimeofday();
            msec = (end_time.sec() - start_time.sec()) * 1000 + (end_time.usec() - start_time.usec()) / 1000;
            AcsNCTraceLog::LOG_NC_ChannelCreated_OK TS_NC_OK(__FILE__, __LINE__, __PRETTY_FUNCTION__);
            TS_NC_OK.setChannelId(channelID_m);
            TS_NC_OK.setChannelName(channelName_mp);
            TS_NC_OK.setTimeMillis(msec);
        }catch(NotifyMonitoringExt::NameAlreadyUsed){
            ACS_SHORT_LOG((LM_INFO,"NC '%s' seems to be getting created. Will wait and try again in %d seconds.", channelName_mp, retrySleepSec));
        }catch(NotifyMonitoringExt::NameMapError){
            ACS_SHORT_LOG((LM_WARNING,"*** TODO check what this NameMapError means!!!"));
        }catch(...){
            ACS_SHORT_LOG((LM_WARNING,"Unexpected exception received while trying to create the notification channel %s",channelName_mp));
        }
        retryNumberAttempts--;
        sleep(retrySleepSec);
        existNotifyChannel = resolveNotifyChannel();
    }
    return existNotifyChannel;
}