Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / orbsvcs / FT_ReplicationManager / FT_ReplicationManager.cpp
blobc9f53833ab4f7247e291e8134787c0c8905f0142
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file FT_ReplicationManager.cpp
6 * This file is part of Fault Tolerant CORBA.
7 * This file implements the FT_ReplicationManager class as declared in
8 * FT_Replication_Manager.h.
10 * @author Curt Hibbs <hibbs_c@ociweb.com>
12 //=============================================================================
13 #include "orbsvcs/Log_Macros.h"
14 #include "FT_ReplicationManager.h"
15 #include "FT_Property_Validator.h"
17 #include "ace/Get_Opt.h"
18 #include "ace/OS_NS_stdio.h"
19 #include "ace/OS_NS_unistd.h"
20 #include "tao/Messaging/Messaging.h"
21 #include "tao/IORTable/IORTable.h"
22 #include "tao/debug.h"
23 #include "tao/ORB_Constants.h"
24 #include "orbsvcs/PortableGroup/PG_Object_Group.h"
25 #include "orbsvcs/PortableGroup/PG_Property_Set.h"
26 #include "orbsvcs/PortableGroup/PG_Properties_Encoder.h"
27 #include "orbsvcs/PortableGroup/PG_Property_Utils.h"
28 #include "orbsvcs/PortableGroup/PG_conf.h"
30 #include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
31 #include "orbsvcs/FT_ReplicationManager/FT_ReplicationManagerFaultAnalyzer.h"
33 // Use this macro at the beginning of CORBA methods
34 // to aid in debugging.
35 #define METHOD_ENTRY(name) \
36 if (TAO_debug_level > 6) \
37 { \
38 ORBSVCS_DEBUG (( LM_DEBUG, \
39 "Enter %s\n", #name \
40 )); \
43 // Use this macro to return from CORBA methods
44 // to aid in debugging. Note that you can specify
45 // the return value after the macro, for example:
46 // METHOD_RETURN(Plugh::plover) xyzzy; is equivalent
47 // to return xyzzy;
48 // METHOD_RETURN(Plugh::troll); is equivalent to
49 // return;
50 // WARNING: THIS GENERATES TWO STATEMENTS!!! THE FOLLOWING
51 // will not do what you want it to:
52 // if (cave_is_closing) METHOD_RETURN(Plugh::pirate) aarrggh;
53 // Moral: Always use braces.
54 #define METHOD_RETURN(name) \
55 if (TAO_debug_level > 6) \
56 { \
57 ORBSVCS_DEBUG (( LM_DEBUG, \
58 "Leave %s\n", #name \
59 )); \
60 } \
61 return /* value goes here */
63 #define TODO
64 //#define TODO int todo; // warn on todos
66 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
68 TAO::FT_ReplicationManager::FT_ReplicationManager ()
69 : orb_ (CORBA::ORB::_nil ())
70 , poa_ (PortableServer::POA::_nil ())
71 , ior_output_file_ (0)
72 , ns_name_ ("")
73 , naming_context_ (CosNaming::NamingContext::_nil ())
74 , replication_manager_ref_ (FT::ReplicationManager::_nil ())
75 , fault_notifier_ (FT::FaultNotifier::_nil ())
76 , fault_notifier_ior_string_ (0)
77 , fault_consumer_ ()
78 , factory_registry_ ("ReplicationManager::FactoryRegistry")
79 , quit_ (0)
81 // init must be called before using this object.
84 TAO::FT_ReplicationManager::~FT_ReplicationManager ()
86 // cleanup happens in fini
89 //public
90 int TAO::FT_ReplicationManager::parse_args (int argc, ACE_TCHAR * argv[])
92 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("n:o:f:"));
93 int c;
95 while ( (c = get_opts ()) != -1)
97 switch (c)
99 case 'o':
100 this->ior_output_file_ = get_opts.opt_arg ();
101 break;
103 case 'n':
104 this->ns_name_ = ACE_TEXT_ALWAYS_CHAR(get_opts.opt_arg ());
105 break;
107 case 'f':
108 this->fault_notifier_ior_string_ = get_opts.opt_arg ();
109 break;
111 case '?':
112 // fall thru
113 default:
114 ORBSVCS_ERROR_RETURN ( (LM_ERROR,
115 ACE_TEXT ("%T %n (%P|%t) - usage: %s")
116 ACE_TEXT (" -o <iorfile (for testing)>")
117 ACE_TEXT (" -f <fault notifier IOR (for testing)>")
118 ACE_TEXT (" -n <name-to-bind-in-NameService (for testing)>")
119 ACE_TEXT ("\n"),
120 argv [0]),
121 -1);
122 break;
125 // Indicates successful parsing of the command line
126 return 0;
129 //public
130 const char * TAO::FT_ReplicationManager::identity () const
132 return this->identity_.c_str ();
135 //public
136 int TAO::FT_ReplicationManager::init (CORBA::ORB_ptr orb)
138 int result = 0;
140 if (TAO_debug_level > 1)
142 ORBSVCS_DEBUG ( (LM_DEBUG,
143 ACE_TEXT (
144 "%T %n (%P|%t) - Enter TAO::FT_ReplicationManager::init.\n")
149 this->orb_ = CORBA::ORB::_duplicate (orb);
151 // Get the RootPOA.
152 CORBA::Object_var poa_obj = this->orb_->resolve_initial_references (
153 TAO_OBJID_ROOTPOA);
154 this->poa_ = PortableServer::POA::_narrow (
155 poa_obj.in ());
158 // initialize the FactoryRegistry
159 this->factory_registry_.init (this->orb_.in (), this->poa_.in ());
161 PortableGroup::FactoryRegistry_var factory_registry = this->factory_registry_.reference ();
163 // @@: do we want to use the same poa to create object groups?
164 this->group_factory_.init (
165 this->orb_.in (),
166 this->poa_.in (),
167 factory_registry.in ());
169 // Activate ourself in the POA.
170 PortableServer::ObjectId_var oid = this->poa_->activate_object (
171 this);
173 CORBA::Object_var this_obj = this->poa_->id_to_reference (
174 oid.in ());
175 this->replication_manager_ref_ = FT::ReplicationManager::_narrow (
176 this_obj.in ());
178 // If we were given an initial IOR string for a Fault Notifier on the
179 // command line, convert it to an IOR, then register the fault
180 // notifier.
181 if (this->fault_notifier_ior_string_ != 0)
183 CORBA::Object_var notifier_obj = this->orb_->string_to_object (
184 this->fault_notifier_ior_string_);
185 FT::FaultNotifier_var notifier = FT::FaultNotifier::_narrow (
186 notifier_obj.in ());
187 if (! CORBA::is_nil (notifier.in ()))
189 this->register_fault_notifier_i (notifier.in ());
191 else
193 ORBSVCS_ERROR_RETURN ( (LM_ERROR,
194 ACE_TEXT (
195 "%T %n (%P|%t) - Could not resolve notifier IOR.\n")),
196 -1);
200 // Activate the RootPOA.
201 PortableServer::POAManager_var poa_mgr =
202 this->poa_->the_POAManager ();
203 poa_mgr->activate ();
205 // Register our IOR in the IORTable with the key-string
206 // "ReplicationManager".
207 CORBA::Object_var ior_table_obj =
208 this->orb_->resolve_initial_references (
209 TAO_OBJID_IORTABLE);
211 IORTable::Table_var ior_table =
212 IORTable::Table::_narrow (ior_table_obj.in ());
213 if (CORBA::is_nil (ior_table.in ()))
215 ORBSVCS_ERROR_RETURN ( (LM_ERROR,
216 ACE_TEXT ("%T %n (%P|%t) - Unable to resolve the IORTable.\n")),
217 -1);
219 else
221 CORBA::String_var rm_ior_str = this->orb_->object_to_string (
222 this->replication_manager_ref_.in ());
223 ior_table->bind ("ReplicationManager", rm_ior_str.in ());
226 // Publish our IOR, either to a file or the Naming Service.
227 if (this->ior_output_file_ != 0)
229 this->identity_ = "file:";
230 this->identity_ += ACE_TEXT_ALWAYS_CHAR(this->ior_output_file_);
231 result = this->write_ior ();
234 if (result == 0 && this->ns_name_.length () != 0)
236 this->identity_ = "name:";
237 this->identity_ += this->ns_name_;
239 CORBA::Object_var naming_obj = this->orb_->resolve_initial_references (
240 TAO_OBJID_NAMESERVICE);
242 this->naming_context_ =
243 CosNaming::NamingContext::_narrow (
244 naming_obj.in ());
246 if (CORBA::is_nil (this->naming_context_.in ()))
248 ORBSVCS_ERROR_RETURN ( (LM_ERROR,
249 ACE_TEXT ("%T %n (%P|%t) - Unable to find the Naming Service.\n")),
250 -1);
253 this->this_name_.length (1);
254 this->this_name_[0].id = CORBA::string_dup (this->ns_name_.c_str ());
256 this->naming_context_->rebind (
257 this->this_name_,
258 this->replication_manager_ref_.in ());
261 if (TAO_debug_level > 1)
263 if (result == 0)
265 ORBSVCS_DEBUG ( (LM_DEBUG,
266 ACE_TEXT (
267 "%T %n (%P|%t) - Leave TAO::FT_ReplicationManager::init.\n")
270 else
272 ORBSVCS_DEBUG ( (LM_DEBUG,
273 ACE_TEXT (
274 "%T %n (%P|%t) - FT_ReplicationManager::init failed.\n")
279 ////////////////////////////////
280 // Initialize default properties
281 PortableGroup::Value value;
282 value <<= TAO_PG_MEMBERSHIP_STYLE;
283 this->properties_support_.set_default_property (PortableGroup::PG_MEMBERSHIP_STYLE, value);
285 value <<= TAO_PG_INITIAL_NUMBER_MEMBERS;
286 this->properties_support_.set_default_property (PortableGroup::PG_INITIAL_NUMBER_MEMBERS, value);
288 value <<= TAO_PG_MINIMUM_NUMBER_MEMBERS;
289 this->properties_support_.set_default_property (PortableGroup::PG_MINIMUM_NUMBER_MEMBERS, value);
291 value <<= FT::SEMI_ACTIVE;
292 this->properties_support_.set_default_property (FT::FT_REPLICATION_STYLE, value);
294 value <<= FT::CONS_APP_CTRL;
295 this->properties_support_.set_default_property ( FT::FT_CONSISTENCY_STYLE, value);
297 value <<= FT::PULL;
298 this->properties_support_.set_default_property (FT::FT_FAULT_MONITORING_STYLE, value);
300 value <<= FT::MEMB;
301 this->properties_support_.set_default_property (FT::FT_FAULT_MONITORING_GRANULARITY, value);
303 #if 0
304 FaultMonitoringIntervalAndTimeoutValue times;
305 value <<= times;
306 this->properties_support_.set_default_property (FT::FT_FAULT_MONITORING_INTERVAL_AND_TIMEOUT, value);
307 #endif
309 #if 0
310 value << interval;
311 this->properties_support_.set_default_property (FT::FT_CHECKPOINT_INTERVAL, value);
312 #endif
315 return result;
318 //public
319 int TAO::FT_ReplicationManager::idle (int & result)
321 ACE_UNUSED_ARG (result);
322 return this->quit_;
326 //public
327 int TAO::FT_ReplicationManager::fini ()
329 int result = 0;
331 result = this->fault_consumer_.fini ();
333 if (this->ior_output_file_ != 0)
335 ACE_OS::unlink (this->ior_output_file_);
336 this->ior_output_file_ = 0;
338 if (this->ns_name_.length () != 0)
340 this->naming_context_->unbind (this->this_name_);
341 this->ns_name_.clear ();
344 return result;
347 //CORBA
348 void
349 TAO::FT_ReplicationManager::register_fault_notifier (
350 FT::FaultNotifier_ptr fault_notifier)
352 this->register_fault_notifier_i (fault_notifier);
355 //private
356 void
357 TAO::FT_ReplicationManager::register_fault_notifier_i (
358 FT::FaultNotifier_ptr fault_notifier)
360 if (CORBA::is_nil (fault_notifier))
362 ORBSVCS_ERROR ( (LM_ERROR,
363 ACE_TEXT (
364 "%T %n (%P|%t) - Bad Fault Notifier object reference provided.\n")
366 throw CORBA::BAD_PARAM (
367 CORBA::SystemException::_tao_minor_code (
368 TAO::VMCID,
369 EINVAL),
370 CORBA::COMPLETED_NO);
373 // Cache new Fault Notifier object reference.
374 this->fault_notifier_ = FT::FaultNotifier::_duplicate (fault_notifier);
376 // Re-initialize our consumer.
377 // Swallow any exception.
378 int result = 0;
381 //@@ should we check to see if a notifier is already registered, rather than
382 // simply "unregistering"?
383 result = this->fault_consumer_.fini ();
385 // Note if the fini failed, we ignore it. It may not have been registered
386 // in the first place.
388 // Create a fault analyzer.
389 TAO::FT_FaultAnalyzer * analyzer = 0;
390 ACE_NEW_NORETURN (
391 analyzer,
392 TAO::FT_ReplicationManagerFaultAnalyzer (this));
393 if (analyzer == 0)
395 ORBSVCS_ERROR ( (LM_ERROR,
396 ACE_TEXT (
397 "%T %n (%P|%t) - Error creating FaultAnalyzer.\n"
400 result = -1;
402 if (result == 0)
404 result = this->fault_consumer_.init (
405 this->poa_.in (),
406 this->fault_notifier_.in (),
407 analyzer);
410 catch (const CORBA::Exception& ex)
412 ex._tao_print_exception (
413 ACE_TEXT ("TAO::FT_ReplicationManager::register_fault_notifier_i: ")
414 ACE_TEXT ("Error reinitializing FT_FaultConsumer.\n"));
415 result = -1;
418 if (result != 0)
420 ORBSVCS_ERROR ( (LM_ERROR,
421 ACE_TEXT (
422 "%T %n (%P|%t) - Could not re-initialize FT_FaultConsumer.\n")
425 throw CORBA::INTERNAL (
426 CORBA::SystemException::_tao_minor_code (
427 TAO::VMCID,
428 EINVAL),
429 CORBA::COMPLETED_NO);
434 // Returns the reference of the Fault Notifier.
435 //CORBA
436 FT::FaultNotifier_ptr
437 TAO::FT_ReplicationManager::get_fault_notifier ()
439 if (CORBA::is_nil (this->fault_notifier_.in ()))
441 throw FT::InterfaceNotFound ();
443 return FT::FaultNotifier::_duplicate (this->fault_notifier_.in ());
447 // TAO-specific find factory registry
448 //CORBA
449 ::PortableGroup::FactoryRegistry_ptr
450 TAO::FT_ReplicationManager::get_factory_registry (
451 const PortableGroup::Criteria & selection_criteria)
453 ACE_UNUSED_ARG (selection_criteria);
454 return this->factory_registry_.reference ();
457 // TAO-specific shutdown operation.
458 //public
459 void TAO::FT_ReplicationManager::shutdown ()
461 this->quit_ = 1;
464 // Get the type_id associated with an object group.
465 //CORBA
466 char * TAO::FT_ReplicationManager::type_id (
467 PortableGroup::ObjectGroup_ptr object_group)
469 char * result = 0;
470 TAO::PG_Object_Group * group = 0;
471 if (this->group_factory_.find_group (object_group, group))
473 result = group->get_type_id ();
475 else
477 throw PortableGroup::ObjectGroupNotFound ();
479 return result;
482 //////////////////////////////////////////////////////
483 // PortableGroup::PropertyManager methods
485 //CORBA
486 void
487 TAO::FT_ReplicationManager::set_default_properties (
488 const PortableGroup::Properties & props)
490 this->properties_support_.set_default_properties (props);
491 //@@ validate properties?
494 //CORBA
495 PortableGroup::Properties *
496 TAO::FT_ReplicationManager::get_default_properties ()
498 return this->properties_support_.get_default_properties ();
501 //CORBA
502 void
503 TAO::FT_ReplicationManager::remove_default_properties (
504 const PortableGroup::Properties & props)
506 this->properties_support_.remove_default_properties (props);
509 //CORBA
510 void
511 TAO::FT_ReplicationManager::set_type_properties (
512 const char *type_id,
513 const PortableGroup::Properties & overrides)
515 this->properties_support_.set_type_properties (
516 type_id,
517 overrides);
520 //CORBA
521 PortableGroup::Properties *
522 TAO::FT_ReplicationManager::get_type_properties (
523 const char *type_id)
525 return this->properties_support_.get_type_properties (type_id);
528 //CORBA
529 void
530 TAO::FT_ReplicationManager::remove_type_properties (
531 const char *type_id,
532 const PortableGroup::Properties & props)
534 this->properties_support_.remove_type_properties (
535 type_id,
536 props);
539 //CORBA
540 void
541 TAO::FT_ReplicationManager::set_properties_dynamically (
542 PortableGroup::ObjectGroup_ptr object_group,
543 const PortableGroup::Properties & overrides)
545 TAO::PG_Object_Group * group = 0;
546 if (this->group_factory_.find_group (object_group, group))
548 group->set_properties_dynamically (overrides);
550 else
552 throw PortableGroup::ObjectGroupNotFound ();
556 //CORBA
557 PortableGroup::Properties *
558 TAO::FT_ReplicationManager::get_properties (
559 PortableGroup::ObjectGroup_ptr object_group)
561 PortableGroup::Properties_var result;
562 ACE_NEW_THROW_EX (result, PortableGroup::Properties(), CORBA::NO_MEMORY ());
564 TAO::PG_Object_Group * group = 0;
565 if (this->group_factory_.find_group (object_group, group))
567 group->get_properties (result);
569 else
571 throw PortableGroup::ObjectGroupNotFound ();
573 return result._retn();
577 //////////////////////////////////////////////////////
578 // FT::FTObjectGroupManager methods
580 /// Sets the primary member of a group.
581 //CORBA
582 PortableGroup::ObjectGroup_ptr
583 TAO::FT_ReplicationManager::set_primary_member (
584 PortableGroup::ObjectGroup_ptr object_group,
585 const PortableGroup::Location & the_location)
587 METHOD_ENTRY (TAO::FT_ReplicationManager::set_primary_member);
588 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil();
589 TAO::PG_Object_Group * group = 0;
590 if (this->group_factory_.find_group (object_group, group))
592 PortableGroup::TagGroupTaggedComponent tag_component;
593 TAO_FT_IOGR_Property prop (tag_component);
595 int sts = group->set_primary_member (&prop, the_location);
596 if (sts)
598 result = group->reference ();
600 else
602 throw FT::PrimaryNotSet ();
605 else
607 throw PortableGroup::ObjectGroupNotFound ();
609 METHOD_RETURN (TAO::FT_ReplicationManager::set_primary_member) result._retn ();
612 //CORBA
613 PortableGroup::ObjectGroup_ptr
614 TAO::FT_ReplicationManager::create_member (
615 PortableGroup::ObjectGroup_ptr object_group,
616 const PortableGroup::Location & the_location,
617 const char * type_id,
618 const PortableGroup::Criteria & the_criteria)
620 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil();
621 TAO::PG_Object_Group * group = 0;
622 if (this->group_factory_.find_group (object_group, group))
624 group->create_member (the_location, type_id, the_criteria);
625 result = group->reference ();
627 else
629 if (TAO_debug_level > 0)
631 ORBSVCS_ERROR ( (LM_ERROR,
632 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::create_member: unknown group\n")
635 throw PortableGroup::ObjectGroupNotFound ();
637 return result._retn();
641 //CORBA
642 PortableGroup::ObjectGroup_ptr
643 TAO::FT_ReplicationManager::add_member (
644 PortableGroup::ObjectGroup_ptr object_group,
645 const PortableGroup::Location & the_location,
646 CORBA::Object_ptr member)
648 METHOD_ENTRY (TAO::FT_ReplicationManager::add_member);
649 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();
651 // Find the object group corresponding to this IOGR
652 TAO::PG_Object_Group * group = 0;
653 if (this->group_factory_.find_group (object_group, group))
655 group->add_member (
656 the_location,
657 member);
659 result = group->reference ();
661 else
663 if (TAO_debug_level > 0)
665 ORBSVCS_ERROR ( (LM_ERROR,
666 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::add_member to unknown group\n")
669 throw PortableGroup::ObjectGroupNotFound ();
671 METHOD_RETURN (TAO::FT_ReplicationManager::add_member) result._retn ();
674 //CORBA
675 PortableGroup::ObjectGroup_ptr
676 TAO::FT_ReplicationManager::remove_member (
677 PortableGroup::ObjectGroup_ptr object_group,
678 const PortableGroup::Location & the_location)
680 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();
682 // Find the object group corresponding to this IOGR
683 TAO::PG_Object_Group * group = 0;
684 if (this->group_factory_.find_group (object_group, group))
686 group->remove_member (the_location);
688 group->minimum_populate ();
689 //@@ how about the case where the member was removed successfully,
690 // but for one reason or another we were unable to bring the group
691 // back up to minimum_number_of_replicas?
693 result = group->reference ();
695 else
697 throw PortableGroup::ObjectGroupNotFound ();
699 return result._retn ();
702 //CORBA
703 PortableGroup::Locations *
704 TAO::FT_ReplicationManager::locations_of_members (
705 PortableGroup::ObjectGroup_ptr object_group)
707 PortableGroup::Locations * result = 0;
709 // Find the object group corresponding to this IOGR
710 TAO::PG_Object_Group * group = 0;
711 if (this->group_factory_.find_group (object_group, group))
713 result = group->locations_of_members ();
715 else
717 if (TAO_debug_level > 0)
719 ORBSVCS_ERROR ( (LM_ERROR,
720 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::locations_of_members: unknown group\n")
723 throw PortableGroup::ObjectGroupNotFound ();
725 return result;
728 //CORBA
729 PortableGroup::ObjectGroups *
730 TAO::FT_ReplicationManager::groups_at_location (
731 const PortableGroup::Location & the_location)
733 return this->group_factory_.groups_at_location (the_location);
736 //CORBA
737 PortableGroup::ObjectGroupId
738 TAO::FT_ReplicationManager::get_object_group_id (
739 PortableGroup::ObjectGroup_ptr object_group)
741 PortableGroup::ObjectGroupId result = 0;
742 TAO::PG_Object_Group * group = 0;
743 if (this->group_factory_.find_group (object_group, group))
745 group->get_object_group_id ();
746 result = group->get_object_group_id ();
748 else
750 if (TAO_debug_level > 0)
752 ORBSVCS_ERROR ( (LM_ERROR,
753 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::get_object_group_id: unknown group\n")
756 throw PortableGroup::ObjectGroupNotFound ();
758 return result;
761 //CORBA
762 PortableGroup::ObjectGroup_ptr
763 TAO::FT_ReplicationManager::get_object_group_ref (
764 PortableGroup::ObjectGroup_ptr object_group)
766 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();
768 // Find the object group corresponding to this IOGR
769 TAO::PG_Object_Group * group = 0;
770 if (this->group_factory_.find_group (object_group, group))
772 result = group->reference ();
774 else
776 if (TAO_debug_level > 0)
778 ORBSVCS_ERROR ( (LM_ERROR,
779 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::get_object_group_ref: unknown group\n")
782 throw PortableGroup::ObjectGroupNotFound ();
784 return result._retn();
787 //CORBA, TAO specific
788 PortableGroup::ObjectGroup_ptr
789 TAO::FT_ReplicationManager::get_object_group_ref_from_id (
790 PortableGroup::ObjectGroupId group_id)
792 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();
794 // Find the object group corresponding to this IOGR
795 TAO::PG_Object_Group * group = 0;
796 if (this->group_factory_.find_group (group_id, group))
798 result = group->reference ();
800 else
802 if (TAO_debug_level > 0)
804 ORBSVCS_ERROR ( (LM_ERROR,
805 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::get_object_group_ref_from_id: unknown group\n")
808 throw PortableGroup::ObjectGroupNotFound ();
810 return result._retn();
813 //CORBA
814 CORBA::Object_ptr
815 TAO::FT_ReplicationManager::get_member_ref (
816 PortableGroup::ObjectGroup_ptr object_group,
817 const PortableGroup::Location & the_location)
819 CORBA::Object_var result = CORBA::Object::_nil();
821 // Find the object group corresponding to this IOGR
822 TAO::PG_Object_Group * group = 0;
823 if (this->group_factory_.find_group (object_group, group))
825 result = group->get_member_reference (the_location);
827 else
829 if (TAO_debug_level > 0)
831 ORBSVCS_ERROR ( (LM_ERROR,
832 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::get_member_ref: unknown group\n")
835 throw PortableGroup::ObjectGroupNotFound ();
837 return result._retn();
841 //////////////////////////////////////////////////////
842 // PortableGroup::GenericFactory methods
844 //CORBA
845 CORBA::Object_ptr
846 TAO::FT_ReplicationManager::create_object (
847 const char * type_id,
848 const PortableGroup::Criteria & the_criteria,
849 PortableGroup::GenericFactory::FactoryCreationId_out factory_creation_id)
851 METHOD_ENTRY (TAO::FT_ReplicationManager::create_object)
853 ////////////////////////////////
854 // find the properties for this
855 // type of object group
856 TAO::PG_Property_Set_var typeid_properties
857 = this->properties_support_.find_typeid_properties (
858 type_id);
860 TAO::PG_Object_Group * group
861 = this->group_factory_.create_group (
862 type_id,
863 the_criteria,
864 typeid_properties);
866 group->initial_populate ();
867 //@@ on error we should remove the group from the Group_Factory
868 // doing this "right" will require a var-type pointer to the object group
869 // that knows about the factory, too.
871 // Allocate a new FactoryCreationId for use as an "out" parameter.
872 PortableGroup::GenericFactory::FactoryCreationId_ptr factory_id_ptr = 0;
873 ACE_NEW_THROW_EX (factory_id_ptr,
874 PortableGroup::GenericFactory::FactoryCreationId,
875 CORBA::NO_MEMORY (
876 CORBA::SystemException::_tao_minor_code (
877 TAO::VMCID,
878 ENOMEM),
879 CORBA::COMPLETED_NO));
880 PortableGroup::GenericFactory::FactoryCreationId_var factory_id = factory_id_ptr;
881 PortableGroup::ObjectGroupId group_id = group->get_object_group_id ();
882 factory_id <<= group_id;
883 factory_creation_id = factory_id._retn();
885 METHOD_RETURN (TAO::FT_ReplicationManager::create_object) group->reference ();
888 //CORBA
889 void
890 TAO::FT_ReplicationManager::delete_object (
891 const PortableGroup::GenericFactory::FactoryCreationId & factory_creation_id)
893 PortableGroup::ObjectGroupId group_id = 0;
894 if (factory_creation_id >>= group_id)
896 this->group_factory_.delete_group (
897 group_id);
899 else
901 throw PortableGroup::ObjectNotFound ();
905 //private
906 int TAO::FT_ReplicationManager::write_ior ()
908 int result = -1;
909 FILE* out = ACE_OS::fopen (this->ior_output_file_, "w");
910 if (out)
912 CORBA::String_var ior_str = this->orb_->object_to_string (
913 this->replication_manager_ref_.in ());
914 ACE_OS::fprintf (out, "%s", ior_str.in ());
915 ACE_OS::fclose (out);
916 result = 0;
918 else
920 ORBSVCS_ERROR ( (LM_ERROR,
921 ACE_TEXT ("%T %n (%P|%t) - Open failed for %s\n"), this->ior_output_file_
924 return result;
927 TAO_END_VERSIONED_NAMESPACE_DECL