diff options
26 files changed, 1095 insertions, 779 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 31758038ed8..45134529d95 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,68 @@ +Fri Oct 10 12:09:39 2003 Dale Wilson <wilson_d@ociweb.com> + + * orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h: + * orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp: + Use ACE MUTEX macros. + Avoid the evil _this(). + Use auto_ptr<>. + + * orbsvcs/Fault_Notifier/FT_Notifier_i.h: + * orbsvcs/Fault_Notifier/FT_Notifier_i.cpp: + Use ACE MUTEX macros. + Avoid the evil _this(). + + * orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h: + Contrary to my comment, it is necessary to check status after find fails. + Remove the comment; add the status check. + + * orbsvcs/tests/FT_App/FT_App.mpc: + Rename *Config project to *Creator + + * orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h: + * orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp: + New files replace StubConfig.cpp + + * orbsvcs/tests/FT_App/StubConfig.cpp: + Removed + + * orbsvcs/tests/FT_App/FT_Client.cpp: + Add a temporary hack to make the process containing TestReplicas go away sooner. Otherwise the test + timed out waiting for the TestReplicaFactory to notice it was idle. + + * orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h: + * orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp: + * orbsvcs/tests/FT_App/FT_TestReplica_i.h: + * orbsvcs/tests/FT_App/FT_TestReplica_i.cpp: + Add support for location and type_id. + Register the factory (or factories!) with the FactoryRegistry. + + * orbsvcs/tests/FT_App/FactoryRegistry_i.h: + * orbsvcs/tests/FT_App/FactoryRegistry_i.cpp: + Exit cleanly. Use _remove_ref() to determine when we're really gone. + Add additional logging. + + * orbsvcs/tests/FT_App/run_test_registry.pl: + Test is working. + + * orbsvcs/tests/FT_App/testscript: + Shorten sleep to make the test run faster + + + * tao/Utils/ServantMain.h: + * tao/Utils/ServantMain.cpp: + RIP: No remaining users. + Removed these files. + + * orbsvcs/tests/FT_App/StubBatchConsumer.h: + * orbsvcs/tests/FT_App/StubBatchConsumer.cpp: + * orbsvcs/tests/FT_App/StubFaultConsumer.h: + * orbsvcs/tests/FT_App/StubFaultConsumer.cpp: + * orbsvcs/tests/FT_App/StubFaultNotifier.cpp: + Ongoing work on conforming to ACE coding conventions. + + These changes were made in the oci_haft branch. + + Wed Oct 8 13:59:40 2003 Steve Totten <totten_s@ociweb.com> * orbsvcs/FT_ReplicationManager/FT_FaultConsumer.cpp: diff --git a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp index a7d1690c4c3..6f387b8d6e9 100644 --- a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp +++ b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp @@ -226,12 +226,12 @@ int TAO::FT_FaultDetectorFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) // find my IOR - CORBA::Object_var obj = + CORBA::Object_var this_obj = this->poa_->id_to_reference (objectId_.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - this->ior_ = this->orb_->object_to_string (obj.in () + this->ior_ = this->orb_->object_to_string (this_obj.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; @@ -270,7 +270,7 @@ int TAO::FT_FaultDetectorFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) this->this_name_.length (1); this->this_name_[0].id = CORBA::string_dup (this->ns_name_); - this->naming_context_->rebind (this->this_name_, _this() + this->naming_context_->rebind (this->this_name_, this_obj.in() //CORBA::Object::_duplicate(this_obj) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } @@ -481,7 +481,7 @@ CORBA::Object_ptr TAO::FT_FaultDetectorFactory_i::create_object ( CORBA::ULong detectorId = allocate_id(); - // NOTE: ACE_NEW is incompatable with ACE_Auto_Basic_Ptr + // NOTE: ACE_NEW is incompatable with auto_ptr // so create a bare pointer first. TAO::Fault_Detector_i * pFD = 0; @@ -501,7 +501,7 @@ CORBA::Object_ptr TAO::FT_FaultDetectorFactory_i::create_object ( )); ACE_THROW ( PortableGroup::ObjectNotCreated() ); } - ACE_Auto_Basic_Ptr<TAO::Fault_Detector_i> detector(pFD); + auto_ptr<TAO::Fault_Detector_i> detector(pFD); ACE_NEW_NORETURN ( factory_creation_id, PortableGroup::GenericFactory::FactoryCreationId); @@ -572,9 +572,11 @@ CORBA::Boolean TAO::FT_FaultDetectorFactory_i::is_alive (ACE_ENV_SINGLE_ARG_DECL #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template ACE_Vector<TAO::Fault_Detector_i *>; - template ACE_Guard<ACE_Mutex>; + template ACE_Guard<ACE_SYNCH_MUTEX>; + template auto_ptr<TAO::Fault_Detector_i>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) # pragma instantiate ACE_Vector<TAO::Fault_Detector_i *> -# pragma ACE_Guard<ACE_Mutex> +# pragma instantiate ACE_Guard<ACE_SYNCH_MUTEX> +# pragma instantiate auto_ptr<TAO::Fault_Detector_i>; #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h index 800a858ea52..4561860c82d 100644 --- a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h +++ b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.h @@ -232,8 +232,8 @@ namespace TAO * Implementation methods should assume the mutex is * locked if necessary. */ - ACE_Mutex internals_; - typedef ACE_Guard<ACE_Mutex> InternalGuard; + ACE_SYNCH_MUTEX internals_; + typedef ACE_Guard<ACE_SYNCH_MUTEX> InternalGuard; /** * The orb diff --git a/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.cpp b/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.cpp index 60799e18807..933e77fd05a 100644 --- a/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.cpp +++ b/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.cpp @@ -239,12 +239,12 @@ int TAO::FT_FaultNotifier_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL ) // find my IOR - CORBA::Object_var obj = + CORBA::Object_var this_obj = this->poa_->id_to_reference (object_id_.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - this->ior_ = this->orb_->object_to_string (obj.in () + this->ior_ = this->orb_->object_to_string (this_obj.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; @@ -393,7 +393,7 @@ int TAO::FT_FaultNotifier_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL ) this->this_name_.length (1); this->this_name_[0].id = CORBA::string_dup (this->ns_name_); - this->naming_context_->rebind (this->this_name_, _this() + this->naming_context_->rebind (this->this_name_, this_obj.in() //CORBA::Object::_duplicate(this_obj) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } @@ -672,3 +672,8 @@ TAO::FT_FaultNotifier_i::ProxyInfo::ProxyInfo (const ProxyInfo & rhs) , proxyVar_ (rhs.proxyVar_) { } +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + template ACE_Guard<ACE_SYNCH_MUTEX>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +# pragma instantiate ACE_Guard<ACE_SYNCH_MUTEX> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.h b/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.h index 468396348f3..3981088720e 100644 --- a/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.h +++ b/TAO/orbsvcs/Fault_Notifier/FT_Notifier_i.h @@ -167,8 +167,8 @@ namespace TAO * Implementation methods should assume the mutex is * locked if necessary. */ - ACE_Mutex internals_; - typedef ACE_Guard<ACE_Mutex> InternalGuard; + ACE_SYNCH_MUTEX internals_; + typedef ACE_Guard<ACE_SYNCH_MUTEX> InternalGuard; /** * The orb diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h index 355a93fc0ce..ee73d1ddc59 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_Properties_Decoder.h @@ -54,12 +54,13 @@ namespace TAO_PG template <typename TYPE> int find (Properties_Decoder & decoder, const ACE_CString & key, TYPE & value) { + int result = 0; PortableGroup::Value * any; - decoder.find (key, any); - // if find fails, any will be empty and the attempt to extract - // the value will fail, so there's no need to check status - // on the find. - return ((*any) >>= value); + if ( decoder.find (key, any)) + { + result = ((*any) >>= value); + } + return result; } #ifdef PG_PS_UNIT_TEST diff --git a/TAO/orbsvcs/tests/FT_App/FT_App.mpc b/TAO/orbsvcs/tests/FT_App/FT_App.mpc index c360c591d9d..15aba7e7be3 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_App.mpc +++ b/TAO/orbsvcs/tests/FT_App/FT_App.mpc @@ -114,11 +114,11 @@ project(*FactoryRegistry): taoclient, fault_tolerance, orbsvcsexe { } } -project(*Config): taoclient, fault_tolerance, orbsvcsexe { - exename = ft_config +project(*Creator): taoclient, fault_tolerance, orbsvcsexe { + exename = ft_create Source_Files { - StubConfig.cpp + TAO_Object_Group_Creator.cpp } // explicitly omit IDL files diff --git a/TAO/orbsvcs/tests/FT_App/FT_Client.cpp b/TAO/orbsvcs/tests/FT_App/FT_Client.cpp index ba213f282d9..a41f99c9b19 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_Client.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_Client.cpp @@ -468,8 +468,11 @@ int FTClientMain::pass ( { std::cout << "FT Client: ->shutdown();" << std::endl; } -std::cout << "call shutdown" << std::endl; ft_server->shutdown( ACE_ENV_SINGLE_ARG_PARAMETER); + // @@ Note: this is here because the corba event loop seems to go to sleep + // if there's nothing for it to do. + // not quite sure why, yet. Dale + ft_server->is_alive(ACE_ENV_SINGLE_ARG_PARAMETER); } ACE_CATCHANY { diff --git a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp index 43436c3aa01..98b0dd37978 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp @@ -42,6 +42,10 @@ return /* value goes here */ +static const char * type_property = "type"; + +static const char * type_initial_value = "INITIAL_VALUE"; + ////////////////////////////////////////////////////// // FT_ReplicaFactory_i Construction/destruction @@ -50,9 +54,9 @@ FT_ReplicaFactory_i::FT_ReplicaFactory_i () , factory_registry_ior_file_(0) , registered_(0) , ns_name_(0) - , type_id_(0) , location_(0) , quit_on_idle_(0) + , unregister_by_location_(0) , test_output_file_(0) , empty_slots_(0) , quit_requested_(0) @@ -134,7 +138,7 @@ int FT_ReplicaFactory_i::write_ior(const char * outputFile, const char * ior) int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) { - ACE_Get_Opt get_opts (argc, argv, "o:n:f:i:l:t:q"); + ACE_Get_Opt get_opts (argc, argv, "o:n:f:i:l:t:qu"); int c; while ((c = get_opts ()) != -1) @@ -158,7 +162,7 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) } case 'i': { - this->type_id_ = get_opts.opt_arg (); + this->types_.push_back(get_opts.opt_arg ()); break; } case 'l': @@ -171,6 +175,11 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) this->quit_on_idle_ = 1; break; } + case 'u': + { + this->unregister_by_location_ = 1; + break; + } case 't': { @@ -189,6 +198,7 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) " -i <registration: type_id>" " -l <registration: location>" " -t <test replica ior file>" + " -u{nregister by location}" " -q{uit on idle}" "\n", argv [0]), @@ -200,6 +210,11 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) return 0; } +const char * FT_ReplicaFactory_i::location () const +{ + return this->location_; +} + const char * FT_ReplicaFactory_i::identity () const { return this->identity_.c_str(); @@ -236,7 +251,8 @@ int FT_ReplicaFactory_i::idle (int & result) if (this->quit_on_idle_ && this->empty_slots_ != 0) { ACE_ERROR (( LM_ERROR, - "ReplicaFactory exits due to quit on idle option.\n" + "%s exits due to quit on idle option.\n", + identity() )); quit = 1; } @@ -248,13 +264,6 @@ int FT_ReplicaFactory_i::idle (int & result) int FT_ReplicaFactory_i::fini (ACE_ENV_SINGLE_ARG_DECL) { -static bool hasFinied = false; -if(hasFinied) -{ - ACE_ERROR((LM_ERROR, "******************************************FINI CALLED TWICE!*********************\n" - )); -} -hasFinied = true; if (this->ior_output_file_ != 0) { ACE_OS::unlink (this->ior_output_file_); @@ -271,19 +280,45 @@ hasFinied = true; if (registered_) { registered_ = 0; - ACE_ERROR (( LM_INFO, - "%s Unregistering from factory registry\n", - identity() - )); - - PortableGroup::Location location(1); - location.length(1); - location[0].id = CORBA::string_dup(location_); - this->factory_registry_->unregister_factory ( - this->type_id_, - location - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; + + if (this->unregister_by_location_) + { + ACE_ERROR (( LM_INFO, + "%s: unregistering all factories at %s\n", + identity(), + location_ + )); + + PortableGroup::Location location(1); + location.length(1); + location[0].id = CORBA::string_dup(location_); + this->factory_registry_->unregister_factory_by_location ( + location + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + else + { + size_t typeCount = types_.size(); + for (size_t nType = 0; nType < typeCount; ++nType) + { + const char * typeId = this->types_[nType].c_str(); + ACE_ERROR (( LM_INFO, + "Factory for: %s@%s unregistering from factory registry\n", + typeId, + location_ + )); + + PortableGroup::Location location(1); + location.length(1); + location[0].id = CORBA::string_dup(location_); + this->factory_registry_->unregister_factory ( + typeId, + location + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + } } return 0; @@ -357,16 +392,33 @@ int FT_ReplicaFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) ::PortableGroup::GenericFactory_var this_var = ::PortableGroup::GenericFactory::_narrow(this_obj); if (! CORBA::is_nil(this_var)) { - PortableGroup::FactoryInfo info; - info.the_factory = this_var; - info.the_location.length(1); - info.the_location[0].id = CORBA::string_dup(location_); - info.the_criteria.length(0); - - factory_registry_->register_factory( - this->type_id_, - info - ACE_ENV_ARG_PARAMETER); + + size_t typeCount = types_.size(); + for (size_t nType = 0; nType < typeCount; ++nType) + { + const char * typeId = this->types_[nType].c_str(); + + PortableGroup::FactoryInfo info; + info.the_factory = this_var; + info.the_location.length(1); + info.the_location[0].id = CORBA::string_dup(location_); + info.the_criteria.length(1); + info.the_criteria[0].nam.length(1); + info.the_criteria[0].nam[0].id = CORBA::string_dup(type_property); + info.the_criteria[0].val <<= CORBA::string_dup(typeId); + + ACE_ERROR (( LM_INFO, + "Factory: %s@%s registering with factory registry\n", + typeId, + location_ + )); + + factory_registry_->register_factory( + typeId, + info + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } this->registered_ = 1; } else @@ -396,9 +448,9 @@ int FT_ReplicaFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) } int identified = 0; // bool - if (this->type_id_ != 0) + if (this->types_.size() > 0) { - this->identity_ = type_id_; + this->identity_ = "Factory"; if (this->location_ != 0) { this->identity_ += "@"; @@ -449,7 +501,7 @@ int FT_ReplicaFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) this->this_name_.length (1); this->this_name_[0].id = CORBA::string_dup (this->ns_name_); - this->naming_context_->rebind (this->this_name_, _this() + this->naming_context_->rebind (this->this_name_, this_obj.in() // CORBA::Object::_duplicate(this_obj) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } @@ -459,7 +511,7 @@ int FT_ReplicaFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) { // shouldn't be necessary, but create_replica assumes this InternalGuard guard (this->internals_); - FT_TestReplica_i * replica = create_replica (); + FT_TestReplica_i * replica = create_replica ("test"); PortableServer::POA_var poa = replica->_default_POA (ACE_ENV_SINGLE_ARG_PARAMETER); ACE_TRY_CHECK; @@ -557,11 +609,22 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( const char * missingParameterName = 0; CORBA::Long initialValue = 0; - if (! ::TAO_PG::find (decoder, "INITIAL_VALUE", initialValue) ) + if (! ::TAO_PG::find (decoder, type_initial_value, initialValue) ) { // not required. Otherwise: // missingParameter = 1; - // missingParameterName = "INITIAL_VALUE"; + // missingParameterName = type_initial_value; + } + + const char * type = "replica"; + if (! ::TAO_PG::find (decoder, type_property, type) ) + { + ACE_ERROR((LM_INFO, + "Property \"%s\" not found?\n", type_property + )); + // not required. Otherwise: + // missingParameter = 1; + // missingParameterName = "type"; } if (missingParameter) @@ -573,7 +636,7 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( ACE_THROW ( PortableGroup::InvalidCriteria() ); } - FT_TestReplica_i * replica = create_replica(); + FT_TestReplica_i * replica = create_replica(type); if (replica == 0) { ACE_ERROR ((LM_ERROR, @@ -582,23 +645,22 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( ACE_THROW ( PortableGroup::ObjectNotCreated() ); } - 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_NEW_THROW_EX ( factory_creation_id, + PortableGroup::GenericFactory::FactoryCreationId, + PortableGroup::ObjectNotCreated()); + CORBA::ULong factory_id = replica->factory_id(); + (*factory_creation_id) <<= factory_id; + + ACE_ERROR ((LM_INFO, + "Created %s@%s#%d.\n", type, this->location_, ACE_static_cast(int, factory_id) + )); - ACE_THROW ( PortableGroup::ObjectNotCreated() ); - } - (*factory_creation_id) <<= replica->factory_id(); ::CORBA::Object_ptr replica_obj = replica->_default_POA()->servant_to_reference(replica); METHOD_RETURN(FT_ReplicaFactory_i::create_object) replica_obj->_duplicate(replica_obj ACE_ENV_ARG_PARAMETER); } -FT_TestReplica_i * FT_ReplicaFactory_i::create_replica() +FT_TestReplica_i * FT_ReplicaFactory_i::create_replica(const char * name) { // assume mutex is locked CORBA::ULong factoryId = allocate_id(); @@ -606,6 +668,7 @@ FT_TestReplica_i * FT_ReplicaFactory_i::create_replica() FT_TestReplica_i * pFTReplica = 0; ACE_NEW_NORETURN(pFTReplica, FT_TestReplica_i( this, + name, factoryId )); this->replicas_[factoryId] = pFTReplica; @@ -675,7 +738,9 @@ void FT_ReplicaFactory_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template ACE_Vector<FT_TestReplica_i *>; template ACE_Guard<ACE_Mutex>; + template ACE_Vector<ACE_CString>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) # pragma instantiate ACE_Vector<FT_TestReplica_i *> -# pragma ACE_Guard<ACE_Mutex> +# pragma instantiate ACE_Guard<ACE_Mutex> +# pragma instantiate ACE_Vector<ACE_CString> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h index 3445b15fc12..e89f45a6552 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h @@ -43,6 +43,7 @@ class FT_ReplicaFactory_i : public virtual POA_FT_TEST::ReplicaFactory { typedef ACE_Vector<FT_TestReplica_i *> ReplicaVec; + typedef ACE_Vector<ACE_CString> StringVec; ////////////////////// // non-CORBA interface @@ -87,6 +88,8 @@ public: */ const char * identity () const; + const char * location () const; + /** * Remove pointer to individual replica; delete FT_TestReplica_i. * See replica life cycle description. @@ -141,8 +144,9 @@ public: private: /** * Actual replica creation happens in this method. + * @param name becomes part of the objects identity. */ - FT_TestReplica_i * create_replica(); + FT_TestReplica_i * create_replica(const char * name); /** * Find or allocate an ID for a new replica @@ -239,15 +243,21 @@ private: CosNaming::Name this_name_; -//todo initialize - const char * type_id_; + StringVec types_; + const char * location_; /** - * Quit on idle flag. + * bool: quit on idle flag. */ int quit_on_idle_; + + /** + * bool: use a single call to unregister. + */ + int unregister_by_location_; + /** * A vector of Replicas. Note that the Replica ID * is an index into this vector. diff --git a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp index a8f51e0c1b0..242f1753f48 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp @@ -85,8 +85,9 @@ namespace ////////////////////////////////////////////////// // class FT_TestReplica_i construction/destruction -FT_TestReplica_i::FT_TestReplica_i (FT_ReplicaFactory_i * factory, long factory_id) +FT_TestReplica_i::FT_TestReplica_i (FT_ReplicaFactory_i * factory, const char * name, unsigned long factory_id) : factory_(factory) + , name_(name) , factory_id_(factory_id) , death_pending_(FT_TEST::TestReplica::NOT_YET) , verbose_(1) @@ -100,7 +101,7 @@ FT_TestReplica_i::~FT_TestReplica_i () void FT_TestReplica_i::suicide(const char * note) { - std::cout << this->factory_->identity() << '#' << this->factory_id_ << " Simulate fault: " << note << std::endl; + std::cout << name_.c_str() << '@' << this->factory_->location() << '#' << this->factory_id_ << " Simulate fault: " << note << std::endl; // Tell the poa we aren't accepting future calls this->poa_->deactivate_object (this->object_id_.in () @@ -122,7 +123,7 @@ FT_TestReplica_i::usage_options() return ""; } -long FT_TestReplica_i::factory_id()const +unsigned long FT_TestReplica_i::factory_id()const { return this->factory_id_; } @@ -209,8 +210,9 @@ CORBA::Boolean FT_TestReplica_i::is_alive () { KEVORKIAN(DURING_IS_ALIVE, is_alive) ACE_ERROR ((LM_ERROR, - "%s#%d: is_alive: %d\n", - this->factory_->identity(), + "%s@%s#%d: is_alive: %d\n", + this->name_.c_str(), + this->factory_->location(), this->factory_id_, (this->death_pending_ != FT_TEST::TestReplica::DENY_IS_ALIVE) )); @@ -328,7 +330,7 @@ void FT_TestReplica_i::die (FT_TEST::TestReplica::Bane when ACE_ENV_ARG_DECL) ACE_THROW_SPEC ((CORBA::SystemException)) { - std::cout << this->factory_->identity() << '#' << this->factory_id_ << " Received death threat: " << when << std::endl; + std::cout << name_.c_str() << '@' << this->factory_->location() << '#' << this->factory_id_ << " Received death threat: " << when << std::endl; this->death_pending_ = when; KEVORKIAN(RIGHT_NOW, die) @@ -337,7 +339,7 @@ void FT_TestReplica_i::die (FT_TEST::TestReplica::Bane when void FT_TestReplica_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) ACE_THROW_SPEC ((CORBA::SystemException)) { - std::cout << this->factory_->identity() << '#' << this->factory_id_ << " Shut down requested" << std::endl; + std::cout << name_.c_str() << '@' << this->factory_->location() << '#' << this->factory_id_ << " Shut down requested" << std::endl; this->death_pending_ = FT_TEST::TestReplica::CLEAN_EXIT; } @@ -349,8 +351,9 @@ int FT_TestReplica_i::idle (int & result) if (this->death_pending_ == FT_TEST::TestReplica::WHILE_IDLE) { ACE_ERROR ((LM_ERROR, - "%s#%d: Simulated fault WHILE_IDLE", - this->factory_->identity(), + "%s@%s#%d: Simulated fault WHILE_IDLE", + this->name_.c_str(), + this->factory_->location(), ACE_static_cast(int, this->factory_id_ ) )); this->poa_->deactivate_object (this->object_id_.in () @@ -385,7 +388,7 @@ void FT_TestReplica_i::store(long counter) ACE_OS::fclose(f); if (this->verbose_) { - std::cout << this->factory_->identity() << '#' << this->factory_id_ << ": " << counter << std::endl; + std::cout << name_.c_str() << '@' << this->factory_->location() << '#' << this->factory_id_ << ": " << counter << std::endl; } } } @@ -423,5 +426,3 @@ long FT_TestReplica_i::load () # pragma long loadLong(const unsigned char * & state, size_t offset) #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ - - diff --git a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h index a3a899ddb39..f1bf1efbd4d 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h +++ b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h @@ -33,7 +33,7 @@ class FT_ReplicaFactory_i; class FT_TestReplica_i : public virtual POA_FT_TEST::TestReplica { public: - FT_TestReplica_i (FT_ReplicaFactory_i * factory, long factory_id); + FT_TestReplica_i (FT_ReplicaFactory_i * factory, const char * name, unsigned long factory_id); virtual ~FT_TestReplica_i (); /** @@ -76,7 +76,7 @@ public: void request_quit(); - long factory_id()const; + unsigned long factory_id()const; ::FT_TEST::TestReplica_ptr object_reference(); @@ -167,9 +167,14 @@ private: int verbose_; /** + * who am I? + */ + ACE_CString name_; + + /** * The ID number assigned by the factory */ - long factory_id_; + unsigned long factory_id_; /** * the factory that created thsi replica @@ -177,7 +182,7 @@ private: FT_ReplicaFactory_i * factory_; /** - * The orb + * The orb */ CORBA::ORB_var orb_; diff --git a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp index 9a3b2dc9016..ecdd28fd6af 100644 --- a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp @@ -37,8 +37,8 @@ FactoryRegistry_i::FactoryRegistry_i () : ior_output_file_(0) , ns_name_(0) , quit_on_idle_(0) - , quit_requested_(0) - + , quit_state_(LIVE) + , linger_(0) { } @@ -91,10 +91,27 @@ const char * FactoryRegistry_i::identity () const return this->identity_.c_str(); } + +void FactoryRegistry_i::_remove_ref (ACE_ENV_SINGLE_ARG_DECL) +{ + this->quit_state_ = GONE; +} + int FactoryRegistry_i::idle (int & result) { result = 0; - int quit = this->quit_requested_; + int quit = 0; + if (this->quit_state_ == GONE) + { + if (linger_ < 2) + { + ++linger_; + } + else + { + quit = 1; + } + } return quit; } @@ -154,18 +171,17 @@ int FactoryRegistry_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) ACE_TRY_CHECK; // Register with the POA. - this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - // find my IOR - - CORBA::Object_var obj = + // find my identity as a corba object + CORBA::Object_var this_obj = this->poa_->id_to_reference (object_id_.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - this->ior_ = this->orb_->object_to_string (obj.in () + // and create a ior string + this->ior_ = this->orb_->object_to_string (this_obj.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; @@ -205,7 +221,7 @@ int FactoryRegistry_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) this->this_name_.length (1); this->this_name_[0].id = CORBA::string_dup (this->ns_name_); - this->naming_context_->rebind (this->this_name_, _this() + this->naming_context_->rebind (this->this_name_, this_obj.in() //CORBA::Object::_duplicate(this_obj) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } @@ -270,9 +286,9 @@ void FactoryRegistry_i::register_factory ( (*infos)[length] = factory_info; ACE_DEBUG(( LM_DEBUG, - "FactoryRegistry: Added factory: %s[%d] at %s\n", - type_id, + "FactoryRegistry: Added factory: [%d] %s@%s \n", ACE_static_cast(int,length + 1), + type_id, ACE_static_cast(const char *, factory_info.the_location[0].id) )); @@ -304,7 +320,7 @@ void FactoryRegistry_i::unregister_factory ( found = 1; ACE_ERROR(( LM_INFO, - "Unregistering factory %s at location %s\n", + "Unregistering factory %s@%s\n", type_id, ACE_static_cast(const char *, location[0].id) )); @@ -312,16 +328,31 @@ void FactoryRegistry_i::unregister_factory ( { while (nInfo + 1 < length) { + ACE_ERROR((LM_INFO, + "unregister_factory_by_location: Move: [%d] %s to [%d]\n", + (int)nInfo + 1, type_id, (int)nInfo + )); (*infos)[nInfo] = (*infos)[nInfo + 1]; nInfo += 1; } + ACE_ERROR((LM_INFO, + "unregister_factory_by_location: New length [%d] %s\n", + (int)nInfo, type_id + )); infos->length(nInfo); } else { - assert ( length == 1 ); - this->registry_.unbind (type_id); - delete infos; + ACE_ASSERT ( length == 1 ); + if (this->registry_.unbind (type_id) == 0) + { + delete infos; + } + else + { + ACE_ERROR ((LM_ERROR, + "LOGIC ERROR AT " __FILE__ " (%d): Entry to be deleted disappeared\n", __LINE__)); + } } } } @@ -336,12 +367,18 @@ void FactoryRegistry_i::unregister_factory ( this->registry_.bind(type_id, infos); } - if (registry_.current_size() == 0) + if (registry_.current_size() == 0 && quit_state_ == LIVE) { ACE_ERROR(( LM_INFO, - "FactoryRegistry is idle\n" + "%s is idle\n", + identity() )); - this->quit_requested_ |= this->quit_on_idle_; + if (quit_on_idle_) + { + this->poa_->deactivate_object (this->object_id_.in () + ACE_ENV_ARG_PARAMETER); + quit_state_ = DEACTIVATED; + } } METHOD_RETURN(FactoryRegistry_i::unregister_factory); @@ -355,7 +392,7 @@ void FactoryRegistry_i::unregister_factory_by_type ( { METHOD_ENTRY(FactoryRegistry_i::unregister_factory_by_type); PortableGroup::FactoryInfos * infos; - if (this->registry_.unbind(type_id, infos) ) + if (this->registry_.unbind(type_id, infos) == 0) { ACE_DEBUG(( LM_DEBUG, "Unregistering all factories for type %s\n", type_id @@ -370,12 +407,18 @@ void FactoryRegistry_i::unregister_factory_by_type ( )); } - if (registry_.current_size() == 0) + if (registry_.current_size() == 0 && quit_state_ == LIVE) { ACE_ERROR(( LM_INFO, - "FactoryRegistry is idle\n" + "%s is idle\n", + identity() )); - this->quit_requested_ |= this->quit_on_idle_; + if (quit_on_idle_) + { + this->poa_->deactivate_object (this->object_id_.in () + ACE_ENV_ARG_PARAMETER); + quit_state_ = DEACTIVATED; + } } METHOD_RETURN(FactoryRegistry_i::unregister_factory_by_type); @@ -397,7 +440,9 @@ void FactoryRegistry_i::unregister_factory_by_location ( ++it) { RegistryType_Entry & entry = *it; + ACE_CString & type = entry.ext_id_; PortableGroup::FactoryInfos * infos = entry.int_id_; + // ACE_ERROR((LM_INFO, "unregister_factory_by_location: Checking type %s\n", type.c_str() )); int found = 0; size_t length = infos->length(); @@ -406,19 +451,36 @@ void FactoryRegistry_i::unregister_factory_by_location ( PortableGroup::FactoryInfo & info = (*infos)[nInfo]; if (info.the_location == location) { + + ACE_ERROR((LM_INFO, + "unregister_factory_by_location: Removing: [%d] %s@%s\n", + (int)nInfo, type.c_str(), location[0].id + )); found = 1; if (length > 1) { while (nInfo + 1 < length) { - infos[nInfo] = infos[nInfo + 1]; + ACE_ERROR((LM_INFO, + "unregister_factory_by_location: Move: [%d] %s to [%d]\n", + (int)nInfo + 1, type.c_str(), (int)nInfo + )); + (*infos)[nInfo] = (*infos)[nInfo + 1]; nInfo += 1; } + ACE_ERROR((LM_INFO, + "unregister_factory_by_location: New length [%d] %s\n", + (int)nInfo, type.c_str() + )); infos->length(nInfo); } else { - assert ( length == 1 ); + ACE_ERROR((LM_INFO, + "Removed all entries for %s\n", + type.c_str() + )); + ACE_ASSERT ( length == 1 ); // remember entries to be deleted hitList.push_back(entry.ext_id_); } @@ -430,28 +492,38 @@ void FactoryRegistry_i::unregister_factory_by_location ( for (size_t nHit = 0; nHit < hitList.size(); ++nHit) { + ACE_ERROR((LM_INFO, + "Remove type %s\n", + hitList[nHit].c_str() + )); PortableGroup::FactoryInfos * infos; - if (this->registry_.unbind(hitList[nHit], infos) ) + if (this->registry_.unbind(hitList[nHit], infos) == 0) { delete infos; } else { ACE_ERROR ((LM_ERROR, - "LOGIC ERROR AT " __FILE__ " (%d): Entry to be deleted disappeared\n", __LINE__)); + "LOGIC ERROR AT " __FILE__ " (%d): Entry to be deleted disappeared\n", + __LINE__)); } } ////////////////////////// // If all types are gone... - if (registry_.current_size() == 0) + if (registry_.current_size() == 0 && quit_state_ == LIVE) { ACE_ERROR(( LM_INFO, - "FactoryRegistry is idle\n" + "%s is idle\n", + identity() )); - this->quit_requested_ |= this->quit_on_idle_; + if (quit_on_idle_) + { + this->poa_->deactivate_object (this->object_id_.in () + ACE_ENV_ARG_PARAMETER); + quit_state_ = DEACTIVATED; + } } - METHOD_RETURN(FactoryRegistry_i::unregister_factory_by_location); } diff --git a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h index ca41d740c58..0b6be66828b 100644 --- a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h +++ b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h @@ -90,6 +90,10 @@ public: */ const char * identity () const; + //////////////////////////////// + // override servant base methods + virtual void _remove_ref (ACE_ENV_SINGLE_ARG_DECL); + ////////////////// // CORBA interface // See IDL for documentation @@ -201,10 +205,11 @@ private: int quit_on_idle_; /** - * boolean: starts false. Set to true when it's time to quit. + * State of the quit process */ - int quit_requested_; + enum {LIVE, DEACTIVATED, GONE} quit_state_; + int linger_; RegistryType registry_; diff --git a/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.cpp b/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.cpp index 4b3bbec4533..106676a6a22 100644 --- a/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.cpp @@ -33,7 +33,7 @@ int StubBatchConsumer::parse_args (int argc, char * argv[]) PortableServer::ObjectId StubBatchConsumer::objectId()const { - return this->objectId_.in(); + return this->object_id_.in(); } @@ -44,6 +44,9 @@ int StubBatchConsumer::init (CORBA::ORB_var & orb, ::FT::FaultNotifier_var & not { int result = 0; this->orb_ = orb; + this->notifier_ = notifier; + this->identity_ = "StubBatchConsumer"; + // Use the ROOT POA for now CORBA::Object_var poa_object = @@ -56,9 +59,8 @@ int StubBatchConsumer::init (CORBA::ORB_var & orb, ::FT::FaultNotifier_var & not ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")), -1); - // Get the POA object. - this->poa_ = - PortableServer::POA::_narrow (poa_object.in () + // Get the POA . + this->poa_ = PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER); ACE_CHECK_RETURN (-1); @@ -79,17 +81,20 @@ int StubBatchConsumer::init (CORBA::ORB_var & orb, ::FT::FaultNotifier_var & not // Register with the POA. - this->objectId_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - this->notifier_ = notifier; + // find my identity as an object - this->identity_ = "StubBatchConsumer"; + CORBA::Object_var this_obj = + this->poa_->id_to_reference (object_id_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; CosNotifyFilter::Filter_var filter = CosNotifyFilter::Filter::_nil(); - this->consumerId_ = notifier->connect_sequence_fault_consumer( - _this(), + this->consumer_id_ = notifier->connect_sequence_fault_consumer( + CosNotifyComm::SequencePushConsumer::_narrow(this_obj), filter); return result; @@ -108,7 +113,7 @@ const char * StubBatchConsumer::identity () const */ void StubBatchConsumer::fini (ACE_ENV_SINGLE_ARG_DECL) { - this->notifier_->disconnect_consumer(this->consumerId_ ACE_ENV_ARG_PARAMETER); + this->notifier_->disconnect_consumer(this->consumer_id_ ACE_ENV_ARG_PARAMETER); } diff --git a/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.h b/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.h index a2ecde5b714..1a99f8cb320 100644 --- a/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.h +++ b/TAO/orbsvcs/tests/FT_App/StubBatchConsumer.h @@ -106,7 +106,7 @@ private: // Data Members private: /** - * The orb + * The orb */ CORBA::ORB_var orb_; @@ -118,7 +118,7 @@ private: /** * The CORBA object id assigned to this object. */ - PortableServer::ObjectId_var objectId_; + PortableServer::ObjectId_var object_id_; /** * A human-readable string to distinguish this from other FaultConsumers. @@ -138,7 +138,7 @@ private: /** * consumer id assigned by the notifier */ - ::FT::FaultNotifier::ConsumerId consumerId_; + ::FT::FaultNotifier::ConsumerId consumer_id_; }; diff --git a/TAO/orbsvcs/tests/FT_App/StubConfig.cpp b/TAO/orbsvcs/tests/FT_App/StubConfig.cpp deleted file mode 100644 index 12b1890a0db..00000000000 --- a/TAO/orbsvcs/tests/FT_App/StubConfig.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file StubConfig.cpp - * - * $Id$ - * - * This file is part of Fault Tolerant CORBA. - * Simple configuration manager for a fault tolerant application. - * - * @author Dale Wilson <wilson_d@ociweb.com> - */ -//============================================================================= - - -#include <iostream> -#include <fstream> - -#include <ace/Get_Opt.h> -#include <orbsvcs/PortableGroupC.h> - -class StubConfig -{ - public: - /////////////////////////// - // construction/destruction - StubConfig (); - - ~StubConfig (); - - ///////////////// - // initialization - int parse_args (int argc, char *argv[]); - - int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); - - //////////// - // execution - int run (ACE_ENV_SINGLE_ARG_DECL); - - //////////// - // shut down - int fini (); - - ///////////////// - // implementation -private: - void usage (ostream & out)const; - int read_ior_file(const char * fileName, CORBA::String_var & ior); - int write_ior_file(const char * outputFile, const char * ior); - - //////////////////// - // forbidden methods - private: - StubConfig (const StubConfig & rhs); - StubConfig & operator = (const StubConfig & rhs); - - //////////////// - // Data members - private: - CORBA::ORB_var orb_; - const char * registry_filename_; - PortableGroup::FactoryRegistry_var registry_; - const char * type_id_; -}; - - -StubConfig::StubConfig () - : registry_filename_(0) - , registry_(0) - , type_id_(0) -{ -} - -StubConfig::~StubConfig () -{ -} - -int -StubConfig::parse_args (int argc, char *argv[]) -{ - int result = 0; - - ACE_Get_Opt get_opts (argc, argv, "t:f:"); - int c; - - while (result == 0 && (c = get_opts ()) != -1) - { - switch (c) - { - case 't': - { - this->type_id_ = get_opts.opt_arg (); - break; - } - case 'f': - { - this->registry_filename_ = get_opts.opt_arg (); - break; - } - - default: - { - std::cerr << "Config: Unknown argument -" << (char) c << std::endl; - usage(std::cerr); - result = 1; - break; - } - case '?': - { - usage(std::cerr); - result = 1; - break; - } - } - } - - if ( this->type_id_ == 0) - { - std::cerr << "Config: Missing required parameter: -t <type_id> " << std::endl; - usage (std::cerr); - result = -1; - } - - if ( this->registry_filename_ == 0) - { - std::cerr << "Config: Missing required parameter: -f <FactoryRegistry.ior> " << std::endl; - usage (std::cerr); - result = -1; - } - - return result; -} - -void StubConfig::usage(ostream & out)const -{ - out << "usage" - << " -t <type_id for objects to be created>" - << " -f <factory ior file>" - << std::endl; -} - - - -int StubConfig::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) -{ - int result = 0; - this->orb_ = orb; - - ///////////////////////////// - // resolve reference to factory - CORBA::String_var registry_ior; - if (read_ior_file(this->registry_filename_, registry_ior)) - { - CORBA::Object_var registry_obj = this->orb_->string_to_object(registry_ior); - this->registry_ = PortableGroup::FactoryRegistry::_narrow(registry_obj); - if (CORBA::is_nil(this->registry_)) - { - std::cerr << "Config: Can't resolve FactoryRegistry IOR " << this->registry_filename_ << std::endl; - result = -1; - } - } - else - { - std::cerr << "Config: Can't read FactoryRegistry IOR " << this->registry_filename_ << std::endl; - result = -1; - } - - return result; -} - -int StubConfig::run (ACE_ENV_SINGLE_ARG_DECL) -{ - int result = 0; - - - ::PortableGroup::FactoryInfos_var infos = this->registry_->list_factories_by_type (this->type_id_ - ACE_ENV_ARG_PARAMETER) - ACE_CHECK; - - CORBA::ULong count = infos->length(); - std::cout << "Config: found " << count << " factories for " << this->type_id_ << std::endl; - - for (CORBA::ULong nFact = 0; nFact < count; ++nFact) - { - ::PortableGroup::FactoryInfo info = infos[nFact]; -/* struct FactoryInfo { - GenericFactory the_factory; - Location the_location; - Criteria the_criteria; - }; -*/ - const char * loc_name = info.the_location[0].id; - std::cout << "Config: Creating " << type_id_ << " at " << loc_name << std::endl; - - PortableGroup::GenericFactory::FactoryCreationId_var factory_creation_id; - CORBA::Object_var obj = info.the_factory->create_object ( - this->type_id_, - info.the_criteria, - factory_creation_id - ACE_ENV_ARG_PARAMETER); - ACE_CHECK; - if ( !CORBA::is_nil(obj) ) - { - const char * replica_ior = orb_->object_to_string (obj ACE_ENV_ARG_PARAMETER ); - ACE_CHECK; - - ACE_CString replica_ior_filename(loc_name); // "$(location1)_$type_id.ior" - replica_ior_filename += "_"; - replica_ior_filename += this->type_id_; - replica_ior_filename += ".ior"; - std::cout << "Config: Writing ior for created object to " << replica_ior_filename.c_str() << std::endl; - - if (write_ior_file(replica_ior_filename.c_str(), replica_ior) != 0) - { - std::cerr << "Config: Error writing ior [" << replica_ior << "] to " << replica_ior_filename.c_str() << std::endl; - } - } - else - { - std::cerr << "Config: create_object returned nil????" << std::endl; - } - } - return result; -} - - -int StubConfig::fini () -{ - return 0; -} - - - -int StubConfig::read_ior_file(const char * fileName, CORBA::String_var & ior) -{ - int result = 0; - FILE *in = ACE_OS::fopen (fileName, "r"); - if (in != 0) - { - ACE_OS::fseek(in, 0, SEEK_END); - size_t fileSize = ACE_OS::ftell(in); - ACE_OS::fseek(in, 0, SEEK_SET); - char * buffer; - ACE_NEW_NORETURN (buffer, - char[fileSize+1]); - if (buffer != 0) - { - if( fileSize == ACE_OS::fread(buffer, 1, fileSize, in)) - { - buffer[fileSize] = '\0'; - ior = CORBA::string_dup(buffer); - ACE_TRY_CHECK; - result = 1; // success - } - delete[] buffer; - } - } - else - { - result = 1; - } - return result; -} - -int StubConfig::write_ior_file(const char * outputFile, const char * ior) -{ - int result = -1; - FILE* out = ACE_OS::fopen (outputFile, "w"); - if (out) - { - ACE_OS::fprintf (out, "%s", ior); - ACE_OS::fclose (out); - result = 0; - } - else - { - ACE_ERROR ((LM_ERROR, - "Open failed for %s\n", outputFile - )); - } - return result; -} - -int -main (int argc, char *argv[]) -{ - int result = 0; - ACE_TRY_NEW_ENV - { - CORBA::ORB_var orb = CORBA::ORB_init(argc, argv ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - StubConfig app; - result = app.parse_args(argc, argv); - if (result == 0) - { - result = app.init (orb ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - if (result == 0) - { - result = app.run (ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_TRY_CHECK; - } - if (result == 0) - { - result = app.fini(); - } - } - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "StubConfig::main\t\n"); - result = -1; - } - ACE_ENDTRY; - return result; -} - -#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) -#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp index 2447a62f68e..e1cc7a9edab 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp @@ -25,7 +25,7 @@ StubFaultConsumer::~StubFaultConsumer () PortableServer::ObjectId StubFaultConsumer::objectId()const { - return this->objectId_.in(); + return this->object_id_.in(); } size_t StubFaultConsumer::notifications () const @@ -159,6 +159,9 @@ int StubFaultConsumer::init (CORBA::ORB_var & orb, { int result = 0; this->orb_ = orb; + this->notifier_ = notifier; + this->identity_ = "StubFaultConsumer"; + // Use the ROOT POA for now CORBA::Object_var poa_object = @@ -193,17 +196,20 @@ int StubFaultConsumer::init (CORBA::ORB_var & orb, // Register with the POA. - this->objectId_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); + this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - this->notifier_ = notifier; + // find my identity as an object - this->identity_ = "StubFaultConsumer"; + CORBA::Object_var this_obj = + this->poa_->id_to_reference (object_id_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; CosNotifyFilter::Filter_var filter = CosNotifyFilter::Filter::_nil(); - this->consumerId_ = notifier->connect_structured_fault_consumer( - _this(), + this->consumer_id_ = notifier->connect_structured_fault_consumer( + CosNotifyComm::StructuredPushConsumer::_narrow(this_obj), filter); return result; @@ -222,7 +228,7 @@ const char * StubFaultConsumer::identity () const */ int StubFaultConsumer::fini (ACE_ENV_SINGLE_ARG_DECL) { - this->notifier_->disconnect_consumer(this->consumerId_ ACE_ENV_ARG_PARAMETER); + this->notifier_->disconnect_consumer(this->consumer_id_ ACE_ENV_ARG_PARAMETER); return 0; } diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.h b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.h index 9e451af6010..23329c17f74 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.h +++ b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.h @@ -102,7 +102,7 @@ private: // Data Members private: /** - * The orb + * The orb */ CORBA::ORB_var orb_; @@ -114,7 +114,7 @@ private: /** * The CORBA object id assigned to this object. */ - PortableServer::ObjectId_var objectId_; + PortableServer::ObjectId_var object_id_; /** @@ -135,7 +135,7 @@ private: /** * consumer id assigned by the notifier */ - ::FT::FaultNotifier::ConsumerId consumerId_; + ::FT::FaultNotifier::ConsumerId consumer_id_; size_t notifications_; diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.cpp b/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.cpp index 55937693fb9..803d1c5a61f 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubFaultNotifier.cpp @@ -179,7 +179,13 @@ int StubFaultNotifier::fini () this_name.length (1); this_name[0].id = CORBA::string_dup (this->ns_name_); - naming_context->rebind (this_name, _this() + // find my identity as a corba object + CORBA::Object_var this_obj = + this->poa_->id_to_reference (object_id_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + naming_context->rebind (this_name, this_obj.in() //CORBA::Object::_duplicate(this_obj) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } @@ -237,6 +243,12 @@ int StubFaultNotifier::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; + // find my identity as a corba object + CORBA::Object_var this_obj = + this->poa_->id_to_reference (object_id_.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + ////////////////////////////////////////// // resolve references to detector factory CORBA::String_var factory_ior; @@ -282,7 +294,7 @@ int StubFaultNotifier::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) TAO_PG::Properties_Encoder encoder; PortableGroup::Value value; - value <<= _this(); + value <<= this_obj; encoder.add(::FT::FT_NOTIFIER, value); value <<= replica; @@ -374,7 +386,7 @@ int StubFaultNotifier::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) this_name.length (1); this_name[0].id = CORBA::string_dup (this->ns_name_); - naming_context->rebind (this_name, _this() + naming_context->rebind (this_name, this_obj.in() //CORBA::Object::_duplicate(this_obj) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } diff --git a/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp new file mode 100644 index 00000000000..4dc883786fe --- /dev/null +++ b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp @@ -0,0 +1,410 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file TAO_Object_Group_Creator.cpp + * + * $Id$ + * + * This file is part of Fault Tolerant CORBA. + * Utility to Create Object Group + * + * @author Dale Wilson <wilson_d@ociweb.com> + */ +//============================================================================= + +#include "TAO_Object_Group_Creator.h" +#include <iostream> +#include <fstream> +#include <orbsvcs/PortableGroup/PG_Properties_Encoder.h> +#include <orbsvcs/FT_ReplicationManagerC.h> + +#include <ace/Get_Opt.h> + +TAO::Object_Group_Creator::Object_Group_Creator () + : registry_filename_(0) + , registry_(0) + , iogr_group_id_(0) +{ +} + +TAO::Object_Group_Creator::~Object_Group_Creator () +{ +} + +int +TAO::Object_Group_Creator::parse_args (int argc, char *argv[]) +{ + int result = 0; + + ACE_Get_Opt get_opts (argc, argv, "t:f:"); + int c; + + while (result == 0 && (c = get_opts ()) != -1) + { + switch (c) + { + case 't': + { + this->types_.push_back (get_opts.opt_arg ()); + break; + } + case 'f': + { + this->registry_filename_ = get_opts.opt_arg (); + break; + } + + default: + { + std::cerr << "Creator: Unknown argument -" << (char) c << std::endl; + usage(std::cerr); + result = 1; + break; + } + case '?': + { + usage(std::cerr); + result = 1; + break; + } + } + } + + if ( this->types_.size() == 0) + { + std::cerr << "Creator: Missing required parameter: -t <type> " << std::endl; + usage (std::cerr); + result = -1; + } + + if ( this->registry_filename_ == 0) + { + std::cerr << "Creator: Missing required parameter: -f <FactoryRegistry.ior> " << std::endl; + usage (std::cerr); + result = -1; + } + + return result; +} + +void TAO::Object_Group_Creator::usage(ostream & out)const +{ + out << "usage" + << " -t <type_id for objects to be created>" + << " -f <factory ior file>" + << std::endl; +} + + + +int TAO::Object_Group_Creator::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) +{ + int result = 0; + this->orb_ = orb; + +////////////////STASH0 + + // Find the ReplicationManager. If found, assume it's our factory + CORBA::Object_var obj = orb->resolve_initial_references("ReplicationManager"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + ///////////////////////////// + // resolve reference to factory + CORBA::String_var registry_ior; + if (read_ior_file(this->registry_filename_, registry_ior)) + { + CORBA::Object_var registry_obj = this->orb_->string_to_object(registry_ior); + this->registry_ = PortableGroup::FactoryRegistry::_narrow(registry_obj); + if (CORBA::is_nil(this->registry_)) + { + std::cerr << "Creator: Can't resolve FactoryRegistry IOR " << this->registry_filename_ << std::endl; + result = -1; + } + } + else + { + std::cerr << "Creator: Can't read FactoryRegistry IOR " << this->registry_filename_ << std::endl; + result = -1; + } + + return result; +} + +int TAO::Object_Group_Creator::run (ACE_ENV_SINGLE_ARG_DECL) +{ + int result = 0; + size_t typeCount = this->types_.size(); + for ( size_t nType = 0; result == 0 && nType < typeCount; ++nType) + { + const char * type = this->types_[nType].c_str(); + result = create_group (type); + } + return result; +} + +int TAO::Object_Group_Creator::create_group(const char * type) +{ + int result = 0; + + std::cout << std::endl << "Creator: Creating group of " << type << std::endl; + + ::PortableGroup::FactoryInfos_var infos = this->registry_->list_factories_by_type (type + ACE_ENV_ARG_PARAMETER) + ACE_CHECK; + + CORBA::ULong count = infos->length(); + std::cout << "Creator: found " << count << " factories for " << type << std::endl; + + if (count > 0) + { +////////////////STASH1 + for (CORBA::ULong nFact = 0; nFact < count; ++nFact) + { + ::PortableGroup::FactoryInfo info = infos[nFact]; + /* struct FactoryInfo { + GenericFactory the_factory; + Location the_location; + Criteria the_criteria; + }; + */ + const char * loc_name = info.the_location[0].id; + std::cout << "Creator: Creating " << type << " at " << loc_name << std::endl; + + PortableGroup::GenericFactory::FactoryCreationId_var factory_creation_id; + CORBA::Object_var obj = info.the_factory->create_object ( + type, + info.the_criteria, + factory_creation_id + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + if ( !CORBA::is_nil(obj) ) + { + const char * replica_ior = orb_->object_to_string (obj ACE_ENV_ARG_PARAMETER ); + ACE_CHECK; + +////////////////STASH2 + + //////////////////////////////////// + // Somewhat of a hack + // guess at factory creation id type + CORBA::ULong ulong_id = 0; + CORBA::Long long_id = 0; + if (factory_creation_id >>= ulong_id) + { + // ok + } + else if (factory_creation_id >>= long_id) + { + ulong_id = ACE_static_cast(CORBA::ULong, long_id); + } + else + { + std::cerr << "Can't decypher factory creation id." << std::endl; + // Guessed wrong. Just use default value + } + + char replica_ior_filename[200]; // "${type}_$(location)_${factory_id}.ior" + + ACE_OS::snprintf(replica_ior_filename, sizeof(replica_ior_filename)-1, "%s_%s_%lu.ior", + type, + loc_name, + ACE_static_cast(unsigned long, ulong_id)); + replica_ior_filename[sizeof(replica_ior_filename)-1] = '\0'; + + std::cout << "Creator: Writing ior for created object to " << replica_ior_filename << std::endl; + + if (write_ior_file(replica_ior_filename, replica_ior) != 0) + { + std::cerr << "Creator: Error writing ior [" << replica_ior << "] to " << replica_ior_filename << std::endl; + } + } + else + { + std::cerr << "Creator: create_object returned nil????" << std::endl; + } + } + + std::cout << "Creator: Successfully created group of " << type << std::endl; +////////////////STASH3 + } + + return result; +} + + +int TAO::Object_Group_Creator::fini () +{ + return 0; +} + + + +int TAO::Object_Group_Creator::read_ior_file(const char * fileName, CORBA::String_var & ior) +{ + int result = 0; + FILE *in = ACE_OS::fopen (fileName, "r"); + if (in != 0) + { + ACE_OS::fseek(in, 0, SEEK_END); + size_t fileSize = ACE_OS::ftell(in); + ACE_OS::fseek(in, 0, SEEK_SET); + char * buffer; + ACE_NEW_NORETURN (buffer, + char[fileSize+1]); + if (buffer != 0) + { + if( fileSize == ACE_OS::fread(buffer, 1, fileSize, in)) + { + buffer[fileSize] = '\0'; + ior = CORBA::string_dup(buffer); + ACE_TRY_CHECK; + result = 1; // success + } + delete[] buffer; + } + } + else + { + result = 1; + } + return result; +} + +int TAO::Object_Group_Creator::write_ior_file(const char * outputFile, const char * ior) +{ + int result = -1; + FILE* out = ACE_OS::fopen (outputFile, "w"); + if (out) + { + ACE_OS::fprintf (out, "%s", ior); + ACE_OS::fclose (out); + result = 0; + } + else + { + ACE_ERROR ((LM_ERROR, + "Open failed for %s\n", outputFile + )); + } + return result; +} + +int +main (int argc, char *argv[]) +{ + int result = 0; + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + TAO::Object_Group_Creator app; + result = app.parse_args(argc, argv); + if (result == 0) + { + result = app.init (orb ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (result == 0) + { + result = app.run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + if (result == 0) + { + result = app.fini(); + } + } + std::cout << "***END TRY SCOPE***" << std::endl; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Object_Group_Creator::main\t\n"); + result = -1; + } + ACE_ENDTRY; + std::cout << "***EXIT***" << std::endl; + + return result; +} + + +#ifdef UNUSED_CODE_STASH +////////////////STASH0 + // Get an object reference for the ORBs IORManipulation object! + CORBA::Object_var IORM = + this->orb_->resolve_initial_references (TAO_OBJID_IORMANIPULATION, + 0 + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + this->iorm_ = TAO_IOP::TAO_IOR_Manipulation::_narrow (IORM.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + +////////////////STASH1 + // Create IOR list for use with merge_iors. + TAO_IOP::TAO_IOR_Manipulation::IORList iors (count + 1); + + // create a property set + TAO_PG::Properties_Encoder encoder; + PortableGroup::Value value; + + value <<= 99; + encoder.add(::FT::FT_MINIMUM_NUMBER_REPLICAS, value); + + // allocate and populate the criteria + FT::Properties_var props_in; + ACE_NEW_NORETURN (props_in, FT::Properties); + if (props_in.ptr() == 0) + { + ACE_ERROR((LM_ERROR, "Error cannot allocate properties.\n" )); + } + else + { + encoder.encode(props_in); + } + + iors.length (count + 1); + iors [0] = this->object_group_manager_.create_object_group( + this->iogr_group_id_, + "domain", + type, + props_in); + +////////////////STASH2 + iors [nFact + 1] = obj; + +////////////////STASH3 + CORBA::Object_var object_group = this->iorm_->merge_iors (iors ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + const char * iogr = orb_->object_to_string (object_group ACE_ENV_ARG_PARAMETER ); + ACE_CHECK; + + + char iogr_filename[200]; // "${type}_${iogr_id}.ior" + + ACE_OS::snprintf(iogr_filename, sizeof(iogr_filename)-1, "%s_%lu.ior", + type, + ACE_static_cast(unsigned long, iogr_group_id_)); + iogr_filename[sizeof(iogr_filename)-1] = '\0'; + + std::cout << "Creator: Writing iogr for created object to " << iogr_filename << std::endl; + + if (write_ior_file(iogr_filename, iogr) != 0) + { + std::cerr << "Creator: Error writing iogr [" << iogr << "] to " << iogr_filename << std::endl; + } + + + this->iogr_group_id_ += 1; + +#endif // UNUSED_CODE_STASH + + + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + template ACE_Vector<ACE_CString>; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +# pragma instantiate ACE_Vector<ACE_CString> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h new file mode 100644 index 00000000000..21ef83a5ab9 --- /dev/null +++ b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h @@ -0,0 +1,81 @@ +/* -*- C++ -*- */ +//============================================================================= +/** + * @file TAO_Object_Group_Creator.cpp + * + * $Id$ + * + * This file is part of Fault Tolerant CORBA. + * Utility to Create Object Group + * + * @author Dale Wilson <wilson_d@ociweb.com> + */ +//============================================================================= + +#ifndef TAO_OBJECT_GROUP_CREATOR_H +#define TAO_OBJECT_GROUP_CREATOR_H +#include <ace/ACE.h> + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include <orbsvcs/PortableGroupC.h> +#include <ace/SString.h> +#include <ace/Vector_T.h> +#include <tao/IORManipulation/IORC.h> +#include <orbsvcs/PortableGroup/PG_ObjectGroupManager.h> + +namespace TAO +{ + class Object_Group_Creator + { + typedef ACE_Vector<ACE_CString> StringVec; + public: + /////////////////////////// + // construction/destruction + Object_Group_Creator (); + + ~Object_Group_Creator (); + + ///////////////// + // initialization + int parse_args (int argc, char *argv[]); + + int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); + + //////////// + // execution + int run (ACE_ENV_SINGLE_ARG_DECL); + + //////////// + // shut down + int fini (); + + ///////////////// + // implementation + private: + void usage (ostream & out)const; + int read_ior_file(const char * fileName, CORBA::String_var & ior); + int write_ior_file(const char * outputFile, const char * ior); + + int create_group(const char * type_id); + + //////////////////// + // forbidden methods + private: + Object_Group_Creator (const Object_Group_Creator & rhs); + Object_Group_Creator & operator = (const Object_Group_Creator & rhs); + + //////////////// + // Data members + private: + CORBA::ORB_var orb_; + const char * registry_filename_; + PortableGroup::FactoryRegistry_var registry_; + StringVec types_; + }; + +} // namespace TAO + +#endif // TAO_OBJECT_GROUP_CREATOR_H diff --git a/TAO/orbsvcs/tests/FT_App/run_test_registry.pl b/TAO/orbsvcs/tests/FT_App/run_test_registry.pl index 4fc76c7436c..00b4cc0cbd9 100755 --- a/TAO/orbsvcs/tests/FT_App/run_test_registry.pl +++ b/TAO/orbsvcs/tests/FT_App/run_test_registry.pl @@ -9,57 +9,76 @@ eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' # To test the FactoryRegistry # # Process being tested: -# FT_Registry +# FT_Registry # implements PortableGroup::FactoryRegistry interface. # Processes used in test: -# FT_Replica * 2 +# FT_Replica * 3 # implements GenericFactory interface to create TestReplicas # TestReplica implements TestReplica interface. # TestReplica implements PullMonitorable interface. # FT_Client # client for TestReplica interface. # client for PullMonitorable. -# StubConfiguratonManager -# Orchestrates the test. +# Object Group Creator +# Creates groups of objects. # # Test Scenario (***Test: marks behavior being tested): -# Phase 1: -# Start FactoryRegistry (FR) -# FR writes IOR to file. -# Phase 2: -# Wait for IOR: FR. -# Start two FT_ReplicaFactories giving them FR IOR. -# Specifying same type_id, different location. -# ***Test: FT_ReplicaFactories register with FactoryRegistry. -# RFs write IORs to files (used for synchronization purposes only). -# Phase 3: -# Wait for IORS: RF1, RF2 -# Start StubConfiguratonManager given type_id and IORs: FR -# ***Test: StubConfiguratonManager asks FR for factory-by-type. -# Receives list of factories(RF1 RF2). -# StubConfiguratonManager uses create_object for each factory to -# create TestReplicas (TR1 and TR2). -# StubConfiguratonManager writes TestReplica IORs (TR1 and TR2) to files -# StubConfigurationManger exits. It's job is done! -# Phase 4: -# Wait for IORS: TR1 and TR2 -# Start FT_Client giving it TR1 and TR2. [1] -# FT_Client interacts with TR1. -# FT_Client asks TR1 to fault. It does so -# FR1 is idle. It honors quit-on-idle option. As it exits, it unregisters from FR. -# FT_Client notices fault and switches to TR2. [1] -# FT_Client interacts with TR2. -# FT_Client asks TR2 to shut down. -# FT_Client shuts down. -# FR2 notices TR2 is gone and honors it's quit-on-idle option. It unregisters from FR. -# All factories have unregistered from FR. FR honors its quit-on-idle option. -# Phase 7: housekeeping -# Wait for all processes to terminate. -# Check termination status. -# Delete temp files. # -# [1] Client mediated fault tolerance. These points will -# change when IOGR support is available. +# First the test starts a factory registry, +# Then starts three factories. Each factory exists at a separate location. +# The locations are named shire, bree, and rivendell. In a "real" system +# these locations would be on separate computers. +# +# The factory at the shire location knows how to create hobbits; +# the factory at the bree location knows how to create hobbits and elves, and +# the factory at rivendell can create elves. +# Both hobbits and elves are actually TestReplica objects. A creation parameter +# included as part of the registration information specifies which species they are. +# +# ***Test: The factories register themselves with the factory registry. Registration +# information includes the location, the type of object created, a object reference +# to the factory and set of parameters to be passed to the factory's create_object +# method. +# +# An object group creator is started and asked to create three object groups: +# a group of hobbits, a group of elves; and another group of hobbits. +# +# ***Test: the object group creator asks the registry for the set of factories +# that can create the type of object needed, then uses the create_object method +# for each factory to create the actual object. +# +# [temporary until IOGR's are working: The object group creator writes the +# IOR's of the create objects to files -- using a file naming convention to +# distinguish members of the group. It will be enhanced to assemble these +# IORs into an IOGR and either write the IOGR to a file or register it with +# the Naming Service.] +# +# Three clients are started, one at a time. Each client is given a reference +# to an object group +# +# [temporary until IOGRs and transparent reinvocaton work: each client is +# given references to the members of the group and manages its own recovery +# (client mediated fault tolerance)] +# +# Each client sends a few requests to first member of the object group. Eventually +# this member fails and the requests are then rerouted to the second (and last) +# member of the group. +# +# When a clients job is done, it exits and asks the remaining group member to +# exit, too. +# +# The factories are run with the quit-on-idle option so when the last object +# created at that location goes away, the factory exits. +# +# ***Test: As it exits the factory unregisters itself with the factory registry. +# ***Test: A command line option determines whether it uses a single +# unregister_factory_by_location call, or separate unregister_factory calles for +# each type of object created. In this test, the shire location uses unregister_factory, +# and bree and rivendell use unregister_factory_by_location. +# +# The factory registry is also run with the quit-on-idle option so when the last +# factory unregisters itself, the factory registry shuts down to end the test. + use lib '../../../../bin'; #use lib '$ENV{ACE_ROOT}/bin'; use PerlACE::Run_Test; @@ -86,7 +105,6 @@ foreach $i (@ARGV) { } } - my($build_directory) = "/Release"; if ( $debug_builds ) { $build_directory = ""; @@ -98,43 +116,70 @@ if ( $verbose > 1) { print "simulated: $simulated\n"; } -my($type_id) = "test_replica"; -my($location1) = "hither"; -my($location2) = "yon"; +my($species1) = "hobbit"; +my($species2) = "elf"; +my($location1) = "shire"; +my($location2) = "bree"; +my($location3) = "rivendell"; #define temp files my($registry_ior) = PerlACE::LocalFile ("registry.ior"); my($factory1_ior) = PerlACE::LocalFile ("factory1.ior"); my($factory2_ior) = PerlACE::LocalFile ("factory2.ior"); -my($replica1_ior) = PerlACE::LocalFile ("${location1}_$type_id.ior"); -my($replica2_ior) = PerlACE::LocalFile ("${location2}_$type_id.ior"); +my($factory3_ior) = PerlACE::LocalFile ("factory3.ior"); +my($replica1_ior) = PerlACE::LocalFile ("${species1}_${location1}_0.ior"); +my($replica2_ior) = PerlACE::LocalFile ("${species1}_${location2}_0.ior"); +my($replica3_ior) = PerlACE::LocalFile ("${species2}_${location2}_1.ior"); +my($replica4_ior) = PerlACE::LocalFile ("${species2}_${location3}_0.ior"); +my($replica5_ior) = PerlACE::LocalFile ("${species1}_${location1}_1.ior"); +my($replica6_ior) = PerlACE::LocalFile ("${species1}_${location2}_2.ior"); + +my($replica1_iogr) = PerlACE::LocalFile ("${species1}_0.iogr"); +my($replica2_iogr) = PerlACE::LocalFile ("${species2}_1.iogr"); +my($replica3_iogr) = PerlACE::LocalFile ("${species1}_2.iogr"); + my($client_data) = PerlACE::LocalFile ("persistent.dat"); #discard junk from previous tests unlink $registry_ior; unlink $factory1_ior; unlink $factory2_ior; +unlink $factory3_ior; unlink $replica1_ior; unlink $replica2_ior; +unlink $replica3_ior; +unlink $replica4_ior; +unlink $replica5_ior; +unlink $replica6_ior; +unlink $replica1_iogr; +unlink $replica2_iogr; + unlink $client_data; my($status) = 0; my($REG) = new PerlACE::Process (".$build_directory/ft_registry", "-o $registry_ior -q"); -my($FAC1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -f $registry_ior -l $location1 -i $type_id -q"); -my($FAC2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -f $registry_ior -l $location2 -i $type_id -q"); -my($CFG) = new PerlACE::Process (".$build_directory/ft_config", "-t $type_id -f $registry_ior "); - -my($CL); +my($FAC1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -f $registry_ior -l $location1 -i $species1 -q"); +my($FAC2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -f $registry_ior -l $location2 -i $species1 -i $species2 -q -u"); +my($FAC3) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory3_ior -f $registry_ior -l $location3 -i $species2 -q -u"); +my($CTR) = new PerlACE::Process (".$build_directory/ft_create", "-f $registry_ior -t $species1 -t $species2 -t $species1"); + +my($CL1); +my($CL2); +my($CL3); if (simulated) { - $CL = new PerlACE::Process (".$build_directory/ft_client", "-f $replica1_ior,$replica2_ior -c testscript"); + $CL1 = new PerlACE::Process (".$build_directory/ft_client", "-f $replica1_ior,$replica2_ior -c testscript"); + $CL2 = new PerlACE::Process (".$build_directory/ft_client", "-f $replica3_ior,$replica4_ior -c testscript"); + $CL3 = new PerlACE::Process (".$build_directory/ft_client", "-f $replica5_ior,$replica6_ior -c testscript"); }else{ #todo figure out how to get iogr - $CL = new PerlACE::Process (".$build_directory/ft_client", "-f $replica1_iogr -c testscript"); + $CL1 = new PerlACE::Process (".$build_directory/ft_client", "-f $replica1_iogr -c testscript"); + $CL2 = new PerlACE::Process (".$build_directory/ft_client", "-f $replica2_iogr -c testscript"); + $CL3 = new PerlACE::Process (".$build_directory/ft_client", "-f $replica3_iogr -c testscript"); } -######### -# Phase 1 +####################### +# Start FactoryRegistry print "\nTEST: starting registry " . $REG->CommandLine . "\n" if ($verbose); $REG->Spawn (); @@ -146,8 +191,8 @@ if (PerlACE::waitforfile_timed ($registry_ior, 5) == -1) { exit 1; } -######### -# Phase 2 +################# +# Start Factories print "\nTEST: starting factory 1 " . $FAC1->CommandLine . "\n" if ($verbose); $FAC1->Spawn (); @@ -172,80 +217,146 @@ if (PerlACE::waitforfile_timed ($factory2_ior, 5) == -1) { exit 1; } +print "\nTEST: starting factory 3 " . $FAC3->CommandLine . "\n" if ($verbose); +$FAC3->Spawn (); + +print "TEST: waiting for factory 3's IOR\n" if ($verbose); +if (PerlACE::waitforfile_timed ($factory3_ior, 5) == -1) { + print STDERR "ERROR: cannot find file <$factory3_ior>\n"; + $FAC1->Kill (); $FAC1->TimedWait (1); + $FAC2->Kill (); $FAC2->TimedWait (1); + $REG->Kill (); $REG->TimedWait (1); + $FAC3->Kill (); $FAC3->TimedWait (1); + exit 1; +} -######### -# Phase 3 +###################### +# Create object groups -print "\nTEST: starting configuration manager " . $CFG->CommandLine . "\n" if ($verbose); -$CFG->Spawn (); +print "\nTEST: starting object group creator " . $CTR->CommandLine . "\n" if ($verbose); +$CTR->Spawn (); -print "TEST: waiting for Replica 1 IOR file from configuration manager\n" if ($verbose); +print "TEST: waiting for Replica IOR files from object group creator\n" if ($verbose); if (PerlACE::waitforfile_timed ($replica1_ior, 5) == -1){ print STDERR "ERROR: cannot find file <$replica1_ior>\n"; + $status = 1; +} +elsif (PerlACE::waitforfile_timed ($replica2_ior, 5) == -1){ + print STDERR "ERROR: cannot find file <$replica2_ior> \n"; + $status = 1; +} +elsif (PerlACE::waitforfile_timed ($replica3_ior, 5) == -1){ + print STDERR "ERROR: cannot find file <$replica3_ior> \n"; + $status = 1; +} +elsif (PerlACE::waitforfile_timed ($replica4_ior, 5) == -1){ + print STDERR "ERROR: cannot find file <$replica4_ior> \n"; + $status = 1; +} +elsif (PerlACE::waitforfile_timed ($replica5_ior, 5) == -1){ + print STDERR "ERROR: cannot find file <$replica5_ior> \n"; + $status = 1; +} +elsif (PerlACE::waitforfile_timed ($replica6_ior, 5) == -1){ + print STDERR "ERROR: cannot find file <$replica6_ior> \n"; + $status = 1; +} + +if($status != 0){ + $FAC3->Kill (); $FAC3->TimedWait (1); $FAC2->Kill (); $FAC2->TimedWait (1); $FAC1->Kill (); $FAC1->TimedWait (1); $REG->Kill (); $REG->TimedWait (1); - $CFG->Kill (); $CFG->TimedWait(1); + $CTR->Kill (); $CTR->TimedWait(1); exit 1; } -if (PerlACE::waitforfile_timed ($replica2_ior, 5) == -1){ - print STDERR "ERROR: cannot find file <$replica2_ior> \n"; + +print "\nTEST: wait for object group creator.\n" if ($verbose); +$config = $CTR->WaitKill (5); +if ($config != 0) { + print STDERR "ERROR: configuration manager returned $config\n"; + $FAC3->Kill (); $FAC3->TimedWait (1); $FAC2->Kill (); $FAC2->TimedWait (1); $FAC1->Kill (); $FAC1->TimedWait (1); $REG->Kill (); $REG->TimedWait (1); - $CFG->Kill (); $CFG->TimedWait(1); exit 1; } -######### -# Phase 4 -print "\nTEST: starting client " . $CL->CommandLine . "\n" if ($verbose); -$client = $CL->SpawnWaitKill (60); + +############# +# Run clients + +print "\nTEST: starting client " . $CL1->CommandLine . "\n" if ($verbose); +$client = $CL1->SpawnWaitKill (60); if ($client != 0) { print STDERR "ERROR: client returned $client\n"; $status = 1; } -######### -# Phase 4 +print "\nTEST: starting client again " . $CL2->CommandLine . "\n" if ($verbose); +$client2 = $CL2->SpawnWaitKill (60); + +if ($client2 != 0) { + print STDERR "ERROR: client returned $client2\n"; + $status = 1; +} + +print "\nTEST: starting client, one more time with feeling " . $CL3->CommandLine . "\n" if ($verbose); +$client3 = $CL3->SpawnWaitKill (60); + +if ($client3 != 0) { + print STDERR "ERROR: client returned $client3\n"; + $status = 1; +} + +###################### +# Clean house and exit print "\nTEST: wait for factory 1.\n" if ($verbose); -$factory1 = $FAC1->WaitKill (5); +$factory1 = $FAC1->WaitKill (30); if ($factory1 != 0) { print STDERR "ERROR: replica returned $factory 1\n"; $status = 1; } print "\nTEST: wait for factory 2.\n" if ($verbose); -$factory2 = $FAC2->WaitKill (5); +$factory2 = $FAC2->WaitKill (30); if ($factory2 != 0) { print STDERR "ERROR: factory 2 returned $factory2\n"; $status = 1; } -print "\nTEST: wait for configuration manager to leave.\n" if ($verbose); -$config = $CFG->WaitKill (5); -if ($config != 0) { - print STDERR "ERROR: configuration manager returned $config\n"; +print "\nTEST: wait for factory 3.\n" if ($verbose); +$factory3 = $FAC3->WaitKill (30); +if ($factory3 != 0) { + print STDERR "ERROR: factory 3 returned $factory3\n"; $status = 1; } -print "\nTEST: wait for FactoryRegistry to leave.\n" if ($verbose); -$registry = $REG->WaitKill (5); +print "\nTEST: wait for FactoryRegistry.\n" if ($verbose); +$registry = $REG->WaitKill (30); if ($registry != 0) { print STDERR "ERROR: FactoryRegistry returned $registry\n"; $status = 1; } - print "\nTEST: releasing scratch files.\n" if ($verbose); unlink $registry_ior; unlink $factory1_ior; unlink $factory2_ior; +unlink $factory3_ior; unlink $replica1_ior; unlink $replica2_ior; +unlink $replica3_ior; +unlink $replica4_ior; +unlink $replica5_ior; +unlink $replica6_ior; +unlink $replica1_iogr; +unlink $replica2_iogr; + unlink $client_data; + exit $status; diff --git a/TAO/orbsvcs/tests/FT_App/testscript b/TAO/orbsvcs/tests/FT_App/testscript index ae95a3cd110..a428a227ef3 100644 --- a/TAO/orbsvcs/tests/FT_App/testscript +++ b/TAO/orbsvcs/tests/FT_App/testscript @@ -5,6 +5,6 @@ d3 FMI: d3 is before state change; d4 is before replication;d5 is before reply +5 c10 +5 -z5 sleep for a while +z3 sleep for a while +7 q1 quit and bring down current primary replica diff --git a/TAO/tao/Utils/ServantMain.cpp b/TAO/tao/Utils/ServantMain.cpp deleted file mode 100644 index 870e4c0cd4e..00000000000 --- a/TAO/tao/Utils/ServantMain.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file ServantMain.cpp - * - * $Id$ - * - * Implements a generic object that acts as "main" for a CORBA server. - * - * @author Dale Wilson <wilson_d@ociweb.com> - */ -//============================================================================= -// -#ifndef TAO_UTILS_SERVANTMAIN_T_CPP -#define TAO_UTILS_SERVANTMAIN_T_CPP - -#include "ServantMain.h" -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -ACE_RCSID(Utils, ServantMain, "$Id$") - -#include <ace/Argv_Type_Converter.h> -#include <tao/PortableServer/ORB_Manager.h> - -template <typename SERVANT> -TAO::Utils::ServantMain<SERVANT>::ServantMain(const char * name) - : name_(name) -{ -} - -template <typename SERVANT> -TAO::Utils::ServantMain<SERVANT>::~ServantMain() -{ -} - -template <typename SERVANT> -int TAO::Utils::ServantMain<SERVANT>::Main (int argc, ACE_TCHAR *argv[]) -{ - int result = 0; - // hide unicode if necessary. - ACE_Argv_Type_Converter command_line(argc, argv); - - char ** asciiArgv = command_line.get_ASCII_argv(); - - ACE_TRY_NEW_ENV - { - // Create an object that manages all the - // details of being a server. - TAO_ORB_Manager orbManager; - result = orbManager.init (argc, asciiArgv - ACE_ENV_ARG_PARAMETER); - if(result == 0) - { - ACE_CHECK_RETURN (-1); - - // create an instance of the servant and give it a - // chance at the arguments. - SERVANT servant; - result = servant.parse_args (argc, asciiArgv); - if (result == 0) - { - ////////////////////////////////// - // let the servant register itself - result = servant.init(orbManager); - if (result == 0) - { - ACE_ERROR ((LM_INFO, - "%n\n%T: %s Ready %s\n", name_, servant.identity() - )); - - ////////////////////////////////// - // Run the event loop for the ORB. - // Initial run to initialize the orb - ACE_Time_Value tv(1,0); - result = orbManager.run (tv - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - // now run event loop - CORBA::ORB_var orb = orbManager.orb(); - int quit = 0; - while (result == 0 && ! quit ) - { - ACE_Time_Value work_tv(1,0); - orb->perform_work(work_tv - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - quit = servant.idle(result); - } - ACE_ERROR ((LM_DEBUG, - "call fini" - )); - servant.fini(ACE_ENV_SINGLE_ARG_PARAMETER); - ACE_ERROR ((LM_DEBUG, - "return fini" - )); - orb->shutdown(0 ACE_ENV_ARG_PARAMETER); - ACE_ERROR ((LM_INFO, - "%n\n%T: %s Terminated normally. %s\n", name_, servant.identity() - )); - } - else - { - ACE_ERROR ((LM_ERROR, - "%n\n%T: %s registration failed: %p\n", name_ - )); - result = -1; - } - } - else - { - ACE_ERROR ((LM_ERROR, - "%n\n%T: %s: ORB manager init failed\n", name_ - )); - result = -1; - } - } - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - name_); - result = -1; - } - ACE_ENDTRY; - return result; -} - -#endif //TAO_UTILS_SERVANTMAIN_T_CPP diff --git a/TAO/tao/Utils/ServantMain.h b/TAO/tao/Utils/ServantMain.h deleted file mode 100644 index 676bcda366c..00000000000 --- a/TAO/tao/Utils/ServantMain.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- C++ -*- */ -//============================================================================= -/** - * @file ServantMain.h - * - * $Id$ - * - * Declares a generic object that acts as "main" for a CORBA server. - * @author Dale Wilson <wilson_d@ociweb.com> - * - * This object supports creation of a relatively simple CORBA server. - * The object implements "main" for a process. - * A single servant is created and initialized as the process begins - * execution. The lifetime of this initial servant is the lifetime of - * the process. - * The servant is free to create other servants as necessary. - * The servant can capture command line options. - * A callback method in the ORB event loop allows the servant to act - * asynchronously if necessary. - * The callback method allows the servant to request process termination - * and specify the status to be returned from the process. - * - * The application should create a C/C++ main that looks something like: - * #include <tao/Utils/ServantMain.h> - * #include "Xyzzy_i.h" - * int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) - * { - * ServantMain<Xyzzy_i> servant ("Xyzzy"); - * return servant.Main(argc, argv); - * } - * - * The servant implementation (Xyzzy_i in this case) must implement - * the following methods: - * Xyzzy_i (); // null constructor - * ~Xyzzy_i (); // destructor - * int parse_args (int argc, char * argv[]); - * int init (TAO_ORB_Manager & orbManager ACE_ENV_ARG_DECL_WITH_DEFAULTS); - * int idle(int &result); - * int fini (ACE_ENV_SINGLE_ARG_DECL); - * const char * identity () const; - * - * parse_args, self_register, self_unregister return 0 if ok, nonzero for error. - * idle returns 0 to continue execution; nonzero to exit -- returning "result" from the process - * identity provides a string to identify this servant in log messages. - * - */ -//============================================================================= - -#ifndef TAO_UTILS_SERVANTMAIN_H -#define TAO_UTILS_SERVANTMAIN_H - -#include <ace/ACE.h> -#if !defined (ACE_LACKS_PRAGMA_ONCE) -# pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -#include /**/ <ace/pre.h> -namespace TAO -{ - namespace Utils - { - template <typename SERVANT> - class ServantMain - { - public: - ServantMain(const char * name); - ~ServantMain(); - - int Main (int argc, ACE_TCHAR *argv[]); - - private: - ServantMain( const ServantMain &); - ServantMain & operator = (const ServantMain &); - - private: - const char * name_; - }; - } // namespace UTILS -} // namespace TAO - -#if defined (ACE_TEMPLATES_REQUIRE_SOURCE) -# include "ServantMain.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ - -#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) -# pragma implementation "ServantMain.cpp" -#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ - -#include /**/ <ace/post.h> - -#endif //TAO_UTILS_SERVANTMAIN_H |