diff options
author | wilson_d <wilson_d@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-10-15 00:15:53 +0000 |
---|---|---|
committer | wilson_d <wilson_d@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2003-10-15 00:15:53 +0000 |
commit | 8bb07c98fe8be3895327a77d6fb6bf60823ee4a1 (patch) | |
tree | d4e6776e7ab8186d7cfc9899ef2d5a1855f8193c | |
parent | 80c9e626e9768916acc9f142c6f919f583474e1f (diff) | |
download | ATCD-8bb07c98fe8be3895327a77d6fb6bf60823ee4a1.tar.gz |
ChangeLogTag: Tue Oct 14 18:35:07 2003 Dale Wilson <wilson_d@ociweb.com>
-rw-r--r-- | TAO/ChangeLog | 23 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp (renamed from TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp) | 110 | ||||
-rw-r--r-- | TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h | 237 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp | 4 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/FT_App/FT_App.mpc | 2 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp | 124 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h | 14 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h | 219 | ||||
-rw-r--r-- | TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp | 10 |
9 files changed, 432 insertions, 311 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index aa94c70e5ef..fb2dd653207 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,26 @@ +Tue Oct 14 18:35:07 2003 Dale Wilson <wilson_d@ociweb.com> + + * orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp: + * orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h: + * orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp: + Use FactoryRegistry in ReplicationManager if available. + + * orbsvcs/tests/FT_App/FactoryRegistry_i.cpp: + * orbsvcs/tests/FT_App/FactoryRegistry_i.h: + * orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp: + * orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h: + Move and rename from FT_APP to PortableGroup + + * orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp: + Use FactoryRegistry from PortableGroup + + * orbsvcs/tests/FT_App/FT_App.mpc: + remove FactoryRegistry_i.cpp + + * orbsvcs/tests/FT_App/run_test_registry.pl: + new unit test using ReplicationManager as FactoryRegistry + + Tue Oct 14 18:30:45 2003 Steve Totten <totten_s@ociweb.com> * orbsvcs/FT_ReplicationManager/FT_ReplicationManager.cpp: diff --git a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp index ecdd28fd6af..2796027c815 100644 --- a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.cpp +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.cpp @@ -2,7 +2,7 @@ // // $Id$ -#include "FactoryRegistry_i.h" +#include "PG_FactoryRegistry.h" #include <ace/Get_Opt.h> #include <ace/Vector_T.h> @@ -11,9 +11,10 @@ // Use this macro at the beginning of CORBA methods // to aid in debugging. -#define METHOD_ENTRY(name) \ - ACE_DEBUG (( LM_DEBUG, \ - "Enter %s\n", #name \ +#define METHOD_ENTRY(name) \ + if (TAO_debug_level <= 6){} else \ + ACE_DEBUG (( LM_DEBUG, \ + "Enter %s\n", #name \ )) // Use this macro to return from CORBA methods @@ -27,31 +28,34 @@ // will not do what you want it to: // if (cave_is_closing) METHOD_RETURN(Plugh::pirate) aarrggh; // Moral: Always use braces. -#define METHOD_RETURN(name) \ - ACE_DEBUG (( LM_DEBUG, \ - "Leave %s\n", #name \ - )); \ - return /* value goes here */ - -FactoryRegistry_i::FactoryRegistry_i () - : ior_output_file_(0) +#define METHOD_RETURN(name) \ + if (TAO_debug_level <= 6){} else \ + ACE_DEBUG (( LM_DEBUG, \ + "Leave %s\n", #name \ + )); \ + return /* value goes here */ + +TAO::PG_FactoryRegistry::PG_FactoryRegistry (const char * name) + : identity_(name) + , ior_output_file_(0) , ns_name_(0) , quit_on_idle_(0) , quit_state_(LIVE) , linger_(0) + , this_obj_(0) { } -FactoryRegistry_i::~FactoryRegistry_i (void) +TAO::PG_FactoryRegistry::~PG_FactoryRegistry (void) { } ////////////////////////////////////////////////////// // FactoryRegistry_i public, non-CORBA methods -int FactoryRegistry_i::parse_args (int argc, char * argv[]) +int TAO::PG_FactoryRegistry::parse_args (int argc, char * argv[]) { - ACE_Get_Opt get_opts (argc, argv, "o:q"); + ACE_Get_Opt get_opts (argc, argv, "o:n:q"); int c; while ((c = get_opts ()) != -1) @@ -63,6 +67,11 @@ int FactoryRegistry_i::parse_args (int argc, char * argv[]) this->ior_output_file_ = get_opts.opt_arg (); break; } + case 'n': + { + this->ns_name_ = get_opts.opt_arg(); + break; + } case 'q': { this->quit_on_idle_ = 1; @@ -74,7 +83,8 @@ int FactoryRegistry_i::parse_args (int argc, char * argv[]) default: ACE_ERROR_RETURN ((LM_ERROR, "usage: %s" - " -o <factory ior file>" + " -o <registry ior file>" + " -n <name to use to register with name service>" " -q{uit on idle}" "\n", argv [0]), @@ -86,18 +96,18 @@ int FactoryRegistry_i::parse_args (int argc, char * argv[]) return 0; } -const char * FactoryRegistry_i::identity () const +const char * TAO::PG_FactoryRegistry::identity () const { return this->identity_.c_str(); } -void FactoryRegistry_i::_remove_ref (ACE_ENV_SINGLE_ARG_DECL) +void TAO::PG_FactoryRegistry::_remove_ref (ACE_ENV_SINGLE_ARG_DECL) { this->quit_state_ = GONE; } -int FactoryRegistry_i::idle (int & result) +int TAO::PG_FactoryRegistry::idle (int & result) { result = 0; int quit = 0; @@ -116,7 +126,7 @@ int FactoryRegistry_i::idle (int & result) } -int FactoryRegistry_i::fini (ACE_ENV_SINGLE_ARG_DECL) +int TAO::PG_FactoryRegistry::fini (ACE_ENV_SINGLE_ARG_DECL) { if (this->ior_output_file_ != 0) { @@ -132,7 +142,7 @@ int FactoryRegistry_i::fini (ACE_ENV_SINGLE_ARG_DECL) return 0; } -int FactoryRegistry_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) +int TAO::PG_FactoryRegistry::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) { int result = 0; @@ -175,13 +185,14 @@ int FactoryRegistry_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) ACE_TRY_CHECK; // find my identity as a corba object - CORBA::Object_var this_obj = + this->this_obj_ = this->poa_->id_to_reference (object_id_.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; + // and create a ior string - this->ior_ = this->orb_->object_to_string (this_obj.in () + this->ior_ = this->orb_->object_to_string (this->this_obj_.in () ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; @@ -192,12 +203,6 @@ int FactoryRegistry_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) this->identity_ += this->ior_output_file_; result = write_ior_file (this->ior_output_file_, this->ior_); } - else - { - // if no IOR file specified, - // then always try to register with name service - this->ns_name_ = "FactoryRegistry"; - } if (this->ns_name_ != 0) { @@ -221,7 +226,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_obj.in() //CORBA::Object::_duplicate(this_obj) + this->naming_context_->rebind (this->this_name_, this->this_obj_.in() //CORBA::Object::_duplicate(this_obj) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; } @@ -229,6 +234,13 @@ int FactoryRegistry_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) return result; } + +::PortableGroup::FactoryRegistry_ptr TAO::PG_FactoryRegistry::reference() +{ + // narrow and duplicate + return ::PortableGroup::FactoryRegistry::_narrow(this->this_obj_); +} + ////////////////////////////////////////// // FactoryRegistry_i CORBA methods @@ -244,14 +256,14 @@ int FactoryRegistry_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) */ -void FactoryRegistry_i::register_factory ( +void TAO::PG_FactoryRegistry::register_factory ( const char * type_id, const PortableGroup::FactoryInfo & factory_info ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberAlreadyPresent)) { - METHOD_ENTRY(FactoryRegistry_i::register_factory); + METHOD_ENTRY(TAO::PG_FactoryRegistry::register_factory); PortableGroup::FactoryInfos * infos; if (this->registry_.find(type_id, infos) != 0) @@ -292,17 +304,17 @@ void FactoryRegistry_i::register_factory ( ACE_static_cast(const char *, factory_info.the_location[0].id) )); - METHOD_RETURN(FactoryRegistry_i::register_factory); + METHOD_RETURN(TAO::PG_FactoryRegistry::register_factory); } -void FactoryRegistry_i::unregister_factory ( +void TAO::PG_FactoryRegistry::unregister_factory ( const char * type_id, const PortableGroup::Location & location ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberNotFound)) { - METHOD_ENTRY(FactoryRegistry_i::unregister_factory); + METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory); PortableGroup::FactoryInfos * infos; if (this->registry_.find(type_id, infos) == 0) @@ -381,16 +393,16 @@ void FactoryRegistry_i::unregister_factory ( } } - METHOD_RETURN(FactoryRegistry_i::unregister_factory); + METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory); } -void FactoryRegistry_i::unregister_factory_by_type ( +void TAO::PG_FactoryRegistry::unregister_factory_by_type ( const char * type_id ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(FactoryRegistry_i::unregister_factory_by_type); + METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_type); PortableGroup::FactoryInfos * infos; if (this->registry_.unbind(type_id, infos) == 0) { @@ -421,16 +433,16 @@ void FactoryRegistry_i::unregister_factory_by_type ( } } - METHOD_RETURN(FactoryRegistry_i::unregister_factory_by_type); + METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_type); } -void FactoryRegistry_i::unregister_factory_by_location ( +void TAO::PG_FactoryRegistry::unregister_factory_by_location ( const PortableGroup::Location & location ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(FactoryRegistry_i::unregister_factory_by_location); + METHOD_ENTRY(TAO::PG_FactoryRegistry::unregister_factory_by_location); ACE_Vector<ACE_CString> hitList; @@ -524,16 +536,16 @@ void FactoryRegistry_i::unregister_factory_by_location ( } } - METHOD_RETURN(FactoryRegistry_i::unregister_factory_by_location); + METHOD_RETURN(TAO::PG_FactoryRegistry::unregister_factory_by_location); } -::PortableGroup::FactoryInfos * FactoryRegistry_i::list_factories_by_type ( +::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_type ( const char * type_id ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(FactoryRegistry_i::list_factories_by_type); + METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_type); PortableGroup::FactoryInfos_var infos; ACE_NEW_THROW_EX (infos, ::PortableGroup::FactoryInfos(), @@ -550,16 +562,16 @@ void FactoryRegistry_i::unregister_factory_by_location ( "Info: list_factories_by_type: unknown type %s\n", type_id )); } - METHOD_RETURN(FactoryRegistry_i::list_factories_by_type) infos._retn(); + METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_type) infos._retn(); } -::PortableGroup::FactoryInfos * FactoryRegistry_i::list_factories_by_location ( +::PortableGroup::FactoryInfos * TAO::PG_FactoryRegistry::list_factories_by_location ( const PortableGroup::Location & location ACE_ENV_ARG_DECL ) ACE_THROW_SPEC ((CORBA::SystemException)) { - METHOD_ENTRY(FactoryRegistry_i::list_factories_by_location); + METHOD_ENTRY(TAO::PG_FactoryRegistry::list_factories_by_location); ::PortableGroup::FactoryInfos_var infos; ACE_NEW_THROW_EX (infos, ::PortableGroup::FactoryInfos(this->registry_.current_size()), CORBA::NO_MEMORY (TAO_DEFAULT_MINOR_CODE, CORBA::COMPLETED_NO)); @@ -590,13 +602,13 @@ void FactoryRegistry_i::unregister_factory_by_location ( } } - METHOD_RETURN(FactoryRegistry_i::list_factories_by_location) infos._retn(); + METHOD_RETURN(TAO::PG_FactoryRegistry::list_factories_by_location) infos._retn(); } ////////////////////////////// // Implementation methods -int FactoryRegistry_i::write_ior_file(const char * outputFile, const char * ior) +int TAO::PG_FactoryRegistry::write_ior_file(const char * outputFile, const char * ior) { int result = -1; FILE* out = ACE_OS::fopen (outputFile, "w"); diff --git a/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h new file mode 100644 index 00000000000..133681f9e65 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/PortableGroup/PG_FactoryRegistry.h @@ -0,0 +1,237 @@ +// -*- C++ -*- +//============================================================================= +/** + * @file PG_FactoryRegistry.h + * + * $Id$ + * + * This file declares the implementation of PortableGroup::FactoryRegistry. + * Eventually this should be folded into the Fault Tolerance ReplicationManager + * + * @author Dale Wilson <wilson_d@ociweb.com> + */ +//============================================================================= + +#ifndef TAO_PG_FACTORYREGISTRY_H_ +#define TAO_PG_FACTORYREGISTRY_H_ +#include /**/ <ace/pre.h> +#include <ace/ACE.h> + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +////////////////////////////////// +// Classes declared in this header +namespace TAO +{ + class PG_FactoryRegistry; +} + +///////////////////////////////// +// Includes needed by this header +#include <orbsvcs/PortableGroupS.h> +#include <ace/Hash_Map_Manager.h> + + +///////////////////// +// Forward references + +namespace TAO +{ + /** + * Implement the PortableGroup::FactoryRegistry interface + * Note FactoryRegistry is not part of the OMG standard. It was added + * as part of the TAO implementation of Fault Tolerant CORBA + */ + 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> */ + 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; + + ////////////////////// + // non-CORBA interface + public: + /// Constructor + PG_FactoryRegistry (const char * name = "FactoryRegistry"); + + /// virtual Destructor + virtual ~PG_FactoryRegistry (void); + + /** + * Parse command line arguments. + * @param argc traditional C argc + * @param argv traditional C argv + * @return zero for success; nonzero is process return code for failure. + */ + int parse_args (int argc, char * argv[]); + + /** + * Initialize this object. + * @param orbManager our ORB -- we keep var to it. + * @return zero for success; nonzero is process return code for failure. + */ + int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); + + /** + * Prepare to exit. + * @return zero for success; nonzero is process return code for failure. + */ + int fini (ACE_ENV_SINGLE_ARG_DECL); + + /** + * Processing to happen when the ORB's event loop is idle. + * @param result is a place to return status to be returned by the process + * @returns 0 to continue. 1 to quit. + */ + int idle(int & result); + + /** + * Identify this object. + * @return a string to identify this object for logging/console message purposes. + */ + const char * identity () const; + + /** + * An object reference to the this object. + * Duplicated by the call so it may (and probably should) be assigned to a _var.. + */ + ::PortableGroup::FactoryRegistry_ptr reference(); + + //////////////////////////////// + // override servant base methods + virtual void _remove_ref (ACE_ENV_SINGLE_ARG_DECL); + + ////////////////// + // CORBA interface + // See IDL for documentation + + virtual void register_factory ( + const char * type_id, + const PortableGroup::FactoryInfo & factory_info + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberAlreadyPresent)); + + virtual void unregister_factory ( + const char * type_id, + 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_location ( + const PortableGroup::Location & location + ACE_ENV_ARG_DECL + ) + 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_location ( + const PortableGroup::Location & location + ACE_ENV_ARG_DECL + ) + ACE_THROW_SPEC ((CORBA::SystemException)); + + ///////////////////////// + // Implementation methods + private: + /** + * Write this factory's IOR to a file + */ + int write_ior_file (const char * outputFile, const char * ior); + + /////////////// + // Data Members + private: + + /** + * A human-readable string to distinguish this from other Notifiers. + */ + ACE_CString identity_; + + /** + * Protect internal state. + * Mutex should be locked by corba methods, or by + * external (public) methods before calling implementation + * methods. + * Implementation methods should assume the mutex is + * locked if necessary. + */ + ACE_Mutex internals_; + typedef ACE_Guard<ACE_Mutex> InternalGuard; + + /** + * The orb + */ + CORBA::ORB_var orb_; + + /** + * The POA used to activate this object. + */ + PortableServer::POA_var poa_; + + /** + * The CORBA object id assigned to this object. + */ + PortableServer::ObjectId_var object_id_; + + /** + * This objects identity as a CORBA object. + */ + CORBA::Object_var this_obj_; + + /** + * IOR of this object as assigned by poa. + */ + CORBA::String_var ior_; + + /** + * A file to which the factory's IOR should be written. + */ + const char * ior_output_file_; + + /** + * A name to be used to register the factory with the name service. + */ + const char * ns_name_; + + CosNaming::NamingContext_var naming_context_; + + CosNaming::Name this_name_; + + /** + * Quit on idle flag. + */ + int quit_on_idle_; + + /** + * State of the quit process + */ + enum {LIVE, DEACTIVATED, GONE} quit_state_; + + int linger_; + + RegistryType registry_; + + }; +} // namespace TAO + +#include /**/ <ace/post.h> + +#endif // TAO_PG_FACTORYREGISTRY_H_ diff --git a/TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp b/TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp index 846f4393201..66936d543cf 100644 --- a/TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp +++ b/TAO/orbsvcs/tests/FT_App/FTAPP_FactoryRegistry_Main.cpp @@ -13,11 +13,11 @@ //============================================================================= #include <tao/Utils/Server_Main.h> -#include "FactoryRegistry_i.h" +#include "orbsvcs/PortableGroup/PG_FactoryRegistry.h" int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { - TAO::Utils::Server_Main<FactoryRegistry_i> server_main("FactoryRegistry"); + TAO::Utils::Server_Main<TAO::PG_FactoryRegistry> server_main("FactoryRegistry"); return server_main.run(argc, argv); } diff --git a/TAO/orbsvcs/tests/FT_App/FT_App.mpc b/TAO/orbsvcs/tests/FT_App/FT_App.mpc index 8cd26b7b3fd..ef4230d9be0 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_App.mpc +++ b/TAO/orbsvcs/tests/FT_App/FT_App.mpc @@ -105,7 +105,6 @@ project(*FactoryRegistry): taoclient, fault_tolerance, orbsvcsexe { Source_Files { FTAPP_FactoryRegistry_Main.cpp - FactoryRegistry_i.cpp } // explicitly omit IDL files @@ -129,5 +128,6 @@ project(*Creator): taoclient, fault_tolerance, orbsvcsexe { Documentation_Files { // pretend the pl file is documentation for now run_test_registry.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 9f35d104f4a..f405396da05 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.cpp @@ -60,6 +60,8 @@ FT_ReplicaFactory_i::FT_ReplicaFactory_i () , test_output_file_(0) , empty_slots_(0) , quit_requested_(0) + , have_replication_manager_(0) + , replication_manager_(0) { } @@ -377,63 +379,113 @@ int FT_ReplicaFactory_i::init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL) ACE_ENV_ARG_PARAMETER); ACE_TRY_CHECK; - - if (factory_registry_ior_ != 0) + 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(factory_registry_)) + 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) + { + /////////////////////////////// + // Find the ReplicationManager + ACE_TRY_NEW_ENV { - ::PortableGroup::GenericFactory_var this_var = ::PortableGroup::GenericFactory::_narrow(this_obj); - if (! CORBA::is_nil(this_var)) +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_)) { - - size_t typeCount = types_.size(); - for (size_t nType = 0; nType < typeCount; ++nType) +ACE_ERROR ((LM_DEBUG, "Found a _real_ ReplicationManager. Ask it for a factory registry.\n")); + have_replication_manager_ = 1; + // empty criteria + ::PortableGroup::Criteria criteria; + this->factory_registry_ = this->replication_manager_->get_factory_registry(criteria ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (CORBA::is_nil (this->factory_registry_)) { - 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; + result = -1; + ACE_ERROR ((LM_ERROR,"ReplicaFactory: ReplicationManager failed to return FactoryRegistry.\n" )); } - this->registered_ = 1; } else { - ACE_ERROR (( LM_ERROR, - "Unexpected error: object reference should be a ReplicaFactory?\n" +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 + } + else + { + ACE_ERROR ((LM_ERROR,"ReplicaFactory: Can't resolve ReplicationManager, and no -f option was given.\n" )); + } + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "ReplicaFactory: Exception resolving ReplicationManager, and no -f option was given.\n" ); + result = 1; + } + ACE_ENDTRY; + + } + + if ( ! CORBA::is_nil (this->factory_registry_)) + { + ::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) + { + 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_ )); + + this->factory_registry_->register_factory( + typeId, + info + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; } + this->registered_ = 1; } else { ACE_ERROR (( LM_ERROR, - "Can't resolve Factory Registry IOR %s\n", - this->factory_registry_ior_ + "Unexpected error: object reference should be a ReplicaFactory?\n" )); - result = -1; } } + int identified = 0; // bool if (this->types_.size() > 0) diff --git a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h index d3cabb80674..259089da68b 100644 --- a/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h +++ b/TAO/orbsvcs/tests/FT_App/FT_ReplicaFactory_i.h @@ -30,6 +30,7 @@ class FT_ReplicaFactory_i; #include <ace/Vector_T.h> #include "FT_TestReplicaS.h" #include <ace/Thread_Manager.h> +#include <orbsvcs/FT_ReplicationManagerC.h> ///////////////////// // Forward references @@ -208,6 +209,19 @@ private: */ const char * ior_output_file_; + + /** + * bool: true if we found a replication manager + */ + int have_replication_manager_; + + /** + * The replication manager (if any + */ + + ::FT::ReplicationManager_var replication_manager_; + + /** * The factory registry IOR */ diff --git a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h b/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h deleted file mode 100644 index 0b6be66828b..00000000000 --- a/TAO/orbsvcs/tests/FT_App/FactoryRegistry_i.h +++ /dev/null @@ -1,219 +0,0 @@ -// -*- C++ -*- -//============================================================================= -/** - * @file FactoryRegistry_i.h - * - * $Id$ - * - * This file declares the implementation of PortableGroup::FactoryRegistry. - * Eventually this should be folded into the Fault Tolerance ReplicationManager - * - * @author Dale Wilson <wilson_d@ociweb.com> - */ -//============================================================================= - -#ifndef FACTORYREGISTRY_I_H_ -#define FACTORYREGISTRY_I_H_ - -#include <orbsvcs/PortableGroupS.h> -#include <ace/Hash_Map_Manager.h> - -#if !defined (ACE_LACKS_PRAGMA_ONCE) -#pragma once -#endif /* ACE_LACKS_PRAGMA_ONCE */ - -////////////////////////////////// -// Classes declared in this header -class FactoryRegistry_i; - -///////////////////////////////// -// Includes needed by this header - -///////////////////// -// Forward references -class TAO_ORB_Manager; - -/** - * Implement the PortableGroup::FactoryRegistry interface - * Note FactoryRegistry is not part of the OMG standard. It was added - * as part of the TAO implementation of Fault Tolerant Corba - */ -class FactoryRegistry_i : public virtual POA_PortableGroup::FactoryRegistry -{ - /* <DESIGN> originally I used FactoryInfos_vars rather than FactoryInfos *, - but it actually made memory management harder. DLW </DESIGN> */ - 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; - - ////////////////////// - // non-CORBA interface -public: - /// Constructor - FactoryRegistry_i (void); - - /// virtual Destructor - virtual ~FactoryRegistry_i (void); - - /** - * Parse command line arguments. - * @param argc traditional C argc - * @param argv traditional C argv - * @return zero for success; nonzero is process return code for failure. - */ - int parse_args (int argc, char * argv[]); - - /** - * Initialize this object. - * @param orbManager our ORB -- we keep var to it. - * @return zero for success; nonzero is process return code for failure. - */ - int init (CORBA::ORB_var & orb ACE_ENV_ARG_DECL); - - /** - * Prepare to exit. - * @return zero for success; nonzero is process return code for failure. - */ - int fini (ACE_ENV_SINGLE_ARG_DECL); - - /** - * Processing to happen when the ORB's event loop is idle. - * @param result is a place to return status to be returned by the process - * @returns 0 to continue. 1 to quit. - */ - int idle(int & result); - - /** - * Identify this object. - * @return a string to identify this object for logging/console message purposes. - */ - const char * identity () const; - - //////////////////////////////// - // override servant base methods - virtual void _remove_ref (ACE_ENV_SINGLE_ARG_DECL); - - ////////////////// - // CORBA interface - // See IDL for documentation - - virtual void register_factory ( - const char * type_id, - const PortableGroup::FactoryInfo & factory_info - ACE_ENV_ARG_DECL - ) - ACE_THROW_SPEC ((CORBA::SystemException, PortableGroup::MemberAlreadyPresent)); - - virtual void unregister_factory ( - const char * type_id, - 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_location ( - const PortableGroup::Location & location - ACE_ENV_ARG_DECL - ) - 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_location ( - const PortableGroup::Location & location - ACE_ENV_ARG_DECL - ) - ACE_THROW_SPEC ((CORBA::SystemException)); - - ///////////////////////// - // Implementation methods -private: - /** - * Write this factory's IOR to a file - */ - int write_ior_file (const char * outputFile, const char * ior); - - /////////////// - // Data Members -private: - - /** - * A human-readable string to distinguish this from other Notifiers. - */ - ACE_CString identity_; - - /** - * Protect internal state. - * Mutex should be locked by corba methods, or by - * external (public) methods before calling implementation - * methods. - * Implementation methods should assume the mutex is - * locked if necessary. - */ - ACE_Mutex internals_; - typedef ACE_Guard<ACE_Mutex> InternalGuard; - - /** - * The orb - */ - CORBA::ORB_var orb_; - - /** - * The POA used to activate this object. - */ - PortableServer::POA_var poa_; - - /** - * The CORBA object id assigned to this object. - */ - PortableServer::ObjectId_var object_id_; - - - /** - * IOR of this object as assigned by poa. - */ - CORBA::String_var ior_; - - /** - * A file to which the factory's IOR should be written. - */ - const char * ior_output_file_; - - /** - * A name to be used to register the factory with the name service. - */ - const char * ns_name_; - - CosNaming::NamingContext_var naming_context_; - - CosNaming::Name this_name_; - - /** - * Quit on idle flag. - */ - int quit_on_idle_; - - /** - * State of the quit process - */ - enum {LIVE, DEACTIVATED, GONE} quit_state_; - - int linger_; - - RegistryType registry_; - -}; - - -#endif /* __FACTORYREGISTRY_I_H_ */ 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 2fc40b6d43c..9611bc0c914 100644 --- a/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp +++ b/TAO/orbsvcs/tests/FT_App/TAO_Object_Group_Creator.cpp @@ -171,7 +171,9 @@ std::cout << "Found a FactoryRegistry DBA ReplicationManager" << std::endl; } ACE_CATCHANY { - std::cerr << "Creator: Exception resolving ReplicationManager, and no -f option was given." << std::endl; + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Creator: Exception resolving ReplicationManager, and no -f option was given.\n"); + result = 1; } ACE_ENDTRY; @@ -228,7 +230,7 @@ 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 (this->have_replication_manager_) + if (0 && this->have_replication_manager_) { PortableGroup::Criteria criteria; iogr = this->replication_manager_->create_object( @@ -299,7 +301,7 @@ int TAO::Object_Group_Creator::create_group(const char * type ACE_ENV_ARG_DECL) std::cerr << "Creator: Error writing ior [" << replica_ior << "] to " << replica_ior_filename << std::endl; } - if (this->have_replication_manager_) + if (0 && this->have_replication_manager_) { iogr = this->replication_manager_->add_member (iogr, info.the_location, @@ -321,7 +323,7 @@ int TAO::Object_Group_Creator::create_group(const char * type ACE_ENV_ARG_DECL) std::cout << "Creator: Successfully created group of " << type << std::endl; - if( have_replication_manager_) + if(0 && have_replication_manager_) { const char * replica_iogr = orb_->object_to_string (iogr ACE_ENV_ARG_PARAMETER ); ACE_CHECK; |