diff options
author | wilson_d <wilson_d@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-10-21 15:22:02 +0000 |
---|---|---|
committer | wilson_d <wilson_d@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-10-21 15:22:02 +0000 |
commit | 53924e27e31b7286a5c1b37cd175beb7768b98be (patch) | |
tree | 4910a178106efb8bebe4f360c26078e21e397a81 | |
parent | 6f5a20004011276c1470c461113bad4f12cc6a30 (diff) | |
download | ATCD-53924e27e31b7286a5c1b37cd175beb7768b98be.tar.gz |
ChangeLogTag: Tue Oct 21 09:49:51 2003 Dale Wilson <wilson_d@ociweb.com>
21 files changed, 886 insertions, 400 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index ce5b4702e72..4d7799fa05c 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,44 @@ +Tue Oct 21 09:49:51 2003 Dale Wilson <wilson_d@ociweb.com> + + * orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h: + * orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp: + Add FactoryRegistry to ReplicationManager + remove obsolete create_test_iogr + + * orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp: + * orbsvcs/Fault_Detector/Fault_Detector_i.cpp: + add a few more info messages. + + * orbsvcs/orbsvcs/PortableGroup.idl: + * orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h: + * orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp: + Modify FactoryRegistry interface to register factories by role, not by type + + + * orbsvcs/tests/FT_App/FT_App.mpc: + remove unneeded dependancies for ft_client. {ft_client is !NOT! JUnit.} + + * orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h: + * orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp: + * orbsvcs/tests/FT_App/FT_TestReplica.idl: + * orbsvcs/tests/FT_App/FT_TestReplica_i.h: + * orbsvcs/tests/FT_App/FT_TestReplica_i.cpp: + * orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp: + * orbsvcs/tests/FT_App/StubFaultConsumer.cpp: + * orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h: + * orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp: + * orbsvcs/tests/FT_App/run_test_notifier.pl: + * orbsvcs/tests/FT_App/run_test_rmregistry.pl: + Support the "roles" concept. i.e. distinguish between the interface implemented + by a replica (its type_id) and its capabilities and purpose (its role.) + + * orbsvcs/tests/FaultTolerance/IOGR/Client_i.h: + add /**/ to pre.h and post.h includes + + + These changes were made in the oci_haft branch. + + Thu Oct 16 18:16:07 2003 Steve Totten <totten_s@ociweb.com> * orbsvcs/FT_ReplicationManager/FT_FaultEventDescriptor.cpp: diff --git a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp index f7669d1e79e..655e60f1e39 100644 --- a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp +++ b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp @@ -44,6 +44,7 @@ TAO::FT_ReplicationManager::FT_ReplicationManager () , fault_notifier_(FT::FaultNotifier::_nil()) , fault_notifier_ior_(0) , fault_consumer_() + , factory_registry_("ReplicationManager::FactoryRegistry") , quit_(0) { //@@Note: this->init() is not called here (in the constructor) @@ -136,6 +137,11 @@ int TAO::FT_ReplicationManager::init (CORBA::ORB_ptr orb ACE_ENV_ARG_DECL) -1); } + + // initialize the FactoryRegistry + this->factory_registry_.init(orb_ ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN(-1); + // Get the RootPOA. CORBA::Object_var poa_obj = this->orb_->resolve_initial_references ( TAO_OBJID_ROOTPOA ACE_ENV_ARG_PARAMETER); @@ -425,9 +431,7 @@ TAO::FT_ReplicationManager::get_factory_registry ( ACE_ENV_ARG_DECL) ACE_THROW_SPEC ((CORBA::SystemException)) { - ::PortableGroup::FactoryRegistry_var registry = ::PortableGroup::FactoryRegistry::_nil(); - int todo_implement_factory_registry; - return registry; + return this->factory_registry_.reference(); } /// TAO-specific shutdown operation. @@ -754,129 +758,3 @@ TAO::FT_ReplicationManager::delete_object ( ACE_CHECK; } -#if 0 -// Returns a dummy IOGR for unit tests -CORBA::Object_ptr -TAO::FT_ReplicationManager::create_test_iogr (ACE_ENV_SINGLE_ARG_DECL) -{ - ACE_DEBUG ((LM_DEBUG, "---------------------------------------------\n")); - ACE_DEBUG ((LM_DEBUG, "Creating an IOGR for the Unit Tests.\n")); - - ACE_TRY_NEW_ENV - { - // Domain id - const char * domain_id = "TestFTDomains"; - - // Object group id - this->test_iogr_group_id_ = (CORBA::ULongLong) 10; - - // 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 * props_in; - FT::Properties_var props; - ACE_NEW_NORETURN (props_in, FT::Properties); - if (props_in == 0) - { - ACE_ERROR((LM_ERROR, "Error cannot allocate properties.\n")); - } - else - { - props = props_in; - encoder.encode(props); - } - - // Create a few fictitious IORs - CORBA::Object_var name1 = - this->orb_->string_to_object ( - "corbaloc:iiop:acme.cs.wustl.edu:6060/xyz" ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - CORBA::Object_var name2 = - this->orb_->string_to_object ( - "corbaloc::iiop:tango.cs.wustl.edu:7070/xyz" ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - // Create IOR list for use with merge_iors. - TAO_IOP::TAO_IOR_Manipulation::IORList iors (3); - iors.length (3); - iors [0] = this->object_group_manager_.create_object_group ( - this->test_iogr_group_id_, - "my-dummy-type-id", - domain_id, - props.in() - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - iors [1] = name1; - iors [2] = name2; - - this->test_iogr_ = this->iorm_->merge_iors (iors ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - // We only need this so we can call IORManipulation's set_primary. - FT::TagFTGroupTaggedComponent ft_tag_component; - TAO_FT_IOGR_Property ft_prop (ft_tag_component); - - // set primary - CORBA::Boolean retval = - this->iorm_->set_primary ( - &ft_prop, name2.in (), - this->test_iogr_.in () ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - - if (retval != 0) - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("\tThe primary has been set\n"))); - } - else - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("\tError in setting primary\n"))); - } - } - ACE_CATCHANY - { - ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception!\n"); - } - ACE_ENDTRY; - ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - ACE_DEBUG ((LM_DEBUG, "---------------------------------------------\n")); - - return this->test_iogr_._retn(); -} -#endif - -#if 0 -int TAO::FT_ReplicationManager::readIORFile ( - const char * filename, - CORBA::String_var & ior) -{ - int result = 0; - FILE *in = ACE_OS::fopen (filename, "r"); - 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; - } - return result; -} -#endif - diff --git a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h index 86dcd75b190..90992dfb4c2 100644 --- a/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h +++ b/TAO/orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h @@ -30,10 +30,12 @@ #include "orbsvcs/PortableGroup/PG_PropertyManager.h" #include "orbsvcs/PortableGroup/PG_GenericFactory.h" #include "orbsvcs/PortableGroup/PG_ObjectGroupManager.h" +#include <orbsvcs/PortableGroup/PG_FactoryRegistry.h> #include "orbsvcs/FaultTolerance/FT_Service_Activate.h" #include "orbsvcs/FT_ReplicationManager/FT_FaultConsumer.h" #include "orbsvcs/CosNamingC.h" + namespace TAO { /** @@ -472,6 +474,9 @@ namespace TAO /// The GenericFactory responsible for creating all object groups. TAO_PG_GenericFactory generic_factory_; + + + /// The fault notifier. FT::FaultNotifier_var fault_notifier_; const char * fault_notifier_ior_; @@ -479,6 +484,9 @@ namespace TAO /// The fault consumer. TAO::FT_FaultConsumer fault_consumer_; + /// The factory registry + TAO::PG_FactoryRegistry factory_registry_; + /// Quit flag. int quit_; }; diff --git a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp index 6f387b8d6e9..a7ef0d43542 100644 --- a/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp +++ b/TAO/orbsvcs/Fault_Detector/FT_FaultDetectorFactory_i.cpp @@ -461,7 +461,13 @@ CORBA::Object_ptr TAO::FT_FaultDetectorFactory_i::create_object ( FT::TypeId object_type = 0; if (! ::TAO_PG::find (decoder, ::FT::FT_TYPE_ID, object_type) ) { + object_type = "unknown"; // Not required: missingParameter = 1; + ACE_DEBUG ((LM_DEBUG, "Object type not given.\n")); + } + else + { + ACE_DEBUG ((LM_DEBUG, "Object type: %s\n", object_type)); } FT::ObjectGroupId group_id = 0; diff --git a/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.cpp b/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.cpp index 2c41681825f..34c941b9edd 100644 --- a/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.cpp +++ b/TAO/orbsvcs/Fault_Detector/Fault_Detector_i.cpp @@ -52,6 +52,9 @@ TAO::Fault_Detector_i::Fault_Detector_i ( { this->notifier_ = FT::FaultNotifier::_duplicate(notifier); this->monitorable_ = FT::PullMonitorable::_duplicate(monitorable); + ACE_DEBUG ((LM_DEBUG, + "Object type %s\n", object_type + )); } TAO::Fault_Detector_i::~Fault_Detector_i () diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup.idl b/TAO/orbsvcs/orbsvcs/PortableGroup.idl index 0bdec8763d5..313697f984b 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup.idl +++ b/TAO/orbsvcs/orbsvcs/PortableGroup.idl @@ -86,6 +86,8 @@ module PortableGroup exception MemberAlreadyPresent {}; exception ObjectNotCreated {}; exception ObjectNotAdded {}; + /// TAO Specific: TypeConfict exception + exception TypeConflict {}; exception UnsupportedProperty { Name nam; Value val; @@ -208,9 +210,22 @@ module PortableGroup // The following FactoryRegistry interface is not included in the OMG PortableGroup IDL. // It's an extension needed as part of implementing the FT CORBA specification. + + /** + * a name for the role the object will play + * This allows multiple objects that implement the same interface (TypeId) + * to exist at a location as long as they play different roles. + */ + typedef CORBA::Identifier RoleName; + + /** + * Reserved criteria name for specifing role. + */ + const string role_criteron = "org.omg.portablegroup.Role"; + /** * Interface to allow generic factories for replicas to register themselves. - * Factories are distinguished by the type of object created (TypeId) and the + * Factories are distinguished by the role to be played by the created-object (role) and the * location at which they create the object (FactoryInfo.the_location) */ interface FactoryRegistry @@ -218,21 +233,25 @@ module PortableGroup /** * register a factory to create objects of the given type * at the location given in the FactoryInfo. - * @param type_id the type of object to be created. + * + * @param role the role the object-to-be-created plays. + * @param type_id type id of the object-to-be-created. * @param factory_info information about the factory including its location. * @throws MemberAlreadyPresent if there is already a factory for this type of object * at this location. + * @throws TypeConflict if the specified type_id is different from the type_id previously + * registered for this role. */ - void register_factory(in _TypeId type_id, in FactoryInfo factory_info) - raises (MemberAlreadyPresent); + void register_factory(in RoleName role, in _TypeId type_id, in FactoryInfo factory_info) + raises (MemberAlreadyPresent, TypeConflict); /** * Remove the registration of a factory. - * @param type_id the type of object formerly created by this factory. + * @param role the role played by the object formerly created by this factory. * @param location where the factory formerly created objects. - * @throws MemberNotPresent if no factory is available for the given type at this location. + * @throws MemberNotPresent if no factory is available for the given role at this location. */ - void unregister_factory(in _TypeId type_id, in Location location) + void unregister_factory(in RoleName role, in Location location) raises (MemberNotFound); /** @@ -241,7 +260,7 @@ module PortableGroup * This is not an error. * @param type_id the type of object formerly created by the factories to be unregistered. */ - void unregister_factory_by_type(in _TypeId type_id); + void unregister_factory_by_role(in RoleName role); /** * Remove the registration of all factories that create objects at a particular location. @@ -252,11 +271,12 @@ module PortableGroup void unregister_factory_by_location(in Location location); /** - * List all the factories that create a given type of object. - * If the type is unknown, an empty list is returned. This is not an error. - * @param type_id the type of object the factories create. + * List all the factories that create objects that fill a given role + * If the role is unknown, an empty list is returned. This is not an error. + * @param role the type of object the factories create. + * @param type_id what type of object is created to fill this role. */ - FactoryInfos list_factories_by_type(in _TypeId type_id); + FactoryInfos list_factories_by_role(in RoleName role, out _TypeId type_id); /** * List all the factories that create a objects at a given location. diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp index 2796027c815..cf09c0b4c5f 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp @@ -51,7 +51,7 @@ TAO::PG_FactoryRegistry::~PG_FactoryRegistry (void) } ////////////////////////////////////////////////////// -// FactoryRegistry_i public, non-CORBA methods +// PG_FactoryRegistry public, non-CORBA methods int TAO::PG_FactoryRegistry::parse_args (int argc, char * argv[]) { @@ -241,8 +241,9 @@ int TAO::PG_FactoryRegistry::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) return ::PortableGroup::FactoryRegistry::_narrow(this->this_obj_); } + ////////////////////////////////////////// -// FactoryRegistry_i CORBA methods +// PG_FactoryRegistry CORBA methods /* Reference:info typedef CosNaming::Name Name; @@ -255,52 +256,77 @@ int TAO::PG_FactoryRegistry::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) typedef sequence<FactoryInfo> FactoryInfos; */ +TAO::PG_FactoryRegistry::RoleInfo::RoleInfo(size_t estimated_number_entries) + : infos_(estimated_number_entries) +{ +} + void TAO::PG_FactoryRegistry::register_factory ( + const char * role, const char * type_id, const PortableGroup::FactoryInfo & factory_info ACE_ENV_ARG_DECL ) - ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberAlreadyPresent)) + ACE_THROW_SPEC (( + CORBA::SystemException + , PortableGroup::MemberAlreadyPresent + , PortableGroup::TypeConflict)) { METHOD_ENTRY(TAO::PG_FactoryRegistry::register_factory); - PortableGroup::FactoryInfos * infos; - if (this->registry_.find(type_id, infos) != 0) + RoleInfo * role_info; + auto_ptr<RoleInfo> safe_entry; + if (this->registry_.find(role, role_info) != 0) { ACE_DEBUG(( LM_DEBUG, - "FactoryRegistry: adding new type: %s\n", type_id + "%s: adding new role: %s:%s\n", this->identity_.c_str(), role, type_id )); // Note the 5. It's a guess about the number of factories - // that might exist for any particular type of object. + // that might exist for any particular role object. // todo: make it a parameter. - ACE_NEW_THROW_EX (infos, PortableGroup::FactoryInfos(5), + ACE_NEW_THROW_EX (role_info, RoleInfo(5), CORBA::NO_MEMORY()); - this->registry_.bind(type_id, infos); + safe_entry = auto_ptr<RoleInfo>(role_info); + role_info->type_id_ = type_id; + } + else + { + if (role_info->type_id_ != type_id) + { + ACE_THROW ( PortableGroup::TypeConflict() ); + } } - // at this point infos points to the infos structure - // for this type.. - size_t length = infos->length(); + + PortableGroup::FactoryInfos & infos = role_info->infos_;; + size_t length = infos.length(); for (size_t nInfo = 0; nInfo < length; ++nInfo) { - PortableGroup::FactoryInfo & info = (*infos)[nInfo]; + PortableGroup::FactoryInfo & info = infos[nInfo]; if (info.the_location == factory_info.the_location) { ACE_ERROR(( LM_ERROR, - "Attempt to register duplicate location %s for type: %s\n" , + "%s: Attempt to register duplicate location %s for role: %s\n" , + this->identity_.c_str(), ACE_static_cast(const char *, info.the_location[0].id), - type_id)); + role)); ACE_THROW (PortableGroup::MemberAlreadyPresent() ); } } - infos->length(length + 1); - (*infos)[length] = factory_info; + infos.length(length + 1); + infos[length] = factory_info; + + if (safe_entry.get() != 0) + { + this->registry_.bind(role, safe_entry.release()); + } ACE_DEBUG(( LM_DEBUG, - "FactoryRegistry: Added factory: [%d] %s@%s \n", + "%s: Added factory: [%d] %s@%s \n", + this->identity_.c_str(), ACE_static_cast(int,length + 1), - type_id, + role, ACE_static_cast(const char *, factory_info.the_location[0].id) )); @@ -308,7 +334,7 @@ void TAO::PG_FactoryRegistry::register_factory ( } void TAO::PG_FactoryRegistry::unregister_factory ( - const char * type_id, + const char * role, const PortableGroup::Location & location ACE_ENV_ARG_DECL ) @@ -316,24 +342,23 @@ void TAO::PG_FactoryRegistry::unregister_factory ( { METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory); - PortableGroup::FactoryInfos * infos; - if (this->registry_.find(type_id, infos) == 0) + RoleInfo * role_info; + if (this->registry_.find(role, role_info) == 0) { - // at this point infos points to the infos structure - // for this type.. - + PortableGroup::FactoryInfos & infos = role_info->infos_; int found = 0; - size_t length = infos->length(); + size_t length = infos.length(); for (size_t nInfo = 0; !found && nInfo < length; ++nInfo) { - PortableGroup::FactoryInfo & info = (*infos)[nInfo]; + PortableGroup::FactoryInfo & info = infos[nInfo]; if (info.the_location == location) { found = 1; ACE_ERROR(( LM_INFO, - "Unregistering factory %s@%s\n", - type_id, + "%s: Unregistering factory %s@%s\n", + this->identity_.c_str(), + role, ACE_static_cast(const char *, location[0].id) )); if (length > 1) @@ -341,29 +366,38 @@ void TAO::PG_FactoryRegistry::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 + "%s: Unregister_factory: Compress table: [%d] %s to [%d]\n", + this->identity_.c_str(), + (int)nInfo + 1, location, (int)nInfo )); - (*infos)[nInfo] = (*infos)[nInfo + 1]; + infos[nInfo] = infos[nInfo + 1]; nInfo += 1; } ACE_ERROR((LM_INFO, - "unregister_factory_by_location: New length [%d] %s\n", - (int)nInfo, type_id + "%s: unregister_factory: New length [%d] %s\n", + this->identity_.c_str(), + (int)nInfo, role )); - infos->length(nInfo); + infos.length(nInfo); } else { ACE_ASSERT ( length == 1 ); - if (this->registry_.unbind (type_id) == 0) + if (this->registry_.unbind (role) == 0) { - delete infos; + ACE_DEBUG(( LM_DEBUG, + "%s: No more factories registered for %s\n", + this->identity_.c_str(), + role + )); + delete role_info; } else { ACE_ERROR ((LM_ERROR, - "LOGIC ERROR AT " __FILE__ " (%d): Entry to be deleted disappeared\n", __LINE__)); + "%s: LOGIC ERROR AT " __FILE__ " (%d): Entry to be deleted disappeared\n", + this->identity_.c_str(), + __LINE__)); } } } @@ -372,13 +406,16 @@ void TAO::PG_FactoryRegistry::unregister_factory ( else { ACE_ERROR(( LM_ERROR, - "Attempt to unregister factory for unknown type %s\n", type_id + "%s, Attempt to unregister factory for unknown role %s\n", + this->identity_.c_str(), + role )); ACE_THROW ( PortableGroup::MemberNotFound() ); - infos->length(0); - this->registry_.bind(type_id, infos); } + ////////////////////// + // request complete + // check quit-on-idle if (registry_.current_size() == 0 && quit_state_ == LIVE) { ACE_ERROR(( LM_INFO, @@ -396,29 +433,37 @@ void TAO::PG_FactoryRegistry::unregister_factory ( METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory); } -void TAO::PG_FactoryRegistry::unregister_factory_by_type ( - const char * type_id +void TAO::PG_FactoryRegistry::unregister_factory_by_role ( + const char * role ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_type); - PortableGroup::FactoryInfos * infos; - if (this->registry_.unbind(type_id, infos) == 0) + METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_role); + + RoleInfo * role_info; + if (this->registry_.unbind(role, role_info) == 0) { ACE_DEBUG(( LM_DEBUG, - "Unregistering all factories for type %s\n", type_id + "%s: Unregistering all factories for role %s\n", + this->identity_.c_str(), + role )); // delete the entire set of factories for this location. - delete infos; + delete role_info; } else { ACE_ERROR(( LM_INFO, - "Info: unregister_factory_by_type: unknown type: %s\n", type_id + "%s: Unregister_factory_by_role: unknown role: %s\n", + this->identity_.c_str(), + role )); } + ///////////////////// + // Function complete + // check quit options if (registry_.current_size() == 0 && quit_state_ == LIVE) { ACE_ERROR(( LM_INFO, @@ -433,7 +478,7 @@ void TAO::PG_FactoryRegistry::unregister_factory_by_type ( } } - METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_type); + METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_role); } void TAO::PG_FactoryRegistry::unregister_factory_by_location ( @@ -444,7 +489,9 @@ void TAO::PG_FactoryRegistry::unregister_factory_by_location ( { METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_location); - ACE_Vector<ACE_CString> hitList; + //////////////////////////////////////////// + // a vector of roles that need to be deleted. + ACE_Vector<ACE_CString> emptyRoles; // iterate through the registery for (RegistryType_Iterator it = this->registry_.begin(); @@ -452,21 +499,24 @@ void TAO::PG_FactoryRegistry::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() )); + ACE_CString & role = entry.ext_id_; + RoleInfo * role_info = entry.int_id_; + + PortableGroup::FactoryInfos & infos = role_info->infos_; + // ACE_ERROR((LM_INFO, "unregister_factory_by_location: Checking role %s\n", role.c_str() )); int found = 0; - size_t length = infos->length(); + size_t length = infos.length(); for (size_t nInfo = 0; !found && nInfo < length; ++nInfo) { - PortableGroup::FactoryInfo & info = (*infos)[nInfo]; + 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 + "%s: Unregister_factory_by_location: Removing: [%d] %s@%s\n", + this->identity_.c_str(), + (int)nInfo, role.c_str(), location[0].id )); found = 1; if (length > 1) @@ -474,49 +524,54 @@ void TAO::PG_FactoryRegistry::unregister_factory_by_location ( while (nInfo + 1 < length) { ACE_ERROR((LM_INFO, - "unregister_factory_by_location: Move: [%d] %s to [%d]\n", - (int)nInfo + 1, type.c_str(), (int)nInfo + "%s: Unregister_factory_by_location: Move: [%d] %s to [%d]\n", + this->identity_.c_str(), + (int)nInfo + 1, role.c_str(), (int)nInfo )); - (*infos)[nInfo] = (*infos)[nInfo + 1]; + 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() + "%s: unregister_factory_by_location: New length [%d] %s\n", + this->identity_.c_str(), + (int)nInfo, role.c_str() )); - infos->length(nInfo); + infos.length(nInfo); } else { ACE_ERROR((LM_INFO, - "Removed all entries for %s\n", - type.c_str() + "%s: Removed all entries for %s\n", + this->identity_.c_str(), + role.c_str() )); ACE_ASSERT ( length == 1 ); // remember entries to be deleted - hitList.push_back(entry.ext_id_); + emptyRoles.push_back(entry.ext_id_); } } } } - // now remove any types that became empty + // now remove any roles that became empty - for (size_t nHit = 0; nHit < hitList.size(); ++nHit) + for (size_t nRole = 0; nRole < emptyRoles.size(); ++nRole) { ACE_ERROR((LM_INFO, - "Remove type %s\n", - hitList[nHit].c_str() + "%s: Remove role %s\n", + this->identity_.c_str(), + emptyRoles[nRole].c_str() )); - PortableGroup::FactoryInfos * infos; - if (this->registry_.unbind(hitList[nHit], infos) == 0) + RoleInfo * role_info; + if (this->registry_.unbind(emptyRoles[nRole], role_info) == 0) { - delete infos; + delete role_info; } else { ACE_ERROR ((LM_ERROR, - "LOGIC ERROR AT " __FILE__ " (%d): Entry to be deleted disappeared\n", + "%s: LOGIC ERROR AT " __FILE__ " (%d): Role to be deleted disappeared\n", + this->identity_.c_str(), __LINE__)); } } @@ -539,30 +594,36 @@ void TAO::PG_FactoryRegistry::unregister_factory_by_location ( METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_location); } -::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_type ( - const char * type_id +::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_role ( + const char * role, + CORBA::String_out type_id ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_type); + METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_role); - PortableGroup::FactoryInfos_var infos; - ACE_NEW_THROW_EX (infos, ::PortableGroup::FactoryInfos(), + // allocate stucture to be returned. + PortableGroup::FactoryInfos_var result; + ACE_NEW_THROW_EX (result, ::PortableGroup::FactoryInfos(), CORBA::NO_MEMORY (TAO_DEFAULT_MINOR_CODE, CORBA::COMPLETED_NO)); - PortableGroup::FactoryInfos * typeInfos; - if (this->registry_.find(type_id, typeInfos) == 0) + RoleInfo * role_info; + if (this->registry_.find(role, role_info) == 0) { - (*infos) = (*typeInfos); + type_id = role_info->type_id_.c_str(); + (*result) = role_info->infos_; } else { + type_id = ""; ACE_ERROR(( LM_INFO, - "Info: list_factories_by_type: unknown type %s\n", type_id + "%s: list_factories_by_role: unknown role %s\n", + this->identity_.c_str(), + role )); } - METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_type) infos._retn(); + METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_role) result._retn(); } ::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_location ( @@ -572,11 +633,11 @@ void TAO::PG_FactoryRegistry::unregister_factory_by_location ( ACE_THROW_SPEC ((CORBA::SystemException)) { METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_location); - ::PortableGroup::FactoryInfos_var infos; - ACE_NEW_THROW_EX (infos, ::PortableGroup::FactoryInfos(this->registry_.current_size()), + ::PortableGroup::FactoryInfos_var result; + ACE_NEW_THROW_EX (result, ::PortableGroup::FactoryInfos(this->registry_.current_size()), CORBA::NO_MEMORY (TAO_DEFAULT_MINOR_CODE, CORBA::COMPLETED_NO)); - size_t count = 0; + size_t result_length = 0; // iterate through the registery for (RegistryType_Iterator it = this->registry_.begin(); @@ -584,25 +645,26 @@ void TAO::PG_FactoryRegistry::unregister_factory_by_location ( ++it) { RegistryType_Entry & entry = *it; - PortableGroup::FactoryInfos * infos = entry.int_id_; + RoleInfo * role_info = entry.int_id_; + PortableGroup::FactoryInfos & found_infos = role_info->infos_; // iterate through the entry for this type int found = 0; - size_t length = infos->length(); + size_t length = found_infos.length(); for (size_t nInfo = 0; !found && nInfo < length; ++nInfo) { - PortableGroup::FactoryInfo & info = (*infos)[nInfo]; + PortableGroup::FactoryInfo & info = found_infos[nInfo]; if (info.the_location == location) { found = 1; - count += 1; - infos->length(count); - (*infos)[count-1] = info; + result_length += 1; + result->length(result_length); + (*result)[result_length-1] = info; } } } - METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_location) infos._retn(); + METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_location) result._retn(); } ////////////////////////////// @@ -629,16 +691,16 @@ int TAO::PG_FactoryRegistry::write_ior_file(const char * outputFile, const char #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) - template class ACE_Hash_Map_Manager <ACE_CString, PortableGroup::FactoryInfos *, MapMutex>; - template class ACE_Hash_Map_Entry <ACE_CString, PortableGroup::FactoryInfos *>; - template class ACE_Hash_Map_Iterator <ACE_CString, PortableGroup::FactoryInfos *, MapMutex>; + template class ACE_Hash_Map_Manager <ACE_CString, TAO::PG_FactoryRegistry::RoleInfo *, MapMutex>; + template class ACE_Hash_Map_Entry <ACE_CString, TAO::PG_FactoryRegistry::RoleInfo *>; + template class ACE_Hash_Map_Iterator <ACE_CString, TAO::PG_FactoryRegistry::RoleInfo *>; template class ACE_Vector<ACE_CString>; #elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) -# pragma instantiate ACE_Hash_Map_Manager <ACE_CString, PortableGroup::FactoryInfos *, MapMutex> -# pragma instantiate ACE_Hash_Map_Entry <ACE_CString, PortableGroup::FactoryInfos *> -# pragma instantiate ACE_Hash_Map_Iterator <ACE_CString, PortableGroup::FactoryInfos *, MapMutex> +# pragma instantiate ACE_Hash_Map_Manager <ACE_CString, TAO::PG_FactoryRegistry::RoleInfo *, MapMutex> +# pragma instantiate ACE_Hash_Map_Entry <ACE_CString, TAO::PG_FactoryRegistry::RoleInfo *> +# pragma instantiate ACE_Hash_Map_Iterator <ACE_CString, TAO::PG_FactoryRegistry::RoleInfo *, MapMutex> # pragma instantiate ACE_Vector<ACE_CString> #endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h index 133681f9e65..d44eb4427d6 100644 --- a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h @@ -46,12 +46,17 @@ namespace TAO */ class TAO_PortableGroup_Export PG_FactoryRegistry : public virtual POA_PortableGroup::FactoryRegistry { - /* <DESIGN> originally I used FactoryInfos_vars rather than FactoryInfos *, - but it actually made memory management harder. DLW </DESIGN> */ + struct RoleInfo + { + ACE_CString type_id_; + PortableGroup::FactoryInfos infos_; + + RoleInfo(size_t estimated_number_entries = 5); + }; typedef ACE_Null_Mutex MapMutex; - typedef ACE_Hash_Map_Manager <ACE_CString, PortableGroup::FactoryInfos *, MapMutex> RegistryType; - typedef ACE_Hash_Map_Entry <ACE_CString, PortableGroup::FactoryInfos *> RegistryType_Entry; - typedef ACE_Hash_Map_Iterator <ACE_CString, PortableGroup::FactoryInfos *, MapMutex> RegistryType_Iterator; + typedef ACE_Hash_Map_Manager <ACE_CString, RoleInfo *, MapMutex> RegistryType; + typedef ACE_Hash_Map_Entry <ACE_CString, RoleInfo *> RegistryType_Entry; + typedef ACE_Hash_Map_Iterator <ACE_CString, RoleInfo *, MapMutex> RegistryType_Iterator; ////////////////////// // non-CORBA interface @@ -111,24 +116,29 @@ namespace TAO // See IDL for documentation virtual void register_factory ( + const char * role, const char * type_id, const PortableGroup::FactoryInfo & factory_info ACE_ENV_ARG_DECL ) - ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberAlreadyPresent)); + ACE_THROW_SPEC (( + CORBA::SystemException + , PortableGroup::MemberAlreadyPresent + , PortableGroup::TypeConflict)); virtual void unregister_factory ( - const char * type_id, - const PortableGroup::Location & location + const char * role, + const PortableGroup::Location & location ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberNotFound)); - virtual void unregister_factory_by_type ( - const char * type_id - ACE_ENV_ARG_DECL - ) - ACE_THROW_SPEC ((CORBA::SystemException)); + virtual void unregister_factory_by_role ( + const char * role + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException)); + virtual void unregister_factory_by_location ( const PortableGroup::Location & location @@ -136,11 +146,12 @@ namespace TAO ) ACE_THROW_SPEC ((CORBA::SystemException)); - virtual ::PortableGroup::FactoryInfos * list_factories_by_type ( - const char * type_id - ACE_ENV_ARG_DECL - ) - ACE_THROW_SPEC ((CORBA::SystemException)); + virtual ::PortableGroup::FactoryInfos * list_factories_by_role ( + const char * role, + CORBA::String_out type_id + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException)); virtual ::PortableGroup::FactoryInfos * list_factories_by_location ( const PortableGroup::Location & location diff --git a/TAO/orbsvcs/tests/FT_App/FT_App.mpc b/TAO/orbsvcs/tests/FT_App/FT_App.mpc index 28d7e8931f4..883935a6c11 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_App.mpc +++ b/TAO/orbsvcs/tests/FT_App/FT_App.mpc @@ -20,7 +20,7 @@ project(*Client_Unit): taoclient, fault_tolerance, iormanip, ftorb, orbsvcsexe { } } -project(*Client): taoclient, fault_tolerance, iormanip, ftorb, orbsvcsexe { +project(*Client): taoclient, fault_tolerance, orbsvcsexe { exename = ft_client includes += $(TAO_ROOT) Source_Files { @@ -42,7 +42,7 @@ project(*Notifier): taoserver, fault_tolerance, orbsvcsexe { // Custom folder: script to run this test // too bad this doesn't work! // If you omit the generic_outputext, it creates an empty folder -// if you include the generic_outputext, it tries to "build" the .pl +// if you include the generic_outputext, it tries to "build" the .pl // file which runs the test even when you don't want to. // Define_Custom(Script) { // inputext = .pl, .py, .rb @@ -117,9 +117,9 @@ project(*FactoryRegistry): taoclient, fault_tolerance, orbsvcsexe { project(*Creator): taoclient, fault_tolerance, orbsvcsexe { exename = ft_create - Source_Files { - TAO_Object_Group_Creator.cpp - } + Source_Files { + TAO_Object_Group_Creator.cpp + } // explicitly omit IDL files IDL_Files { @@ -128,7 +128,7 @@ project(*Creator): taoclient, fault_tolerance, orbsvcsexe { Documentation_Files { // pretend the pl file is documentation for now run_test_registry.pl - run_test_rmregistry.pl + run_test_rmregistry.pl } } diff --git a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp index f405396da05..ed6bcc413f8 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp @@ -14,6 +14,7 @@ #include "FT_TestReplica_i.h" #include <ace/Get_Opt.h> #include <orbsvcs/CosNamingC.h> +#include <orbsvcs/PortableGroupC.h> #include <tao/PortableServer/ORB_Manager.h> #include <orbsvcs/PortableGroup/PG_Properties_Decoder.h> @@ -42,9 +43,7 @@ return /* value goes here */ -static const char * type_property = "type"; - -static const char * type_initial_value = "INITIAL_VALUE"; +static const char * criterion_initial_value = "INITIAL_VALUE"; ////////////////////////////////////////////////////// // FT_ReplicaFactory_i Construction/destruction @@ -63,6 +62,11 @@ FT_ReplicaFactory_i::FT_ReplicaFactory_i () , have_replication_manager_(0) , replication_manager_(0) { + ACE_DEBUG((LM_DEBUG, "TestReplica type_id: %s\n", FT_TEST::_tc_TestReplica->id() )); +// ACE_DEBUG((LM_DEBUG, "Hobbit type_id: %s\n", FT_TEST::_tc_Hobbit->id() )); +// ACE_DEBUG((LM_DEBUG, "Elf type_id: %s\n", FT_TEST::_tc_Elf->id() )); +// ACE_DEBUG((LM_DEBUG, "Human type_id: %s\n", FT_TEST::_tc_Human->id() )); + } @@ -164,7 +168,7 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) } case 'i': { - this->types_.push_back(get_opts.opt_arg ()); + this->roles_.push_back(get_opts.opt_arg ()); break; } case 'l': @@ -193,16 +197,15 @@ int FT_ReplicaFactory_i::parse_args (int argc, char * argv[]) // fall thru default: ACE_ERROR_RETURN ((LM_ERROR, - "usage: %s" - " -o <factory ior file>" - " -n <naming service registration name>" - " -f <factory registry ior file>" - " -i <registration: type_id>" - " -l <registration: location>" - " -t <test replica ior file>" - " -u{nregister by location}" - " -q{uit on idle}" - "\n", + "usage: %s \n" + " -o <factory ior file>\n" + " -n <naming service registration name>\n" + " -f <factory registry ior file>\n" + " -i <registration: role>\n" + " -l <registration: location>\n" + " -t <test replica ior file>\n" + " -u{nregister by location}\n" + " -q{uit on idle}\n", argv [0]), -1); break; @@ -301,13 +304,13 @@ int FT_ReplicaFactory_i::fini (ACE_ENV_SINGLE_ARG_DECL) } else { - size_t typeCount = types_.size(); - for (size_t nType = 0; nType < typeCount; ++nType) + size_t roleCount = roles_.size(); + for (size_t nRole = 0; nRole < roleCount; ++nRole) { - const char * typeId = this->types_[nType].c_str(); + const char * roleName = this->roles_[nRole].c_str(); ACE_ERROR (( LM_INFO, "Factory for: %s@%s unregistering from factory registry\n", - typeId, + roleName, location_ )); @@ -315,7 +318,7 @@ int FT_ReplicaFactory_i::fini (ACE_ENV_SINGLE_ARG_DECL) location.length(1); location[0].id = CORBA::string_dup(location_); this->factory_registry_->unregister_factory ( - typeId, + roleName, location ACE_ENV_ARG_PARAMETER); ACE_CHECK; @@ -381,17 +384,20 @@ int FT_ReplicaFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) if (this->factory_registry_ior_ != 0) { - CORBA::Object_var reg_obj = this->orb_->string_to_object(factory_registry_ior_ - ACE_ENV_ARG_PARAMETER); - ACE_TRY_CHECK; - this->factory_registry_ = ::PortableGroup::FactoryRegistry::_narrow(reg_obj); - if (CORBA::is_nil(this->factory_registry_)) + if (ACE_OS::strcmp (this->factory_registry_ior_, "none") != 0) { - ACE_ERROR (( LM_ERROR, - "Can't resolve Factory Registry IOR %s\n", - this->factory_registry_ior_ - )); - result = -1; + CORBA::Object_var reg_obj = this->orb_->string_to_object(factory_registry_ior_ + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + this->factory_registry_ = ::PortableGroup::FactoryRegistry::_narrow(reg_obj); + if (CORBA::is_nil(this->factory_registry_)) + { + ACE_ERROR (( LM_ERROR, + "Can't resolve Factory Registry IOR %s\n", + this->factory_registry_ior_ + )); + result = -1; + } } } else // no -f option. Try RIR(RM) @@ -400,14 +406,12 @@ int FT_ReplicaFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) // Find the ReplicationManager ACE_TRY_NEW_ENV { -ACE_ERROR ((LM_DEBUG,"RIR(ReplicationManager)\n" )); CORBA::Object_var rm_obj = orb->resolve_initial_references("ReplicationManager" ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; this->replication_manager_ = ::FT::ReplicationManager::_narrow(rm_obj.in() ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; if (!CORBA::is_nil (replication_manager_)) { -ACE_ERROR ((LM_DEBUG, "Found a _real_ ReplicationManager. Ask it for a factory registry.\n")); have_replication_manager_ = 1; // empty criteria ::PortableGroup::Criteria criteria; @@ -415,19 +419,16 @@ ACE_ERROR ((LM_DEBUG, "Found a _real_ ReplicationManager. Ask it for a factory ACE_TRY_CHECK; if (CORBA::is_nil (this->factory_registry_)) { - result = -1; - ACE_ERROR ((LM_ERROR,"ReplicaFactory: ReplicationManager failed to return FactoryRegistry.\n" )); + ACE_ERROR ((LM_ERROR,"ReplicaFactory: ReplicationManager failed to return FactoryRegistry. Factory will not be registered.\n" )); } } else { -ACE_ERROR ((LM_DEBUG,"did we get a FactoryRegistry instead?\n" )); this->factory_registry_ = ::PortableGroup::FactoryRegistry::_narrow(rm_obj.in() ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; if (!CORBA::is_nil(this->factory_registry_)) { -ACE_ERROR ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" )); - result = 0; // success + ACE_DEBUG ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" )); } else { @@ -438,8 +439,7 @@ ACE_ERROR ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" )); ACE_CATCHANY { ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, - "ReplicaFactory: Exception resolving ReplicationManager, and no -f option was given.\n" ); - result = 1; + "ReplicaFactory: Exception resolving ReplicationManager, and no -f option was given. Factory will not be registered.\n" ); } ACE_ENDTRY; @@ -450,10 +450,10 @@ ACE_ERROR ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" )); ::PortableGroup::GenericFactory_var this_var = ::PortableGroup::GenericFactory::_narrow(this_obj); if (! CORBA::is_nil(this_var)) { - size_t typeCount = types_.size(); - for (size_t nType = 0; nType < typeCount; ++nType) + size_t roleCount = roles_.size(); + for (size_t nRole = 0; nRole < roleCount; ++nRole) { - const char * typeId = this->types_[nType].c_str(); + const char * roleName = this->roles_[nRole].c_str(); PortableGroup::FactoryInfo info; info.the_factory = this_var; @@ -461,17 +461,18 @@ ACE_ERROR ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" )); 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); + info.the_criteria[0].nam[0].id = CORBA::string_dup(PortableGroup::role_criteron); + info.the_criteria[0].val <<= CORBA::string_dup(roleName); ACE_ERROR (( LM_INFO, "Factory: %s@%s registering with factory registry\n", - typeId, + roleName, location_ )); this->factory_registry_->register_factory( - typeId, + roleName, + FT_TEST::_tc_TestReplica->id(), info ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; @@ -488,7 +489,7 @@ ACE_ERROR ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" )); int identified = 0; // bool - if (this->types_.size() > 0) + if (this->roles_.size() > 0) { this->identity_ = "Factory"; if (this->location_ != 0) @@ -511,9 +512,13 @@ ACE_ERROR ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" )); } else { - // if no IOR file specified, - // then always try to register with name service - this->ns_name_ = "FT_ReplicaFactory"; + if (this->registered_) + { + // if we didn't register with a FactoryRegistry + // and no IOR file specified, + // then always try to register with name service + this->ns_name_ = "FT_ReplicaFactory"; + } } if (this->ns_name_ != 0) @@ -623,22 +628,22 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( const char * missingParameterName = 0; CORBA::Long initialValue = 0; - if (! ::TAO_PG::find (decoder, type_initial_value, initialValue) ) + if (! ::TAO_PG::find (decoder, criterion_initial_value, initialValue) ) { // not required. Otherwise: // missingParameter = 1; - // missingParameterName = type_initial_value; + // missingParameterName = criterion_initial_value; } - const char * type = "replica"; - if (! ::TAO_PG::find (decoder, type_property, type) ) + const char * role = "replica"; + if (! ::TAO_PG::find (decoder, PortableGroup::role_criteron, role) ) { ACE_ERROR((LM_INFO, - "Property \"%s\" not found?\n", type_property + "Property \"%s\" not found?\n", PortableGroup::role_criteron )); // not required. Otherwise: // missingParameter = 1; - // missingParameterName = "type"; + // missingParameterName = PortableGroup::role_criteron; } if (missingParameter) @@ -650,7 +655,7 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( ACE_THROW ( PortableGroup::InvalidCriteria() ); } - FT_TestReplica_i * replica = create_replica(type); + FT_TestReplica_i * replica = create_replica(role); if (replica == 0) { ACE_ERROR ((LM_ERROR, @@ -666,7 +671,7 @@ CORBA::Object_ptr FT_ReplicaFactory_i::create_object ( (*factory_creation_id) <<= factory_id; ACE_ERROR ((LM_INFO, - "Created %s@%s#%d.\n", type, this->location_, ACE_static_cast(int, factory_id) + "Created %s@%s#%d.\n", role, this->location_, ACE_static_cast(int, factory_id) )); @@ -680,11 +685,13 @@ FT_TestReplica_i * FT_ReplicaFactory_i::create_replica(const char * name) CORBA::ULong factoryId = allocate_id(); FT_TestReplica_i * pFTReplica = 0; + ACE_NEW_NORETURN(pFTReplica, FT_TestReplica_i( this, name, factoryId )); + this->replicas_[factoryId] = pFTReplica; this->empty_slots_ -= 1; diff --git a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h index 259089da68b..2ec4df9e817 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h @@ -41,7 +41,8 @@ class FT_TestReplica_i; * Implement the GenericFactory interface. */ class FT_ReplicaFactory_i - : public virtual POA_FT_TEST::ReplicaFactory +//FT_TEST::ReplicaFactory + : public virtual POA_PortableGroup::GenericFactory { typedef ACE_Vector<FT_TestReplica_i *> ReplicaVec; typedef ACE_Vector<ACE_CString> StringVec; @@ -251,8 +252,9 @@ private: CosNaming::Name this_name_; - - StringVec types_; + ///////////////// + // The roles used to register types + StringVec roles_; const char * location_; diff --git a/TAO/orbsvcs/tests/FT_App/FT_TestReplica.idl b/TAO/orbsvcs/tests/FT_App/FT_TestReplica.idl index ec9048a3b74..72f7bdde80c 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_TestReplica.idl +++ b/TAO/orbsvcs/tests/FT_App/FT_TestReplica.idl @@ -104,6 +104,14 @@ module FT_TEST oneway void shutdown(); }; + /////////////////////// + // roles for unit tests + // A TestReplica can act as a... + +// typedef TestReplica Hobbit; +// typedef TestReplica Elf; +// typedef TestReplica Human; + }; #endif // for #ifndef FT_TESTREPLICA_IDL diff --git a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp index 816068ff57b..74bbe47d5d6 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.cpp @@ -17,6 +17,7 @@ #include "FT_ReplicaFactory_i.h" #include <tao/PortableServer/ORB_Manager.h> #include <iostream> +#include "FT_TestReplicaC.h" ////////////////// // TestReplica_i @@ -112,6 +113,15 @@ void FT_TestReplica_i::suicide(const char * note) ///////////////////////////////////////////////////// // class FT_TestReplica_i public, non-CORBA interface + + + +//static +const char * FT_TestReplica_i::repository_id() +{ + return FT_TEST::_tc_TestReplica->id(); +} + int FT_TestReplica_i::parse_args (int argc, char *argv[]) { diff --git a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h index f1bf1efbd4d..e001e82e393 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h +++ b/TAO/orbsvcs/tests/FT_App/FT_TestReplica_i.h @@ -75,9 +75,10 @@ public: void request_quit(); - unsigned long factory_id()const; + static const char * repository_id(); + ::FT_TEST::TestReplica_ptr object_reference(); PortableServer::ObjectId object_id()const; diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp b/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp index ddcd925f5e2..c831f693403 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubFaultAnalyzer.cpp @@ -185,7 +185,7 @@ int StubFaultAnalyzer::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) value <<= object_location; encoder.add(::FT::FT_LOCATION, value); - FT::TypeId object_type = 0; + FT::TypeId object_type = CORBA::string_dup("dummy_type"); value <<= object_type; encoder.add(::FT::FT_TYPE_ID, value); @@ -209,6 +209,9 @@ int StubFaultAnalyzer::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) encoder.encode(criteria); FT::GenericFactory::FactoryCreationId_var factory_creation_id; + ACE_DEBUG((LM_DEBUG, + "Call create_object with type: %s\n", type_id.in() + )); this->factory_->create_object ( type_id.in(), criteria.in(), diff --git a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp index e1cc7a9edab..566b82d97bb 100644 --- a/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp +++ b/TAO/orbsvcs/tests/FT_App/StubFaultConsumer.cpp @@ -266,10 +266,20 @@ void StubFaultConsumer::push_structured_event( for (size_t nProp = 0; nProp < propertyCount; ++nProp) { const CosNotification::Property & property = filterable[nProp]; + + const char * property_name = ACE_static_cast (const char *, property.name); + const char * value = "<unknown>"; + if (property.value >>= value ) + { + // ok! + } ACE_ERROR ((LM_ERROR, - "FaultConsumer: Property Name: %s\n", - ACE_static_cast (const char *, property.name) + "FaultConsumer: Property Name: %s=%s\n", + property_name, + value )); + + // int todo_finish_decode; } diff --git a/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp index 9611bc0c914..efaa8abf28a 100644 --- a/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp +++ b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp @@ -19,11 +19,14 @@ #include <ace/Get_Opt.h> + TAO::Object_Group_Creator::Object_Group_Creator () : registry_filename_(0) , registry_(0) , replication_manager_(0) , have_replication_manager_(0) + , make_iogr_(0) + , write_iors_(1) , iogr_seq_(0) { } @@ -37,21 +40,21 @@ TAO::Object_Group_Creator::parse_args (int argc, char *argv[]) { int result = 0; - ACE_Get_Opt get_opts (argc, argv, "t:f:k:"); + ACE_Get_Opt get_opts (argc, argv, "r:f:u:gi"); int c; while (result == 0 && (c = get_opts ()) != -1) { switch (c) { - case 't': + case 'r': { - this->create_types_.push_back (get_opts.opt_arg ()); + this->create_roles_.push_back (get_opts.opt_arg ()); break; } - case 'k': + case 'u': { - this->kill_types_.push_back (get_opts.opt_arg ()); + this->unregister_roles_.push_back (get_opts.opt_arg ()); break; } case 'f': @@ -60,6 +63,18 @@ TAO::Object_Group_Creator::parse_args (int argc, char *argv[]) break; } + case 'g': + { + make_iogr_ = !make_iogr_; + break; + } + + case 'i': + { + write_iors_ = ! write_iors_; + break; + } + default: { std::cerr << "Creator: Unknown argument -" << (char) c << std::endl; @@ -76,7 +91,7 @@ TAO::Object_Group_Creator::parse_args (int argc, char *argv[]) } } - if ( this->create_types_.size() == 0 && this->kill_types_.size()) + if ( this->create_roles_.size() == 0 && this->unregister_roles_.size()) { std::cerr << "Creator: neither create (-t) nor kill (-k) specified. Nothing to do." << std::endl; usage (std::cerr); @@ -89,8 +104,11 @@ TAO::Object_Group_Creator::parse_args (int argc, char *argv[]) void TAO::Object_Group_Creator::usage(ostream & out)const { out << "usage" - << " -t <type_id for objects to be created>" - << " -f <factory ior file>" + << " -r <role for objects to be created>" + << " -f <factory registry ior file> (if not specified, ReplicationManager is used.)" + << " -u <role to be unregistered (for testing factory registry)>" + << " -g (toggle write iogr for each group (default is not to write iogrs))" + << " -i (toggle write ior for each object (default is to write iors))" << std::endl; } @@ -129,7 +147,6 @@ int TAO::Object_Group_Creator::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) // Find the ReplicationManager ACE_TRY_NEW_ENV { -std::cout << "RIR(ReplicationManager)" << std::endl; CORBA::Object_var rm_obj = orb->resolve_initial_references("ReplicationManager" ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; @@ -137,7 +154,6 @@ std::cout << "RIR(ReplicationManager)" << std::endl; ACE_TRY_CHECK; if (!CORBA::is_nil (replication_manager_)) { -std::cout << "Found a _real_ ReplicationManager. Ask it for a factory registry." << std::cout; have_replication_manager_ = 1; // empty criteria ::PortableGroup::Criteria criteria; @@ -155,12 +171,11 @@ std::cout << "Found a _real_ ReplicationManager. Ask it for a factory registry. else { -std::cout << "did we get a FactoryRegistry instead?" << std::endl; registry_ = ::PortableGroup::FactoryRegistry::_narrow(rm_obj.in() ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; if (!CORBA::is_nil(registry_)) { -std::cout << "Found a FactoryRegistry DBA ReplicationManager" << std::endl; + std::cout << "Found a FactoryRegistry DBA ReplicationManager" << std::endl; result = 0; // success } else @@ -185,44 +200,46 @@ std::cout << "Found a FactoryRegistry DBA ReplicationManager" << std::endl; int TAO::Object_Group_Creator::run (ACE_ENV_SINGLE_ARG_DECL) { int result = 0; - size_t typeCount = this->create_types_.size(); + size_t typeCount = this->create_roles_.size(); for ( size_t nType = 0; result == 0 && nType < typeCount; ++nType) { - const char * type = this->create_types_[nType].c_str(); - result = create_group (type); + const char * role = this->create_roles_[nType].c_str(); + result = create_group (role); } - typeCount = this->kill_types_.size(); + typeCount = this->unregister_roles_.size(); for ( nType = 0; result == 0 && nType < typeCount; ++nType) { - const char * type = this->kill_types_[nType].c_str(); - result = kill_type (type); + const char * role = this->unregister_roles_[nType].c_str(); + result = unregister_role (role); } return result; } -int TAO::Object_Group_Creator::kill_type(const char * type ACE_ENV_ARG_DECL) +int TAO::Object_Group_Creator::unregister_role(const char * role ACE_ENV_ARG_DECL) { int result = 0; - std::cout << std::endl << "Creator: Unregistering all factories for " << type << std::endl; - this->registry_->unregister_factory_by_type (type ACE_ENV_ARG_PARAMETER); + std::cout << std::endl << "Creator: Unregistering all factories for " << role << std::endl; + this->registry_->unregister_factory_by_role (role ACE_ENV_ARG_PARAMETER); ACE_CHECK; return result; } -int TAO::Object_Group_Creator::create_group(const char * type ACE_ENV_ARG_DECL) +int TAO::Object_Group_Creator::create_group(const char * role ACE_ENV_ARG_DECL) { int result = 0; - std::cout << std::endl << "Creator: Creating group of " << type << std::endl; + std::cout << std::endl << "Creator: Creating group of " << role << std::endl; - ::PortableGroup::FactoryInfos_var infos = this->registry_->list_factories_by_type (type + CORBA::String_var type_id; + ::PortableGroup::FactoryInfos_var infos = this->registry_->list_factories_by_role (role, type_id ACE_ENV_ARG_PARAMETER) ACE_CHECK; CORBA::ULong count = infos->length(); - std::cout << "Creator: found " << count << " factories for " << type << std::endl; + std::cout << "Creator: found " << count << " factories for " + << role << "(" << ACE_static_cast(const char *, type_id) << ")"<< std::endl; if (count > 0) { @@ -230,11 +247,16 @@ int TAO::Object_Group_Creator::create_group(const char * type ACE_ENV_ARG_DECL) // Begin with an empty IOGR ::PortableGroup::GenericFactory::FactoryCreationId_var creation_id; CORBA::Object_var iogr; - if (0 && this->have_replication_manager_) + if (make_iogr_ && this->have_replication_manager_) { - PortableGroup::Criteria criteria; + PortableGroup::Criteria criteria(1); + criteria.length(1); + criteria[0].nam.length(1); + criteria[0].nam[0].id = PortableGroup::PG_MEMBERSHIP_STYLE; + criteria[0].val <<= PortableGroup::MEMB_APP_CTRL; + iogr = this->replication_manager_->create_object( - type, + type_id.in(), criteria, creation_id ACE_ENV_ARG_PARAMETER @@ -253,11 +275,11 @@ int TAO::Object_Group_Creator::create_group(const char * type ACE_ENV_ARG_DECL) }; */ const char * loc_name = info.the_location[0].id; - std::cout << "Creator: Creating " << type << " at " << loc_name << std::endl; + std::cout << "Creator: Creating " << role << " at " << loc_name << std::endl; PortableGroup::GenericFactory::FactoryCreationId_var factory_creation_id; CORBA::Object_var created_obj = info.the_factory->create_object ( - type, + type_id.in(), info.the_criteria, factory_creation_id ACE_ENV_ARG_PARAMETER); @@ -267,41 +289,45 @@ int TAO::Object_Group_Creator::create_group(const char * type ACE_ENV_ARG_DECL) const char * replica_ior = orb_->object_to_string (created_obj ACE_ENV_ARG_PARAMETER ); ACE_CHECK; - //////////////////////////////////// - // Somewhat of a hack - // guess at type of factory creation id - 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 + + if (write_iors_) { - std::cerr << "Can't decypher factory creation id." << std::endl; - // Guessed wrong. Just use default value - } + //////////////////////////////////// + // Somewhat of a hack + // guess at role of factory creation id + 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" + char replica_ior_filename[200]; // "${role}_$(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'; + ACE_OS::snprintf(replica_ior_filename, sizeof(replica_ior_filename)-1, "%s_%s_%lu.ior", + role, + 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; + 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; + if (write_ior_file(replica_ior_filename, replica_ior) != 0) + { + std::cerr << "Creator: Error writing ior [" << replica_ior << "] to " << replica_ior_filename << std::endl; + } } - if (0 && this->have_replication_manager_) + if (make_iogr_ && this->have_replication_manager_) { iogr = this->replication_manager_->add_member (iogr, info.the_location, @@ -321,16 +347,16 @@ int TAO::Object_Group_Creator::create_group(const char * type ACE_ENV_ARG_DECL) } } - std::cout << "Creator: Successfully created group of " << type << std::endl; + std::cout << "Creator: Successfully created group of " << role << std::endl; - if(0 && have_replication_manager_) + if(make_iogr_ && have_replication_manager_) { const char * replica_iogr = orb_->object_to_string (iogr ACE_ENV_ARG_PARAMETER ); ACE_CHECK; char replica_iogr_filename[200]; ACE_OS::snprintf(replica_iogr_filename, sizeof(replica_iogr_filename)-1, "%s_%lu.iogr", - type, + role, this->iogr_seq_); replica_iogr_filename[sizeof(replica_iogr_filename)-1] = '\0'; diff --git a/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h index eb3e1ea1bc0..52653c6cfc5 100644 --- a/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h +++ b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.h @@ -1,7 +1,7 @@ /* -*- C++ -*- */ //============================================================================= /** - * @file TAO_Object_Group_Creator.cpp + * @file TAO_Object_Group_Creator.h * * $Id$ * @@ -57,8 +57,8 @@ namespace TAO void usage (ostream & out)const; int write_ior_file(const char * outputFile, const char * ior); - int create_group(const char * type_id ACE_ENV_ARG_DECL); - int kill_type(const char * type_id ACE_ENV_ARG_DECL); + int create_group(const char * role ACE_ENV_ARG_DECL); + int unregister_role(const char * role ACE_ENV_ARG_DECL); //////////////////// // forbidden methods @@ -72,8 +72,8 @@ namespace TAO CORBA::ORB_var orb_; const char * registry_filename_; PortableGroup::FactoryRegistry_var registry_; - StringVec create_types_; - StringVec kill_types_; + StringVec create_roles_; + StringVec unregister_roles_; ::FT::ReplicationManager_var replication_manager_; @@ -83,6 +83,16 @@ namespace TAO int have_replication_manager_; /** + * bool: true if we should create IOGR's + */ + int make_iogr_; + + /** + * bool: true if we should write individual IOR files + */ + int write_iors_; + + /** * sequence number applied to created IOGRs */ unsigned long iogr_seq_; diff --git a/TAO/orbsvcs/tests/FT_App/run_test_notifier.pl b/TAO/orbsvcs/tests/FT_App/run_test_notifier.pl index 3121b92e6b6..9b37adf6a02 100755 --- a/TAO/orbsvcs/tests/FT_App/run_test_notifier.pl +++ b/TAO/orbsvcs/tests/FT_App/run_test_notifier.pl @@ -133,8 +133,8 @@ unlink $client_data; my($status) = 0; -my($REP1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -t $replica1_ior -l loc1 -i type1 -q"); -my($REP2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -t $replica2_ior -l loc2 -i type1 -q"); +my($REP1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -f none -t $replica1_ior -l loc1 -i type1 -q"); +my($REP2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -f none -t $replica2_ior -l loc2 -i type1 -q"); my($DET) = new PerlACE::Process ("$ENV{'TAO_ROOT'}/orbsvcs/Fault_Detector$build_directory/Fault_Detector", "-o $detector_ior -q"); my($NOT) = new PerlACE::Process ("$ENV{'TAO_ROOT'}/orbsvcs/Fault_Notifier$build_directory/Fault_Notifier", "-o $notifier_ior -v -q"); my($ANA) = new PerlACE::Process (".$build_directory/ft_analyzer", "-o $ready_file -n file://$notifier_ior -d file://$detector_ior -r file://$replica1_ior -r file://$replica2_ior -q"); diff --git a/TAO/orbsvcs/tests/FT_App/run_test_rmregistry.pl b/TAO/orbsvcs/tests/FT_App/run_test_rmregistry.pl new file mode 100755 index 00000000000..b35cb5acd2e --- /dev/null +++ b/TAO/orbsvcs/tests/FT_App/run_test_rmregistry.pl @@ -0,0 +1,380 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +# Purpose: +# To test the FactoryRegistry as a component of ReplicationManager +# +# Process being tested: +# FT_ReplicationManager +# implements PortableGroup::FactoryRegistry interface. +# Processes used in test: +# 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. +# Object Group Creator +# Creates groups of objects. +# +# Test Scenario (***Test: marks behavior being tested): +# +# First the test starts The ReplicationManager, +# 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, elves, and humans. +# The factory at rivendell can create elves. +# Hobbits, elves, and humans are roles for TestReplica objects. A creation parameter +# included as part of the registration information specifies which role they are playing. +# +# ***Test: The factories register themselves with the factory registry in the ReplicationManager. +# Registration information includes: +# the role, +# the type of object created, +# the location, +# an object reference to the factory and +# a 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 ReplicationManager::FactoryRegistry +# for the set of factories that can create objects for the desired role. +# Then it 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.] +# +# The object group creator is also told to unregister all factories that create humans. +# ***Test: It does so using the unregister_factory_by_role method. +# +# 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 ReplicationManager::FactoryRegistry. +# ***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 ReplicationManager is killed because it doesn't have a quit-on-idle option. + +use lib '../../../../bin'; +#use lib '$ENV{ACE_ROOT}/bin'; +use PerlACE::Run_Test; + +######################## +#command line options +#set defaults: +my($verbose) = 0; # 1: report perl actions before executing them +my($debug_builds) = 0; # 0: use exes from Release directories +my($simulated) = 1; # 1: use "client simulated" fault tolerance + +foreach $i (@ARGV) { + if ($i eq "--debug_build") + { + $debug_builds = 1; + } + elsif ($i eq "--no_simulate") # reverse this once we have FT ORB support + { + $simulated = 0; + } + elsif ($i eq "-v") + { + $verbose += 1; + } +} + +my($build_directory) = "/Release"; +if ( $debug_builds ) { + $build_directory = ""; +} + +if ( $verbose > 1) { + print "verbose: $verbose\n"; + print "debug_builds: $debug_builds -> $build_directory\n"; + print "simulated: $simulated\n"; +} + +my($role1) = "hobbit"; +my($role2) = "elf"; +my($role3) = "human"; + +my($location1) = "shire"; +my($location2) = "bree"; +my($location3) = "rivendell"; +my($location4) = "rohan"; + +#define temp files +my($rm_ior) = PerlACE::LocalFile ("rm.ior"); +my($factory1_ior) = PerlACE::LocalFile ("factory1.ior"); +my($factory2_ior) = PerlACE::LocalFile ("factory2.ior"); +my($factory3_ior) = PerlACE::LocalFile ("factory3.ior"); +my($replica1_ior) = PerlACE::LocalFile ("${role1}_${location1}_0.ior"); +my($replica2_ior) = PerlACE::LocalFile ("${role1}_${location2}_0.ior"); +my($replica3_ior) = PerlACE::LocalFile ("${role2}_${location2}_1.ior"); +my($replica4_ior) = PerlACE::LocalFile ("${role2}_${location3}_0.ior"); +my($replica5_ior) = PerlACE::LocalFile ("${role1}_${location1}_1.ior"); +my($replica6_ior) = PerlACE::LocalFile ("${role1}_${location2}_2.ior"); + +my($replica1_iogr) = PerlACE::LocalFile ("${role1}_0.iogr"); +my($replica2_iogr) = PerlACE::LocalFile ("${role2}_1.iogr"); +my($replica3_iogr) = PerlACE::LocalFile ("${role1}_2.iogr"); + +my($client_data) = PerlACE::LocalFile ("persistent.dat"); + +#discard junk from previous tests +unlink $rm_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($RM) = new PerlACE::Process ("$ENV{'TAO_ROOT'}/orbsvcs/FT_ReplicationManager$build_directory/FT_ReplicationManager", "-o $rm_ior"); +my($RMC) = new PerlACE::Process (".$build_directory/replmgr_controller", "-k file://$rm_ior -x"); +my($FAC1) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory1_ior -ORBInitRef ReplicationManager=file://$rm_ior -l $location1 -i $role1 -q"); +my($FAC2) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory2_ior -ORBInitRef ReplicationManager=file://$rm_ior -l $location2 -i $role1 -i $role2 -i $role3 -q -u"); +my($FAC3) = new PerlACE::Process (".$build_directory/ft_replica", "-o $factory3_ior -ORBInitRef ReplicationManager=file://$rm_ior -l $location3 -i $role2 -q -u"); +my($CTR) = new PerlACE::Process (".$build_directory/ft_create", "-ORBInitRef ReplicationManager=file://$rm_ior -r $role1 -r $role2 -r $role1 -u $role3"); + +my($CL1); +my($CL2); +my($CL3); +if (simulated) { + $CL1 = new PerlACE::Process (".$build_directory/ft_client", "-f file://$replica1_ior -f file://$replica2_ior -c testscript"); + $CL2 = new PerlACE::Process (".$build_directory/ft_client", "-f file://$replica3_ior -f file://$replica4_ior -c testscript"); + $CL3 = new PerlACE::Process (".$build_directory/ft_client", "-f file://$replica5_ior -f file://$replica6_ior -c testscript"); +}else{ + #todo figure out how to get iogr + $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"); +} + +####################### +# Start ReplicationManager + +print "\nTEST: starting ReplicationManager " . $RM->CommandLine . "\n" if ($verbose); +$RM->Spawn (); + +print "TEST: waiting for registry's IOR\n" if ($verbose); +if (PerlACE::waitforfile_timed ($rm_ior, 5) == -1) { + print STDERR "ERROR: cannot find file <$rm_ior>\n"; + $RM->Kill (); $RM->TimedWait (1); + exit 1; +} + +################# +# Start Factories + +print "\nTEST: starting factory 1 " . $FAC1->CommandLine . "\n" if ($verbose); +$FAC1->Spawn (); + +print "TEST: waiting for factory 1's IOR\n" if ($verbose); +if (PerlACE::waitforfile_timed ($factory1_ior, 5) == -1) { + print STDERR "ERROR: cannot find file <$factory1_ior>\n"; + $RM->Kill (); $RM->TimedWait (1); + $FAC1->Kill (); $FAC1->TimedWait (1); + exit 1; +} + +print "\nTEST: starting factory 2 " . $FAC2->CommandLine . "\n" if ($verbose); +$FAC2->Spawn (); + +print "TEST: waiting for factory 2's IOR\n" if ($verbose); +if (PerlACE::waitforfile_timed ($factory2_ior, 5) == -1) { + print STDERR "ERROR: cannot find file <$factory2_ior>\n"; + $FAC1->Kill (); $FAC1->TimedWait (1); + $RM->Kill (); $RM->TimedWait (1); + $FAC2->Kill (); $FAC2->TimedWait (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); + $RM->Kill (); $RM->TimedWait (1); + $FAC3->Kill (); $FAC3->TimedWait (1); + exit 1; +} + +###################### +# Create object groups + +print "\nTEST: starting object group creator " . $CTR->CommandLine . "\n" if ($verbose); +$CTR->Spawn (); + +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); + $RM->Kill (); $RM->TimedWait (1); + $CTR->Kill (); $CTR->TimedWait(1); + exit 1; +} + +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); + $RM->Kill (); $RM->TimedWait (1); + exit 1; +} + + +############# +# 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; +} + +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 (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 (30); +if ($factory2 != 0) { + print STDERR "ERROR: factory 2 returned $factory2\n"; + $status = 1; +} + +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: shutting down the replication manager.\n" if ($verbose); +$controller = $RMC->SpawnWaitKill (300); +if ($controller != 0) { + print STDERR "ERROR: replication manager controller returned $controller\n"; + $status = 1; +} + +print "\nTEST: wait for ReplicationManager.\n" if ($verbose); +#$RM->Kill (); +$repmgr = $RM->WaitKill (30); +if ($repmgr != 0) { + print STDERR "ERROR: ReplicationManager returned $repmgr\n"; + $status = 1; +} + +print "\nTEST: releasing scratch files.\n" if ($verbose); +unlink $rm_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/FaultTolerance/IOGR/Client_i.h b/TAO/orbsvcs/tests/FaultTolerance/IOGR/Client_i.h index 88f35ea28ca..110808818f7 100644 --- a/TAO/orbsvcs/tests/FaultTolerance/IOGR/Client_i.h +++ b/TAO/orbsvcs/tests/FaultTolerance/IOGR/Client_i.h @@ -20,7 +20,7 @@ #ifndef TEST_FT_IOGR_CLIENT_I_H #define TEST_FT_IOGR_CLIENT_I_H -#include "ace/pre.h" +#include /**/ "ace/pre.h" #include "tao/ORB.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) @@ -41,5 +41,5 @@ private: }; -#include "ace/post.h" +#include /**/ "ace/post.h" #endif /*TEST_FT_IOGR_CLIENT_I_H*/ |