📄 ft_faultdetectorfactory_i.cpp
字号:
}
return result;
}
int TAO::FT_FaultDetectorFactory_i::fini (ACE_ENV_SINGLE_ARG_DECL)
{
if (this->ior_output_file_ != 0)
{
ACE_OS::unlink (this->ior_output_file_);
this->ior_output_file_ = 0;
}
if (this->ns_name_ != 0)
{
this->naming_context_->unbind (this_name_
ACE_ENV_ARG_PARAMETER);
this->ns_name_ = 0;
}
if (this->registered_)
{
this->factory_registry_->unregister_factory(
FT::FAULT_DETECTOR_ROLE_NAME,
this->location_
ACE_ENV_ARG_PARAMETER);
ACE_CHECK_RETURN (-1);
this->registered_ = 0;
}
return 0;
}
CORBA::ULong TAO::FT_FaultDetectorFactory_i::allocate_id()
{
CORBA::ULong id = this->detectors_.size();
if (this->empty_slots_ != 0)
{
for(CORBA::ULong pos = 0; pos < id; ++pos)
{
if (this->detectors_[pos] == 0)
{
id = pos;
}
}
}
else
{
this->detectors_.push_back(0);
this->empty_slots_ += 1;
}
return id;
}
void TAO::FT_FaultDetectorFactory_i::remove_detector(CORBA::ULong id, TAO::Fault_Detector_i * detector)
{
InternalGuard guard (this->internals_);
if (id < this->detectors_.size())
{
if(this->detectors_[id] == detector)
{
delete this->detectors_[id];
this->detectors_[id] = 0;
this->empty_slots_ += 1;
if (this->empty_slots_ == this->detectors_.size())
{
ACE_ERROR (( LM_INFO,
"FaultDetectorFactory is idle.\n"
));
}
}
else
{
ACE_ERROR (( LM_ERROR,
"Remove detector %d mismatch.\n",
ACE_static_cast(int, id)
));
}
}
else
{
ACE_ERROR (( LM_ERROR,
"Attempt to remove invalid detector %d. Limit %d.\n",
ACE_static_cast(int, id),
ACE_static_cast(int, this->detectors_.size())
));
}
}
//////////////////////////////////////////
// FT_FaultDetectorFactory_i CORBA methods
void TAO::FT_FaultDetectorFactory_i::change_properties (
const PortableGroup::Properties & property_set
ACE_ENV_ARG_DECL
)
ACE_THROW_SPEC ((
CORBA::SystemException
, PortableGroup::InvalidProperty
))
{
METHOD_ENTRY(TAO::FT_FaultDetectorFactory_i::change_properties);
// TimeT is expressed in 10E-7 seconds (== 100 nSec == 0.1 uSec)
static const long timeT_per_uSec = 10L;
static const long uSec_per_sec = 1000000L;
::TAO::PG_Property_Set decoder(property_set);
TimeBase::TimeT value = 0;
if( TAO::find (decoder, FT::FT_FAULT_MONITORING_INTERVAL, value) )
{
// note: these should be unsigned long, but
// ACE_Time_Value wants longs.
long uSec = ACE_static_cast (long, (value / timeT_per_uSec) % uSec_per_sec);
long sec = ACE_static_cast (long, (value / timeT_per_uSec) / uSec_per_sec);
ACE_Time_Value atv(sec, uSec);
TAO::Fault_Detector_i::set_time_for_all_detectors(atv);
}
else
{
ACE_ERROR ((LM_ERROR,
"Throwing Invalid Property: %s\n",
FT::FT_FAULT_MONITORING_INTERVAL
));
::PortableGroup::InvalidProperty ex;
ex.nam.length(1);
ex.nam[0].id = CORBA::string_dup(FT::FT_FAULT_MONITORING_INTERVAL);
ACE_THROW (::PortableGroup::InvalidProperty (ex));
}
METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::change_properties);
}
void TAO::FT_FaultDetectorFactory_i::shutdown (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((
CORBA::SystemException
))
{
METHOD_ENTRY(TAO::FT_FaultDetectorFactory_i::shutdown);
InternalGuard guard (this->internals_);
shutdown_i ();
this->quit_requested_ = 1;
METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::shutdown);
}
CORBA::Object_ptr TAO::FT_FaultDetectorFactory_i::create_object (
const char * type_id,
const PortableGroup::Criteria & the_criteria,
PortableGroup::GenericFactory::FactoryCreationId_out factory_creation_id
ACE_ENV_ARG_DECL
)
ACE_THROW_SPEC ((
CORBA::SystemException
, PortableGroup::NoFactory
, PortableGroup::ObjectNotCreated
, PortableGroup::InvalidCriteria
, PortableGroup::InvalidProperty
, PortableGroup::CannotMeetCriteria
))
{
METHOD_ENTRY(TAO::FT_FaultDetectorFactory_i::create_object);
ACE_UNUSED_ARG (type_id); //@@ use it
InternalGuard guard (this->internals_);
::TAO::PG_Property_Set decoder (the_criteria);
// boolean, becomes true if a required parameter is missing
int missingParameter = 0;
const char * missingParameterName = 0;
FT::FaultNotifier_ptr notifier;
if (! ::TAO::find (decoder, ::FT::FT_NOTIFIER, notifier) )
{
if (! CORBA::is_nil (this->notifier_.in ()))
{
notifier = FT::FaultNotifier::_duplicate (this->notifier_.in ());
}
else
{
ACE_ERROR ((LM_ERROR,
"FaultDetectorFactory::create_object: Missing parameter %s\n",
::FT::FT_NOTIFIER
));
missingParameter = 1;
missingParameterName = ::FT::FT_NOTIFIER;
}
}
FT::PullMonitorable_ptr monitorable;
if (! ::TAO::find (decoder, ::FT::FT_MONITORABLE, monitorable) )
{
ACE_ERROR ((LM_ERROR,
"FaultDetectorFactory::create_object: Missing parameter %s\n",
::FT::FT_MONITORABLE
));
missingParameter = 1;
missingParameterName = ::FT::FT_MONITORABLE;
}
FT::FTDomainId domain_id = 0;
// note the cast in the next line makes ANY >>= work.
const char * domain_id_string = 0;
if (::TAO::find (decoder, ::FT::FT_DOMAIN_ID, domain_id_string) )
{
// NOTE the assumption that we can assign a char * to a domain id
domain_id = ACE_const_cast (char *, domain_id_string);
}
else
{
domain_id = this->domain_;
// ACE_ERROR ((LM_ERROR,
// "FaultDetectorFactory::create_object: Missing parameter %s\n",
// ::FT::FT_DOMAIN_ID
// ));
// missingParameter = 1;
// missingParameterName = ::FT::FT_DOMAIN_ID;
}
PortableGroup::Location * object_location = 0;
if (! ::TAO::find (decoder, ::FT::FT_LOCATION, object_location) )
{
object_location = & this->location_;
// ACE_ERROR ((LM_ERROR,
// "FaultDetectorFactory::create_object: Missing parameter %s\n",
// ::FT::FT_LOCATION
// ));
// missingParameter = 1;
// missingParameterName = ::FT::FT_LOCATION;
}
PortableGroup::TypeId object_type = 0;
const char * object_type_string;
if (::TAO::find (decoder, ::FT::FT_TYPE_ID, object_type_string))
{
object_type = ACE_const_cast (char *, object_type_string);
}
else
{
object_type = ACE_const_cast (char *, "unknown");
// Not required: missingParameter = 1;
ACE_DEBUG ((LM_DEBUG, "Object type not given.\n"));
}
FT::ObjectGroupId group_id = 0;
if (! ::TAO::find (decoder, ::FT::FT_GROUP_ID, group_id) )
{
// Not required: missingParameter = 1;
}
if (missingParameter)
{
ACE_ERROR ((LM_ERROR,
"Throwing 'InvalidCriteria' due to missing %s\n",
missingParameterName
));
ACE_THROW_RETURN ( PortableGroup::InvalidCriteria(), CORBA::Object::_nil () );
}
CORBA::ULong detectorId = allocate_id();
// NOTE: ACE_NEW is incompatable with auto_ptr
// so create a bare pointer first.
TAO::Fault_Detector_i * pFD = 0;
ACE_NEW_NORETURN(pFD, TAO::Fault_Detector_i(
*this,
detectorId,
notifier,
monitorable,
domain_id,
*object_location,
object_type,
group_id));
if (pFD == 0)
{
ACE_ERROR ((LM_ERROR,
"New FaultDetector_i returned NULL. Throwing ObjectNotCreated.\n"
));
ACE_THROW_RETURN ( PortableGroup::ObjectNotCreated(), CORBA::Object::_nil () );
}
auto_ptr<TAO::Fault_Detector_i> detector(pFD);
ACE_NEW_NORETURN ( factory_creation_id,
PortableGroup::GenericFactory::FactoryCreationId);
if (factory_creation_id.ptr() == 0)
{
ACE_ERROR ((LM_ERROR,
"New factory_creation_id returned NULL. Throwing ObjectNotCreated.\n"
));
ACE_THROW_RETURN ( PortableGroup::ObjectNotCreated(), CORBA::Object::_nil ());
}
(*factory_creation_id) <<= detectorId;
(*detector).start(this->threadManager_);
this->detectors_[detectorId] = detector.release();
this->empty_slots_ -= 1;
// since FaultDetector is not a CORBA object (it does not implement
// an interface.) we always return NIL;
METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::create_object)
CORBA::Object::_nil();
}
void TAO::FT_FaultDetectorFactory_i::delete_object (
const PortableGroup::GenericFactory::FactoryCreationId & factory_creation_id
ACE_ENV_ARG_DECL
)
ACE_THROW_SPEC ((
CORBA::SystemException
, PortableGroup::ObjectNotFound
))
{
METHOD_ENTRY(TAO::FT_FaultDetectorFactory_i::delete_object);
InternalGuard guard (this->internals_);
CORBA::ULong detectorId;
factory_creation_id >>= detectorId;
if (detectorId < this->detectors_.size())
{
if(this->detectors_[detectorId] != 0)
{
this->detectors_[detectorId]->request_quit();
}
else
{
ACE_THROW(::PortableGroup::ObjectNotFound());
}
}
else
{
ACE_THROW(::PortableGroup::ObjectNotFound());
}
METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::delete_object);
}
CORBA::Boolean TAO::FT_FaultDetectorFactory_i::is_alive (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((CORBA::SystemException))
{
METHOD_RETURN(TAO::FT_FaultDetectorFactory_i::is_alive)
1;
}
///////////////////////////////////
// Template instantiation for
// competence-challenged compilers.
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Vector<TAO::Fault_Detector_i *>;
template class ACE_Guard<ACE_SYNCH_MUTEX>;
template class auto_ptr<TAO::Fault_Detector_i>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
# pragma instantiate ACE_Vector<TAO::Fault_Detector_i *>
# pragma instantiate ACE_Guard<ACE_SYNCH_MUTEX>
# pragma instantiate auto_ptr<TAO::Fault_Detector_i>;
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -