Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / FT_ReplicationManager / FT_ReplicationManager.cpp
blob270584224fd1293d60568cc5efdcd90d5f3673e9
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 (void)
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 (void)
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)
491 this->properties_support_.set_default_properties (props);
492 //@@ validate properties?
495 //CORBA
496 PortableGroup::Properties *
497 TAO::FT_ReplicationManager::get_default_properties ()
499 return this->properties_support_.get_default_properties ();
502 //CORBA
503 void
504 TAO::FT_ReplicationManager::remove_default_properties (
505 const PortableGroup::Properties & props)
507 this->properties_support_.remove_default_properties (props);
510 //CORBA
511 void
512 TAO::FT_ReplicationManager::set_type_properties (
513 const char *type_id,
514 const PortableGroup::Properties & overrides)
516 this->properties_support_.set_type_properties (
517 type_id,
518 overrides);
521 //CORBA
522 PortableGroup::Properties *
523 TAO::FT_ReplicationManager::get_type_properties (
524 const char *type_id)
526 return this->properties_support_.get_type_properties (type_id);
529 //CORBA
530 void
531 TAO::FT_ReplicationManager::remove_type_properties (
532 const char *type_id,
533 const PortableGroup::Properties & props)
535 this->properties_support_.remove_type_properties (
536 type_id,
537 props);
540 //CORBA
541 void
542 TAO::FT_ReplicationManager::set_properties_dynamically (
543 PortableGroup::ObjectGroup_ptr object_group,
544 const PortableGroup::Properties & overrides)
547 TAO::PG_Object_Group * group = 0;
548 if (this->group_factory_.find_group (object_group, group))
550 group->set_properties_dynamically (overrides);
552 else
554 throw PortableGroup::ObjectGroupNotFound ();
558 //CORBA
559 PortableGroup::Properties *
560 TAO::FT_ReplicationManager::get_properties (
561 PortableGroup::ObjectGroup_ptr object_group)
563 PortableGroup::Properties_var result;
564 ACE_NEW_THROW_EX (result, PortableGroup::Properties(), CORBA::NO_MEMORY ());
566 TAO::PG_Object_Group * group = 0;
567 if (this->group_factory_.find_group (object_group, group))
569 group->get_properties (result);
571 else
573 throw PortableGroup::ObjectGroupNotFound ();
575 return result._retn();
579 //////////////////////////////////////////////////////
580 // FT::FTObjectGroupManager methods
582 /// Sets the primary member of a group.
583 //CORBA
584 PortableGroup::ObjectGroup_ptr
585 TAO::FT_ReplicationManager::set_primary_member (
586 PortableGroup::ObjectGroup_ptr object_group,
587 const PortableGroup::Location & the_location)
589 METHOD_ENTRY (TAO::FT_ReplicationManager::set_primary_member);
590 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil();
591 TAO::PG_Object_Group * group = 0;
592 if (this->group_factory_.find_group (object_group, group))
595 PortableGroup::TagGroupTaggedComponent tag_component;
596 TAO_FT_IOGR_Property prop (tag_component);
598 int sts = group->set_primary_member (&prop, the_location);
599 if (sts)
601 result = group->reference ();
603 else
605 throw FT::PrimaryNotSet ();
608 else
610 throw PortableGroup::ObjectGroupNotFound ();
612 METHOD_RETURN (TAO::FT_ReplicationManager::set_primary_member) result._retn ();
615 //CORBA
616 PortableGroup::ObjectGroup_ptr
617 TAO::FT_ReplicationManager::create_member (
618 PortableGroup::ObjectGroup_ptr object_group,
619 const PortableGroup::Location & the_location,
620 const char * type_id,
621 const PortableGroup::Criteria & the_criteria)
623 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil();
624 TAO::PG_Object_Group * group = 0;
625 if (this->group_factory_.find_group (object_group, group))
627 group->create_member (the_location, type_id, the_criteria);
628 result = group->reference ();
630 else
632 if (TAO_debug_level > 0)
634 ORBSVCS_ERROR ( (LM_ERROR,
635 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::create_member: unknown group\n")
638 throw PortableGroup::ObjectGroupNotFound ();
640 return result._retn();
644 //CORBA
645 PortableGroup::ObjectGroup_ptr
646 TAO::FT_ReplicationManager::add_member (
647 PortableGroup::ObjectGroup_ptr object_group,
648 const PortableGroup::Location & the_location,
649 CORBA::Object_ptr member)
651 METHOD_ENTRY (TAO::FT_ReplicationManager::add_member);
652 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();
654 // Find the object group corresponding to this IOGR
655 TAO::PG_Object_Group * group = 0;
656 if (this->group_factory_.find_group (object_group, group))
658 group->add_member (
659 the_location,
660 member);
662 result = group->reference ();
665 else
667 if (TAO_debug_level > 0)
669 ORBSVCS_ERROR ( (LM_ERROR,
670 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::add_member to unknown group\n")
673 throw PortableGroup::ObjectGroupNotFound ();
675 METHOD_RETURN (TAO::FT_ReplicationManager::add_member) result._retn ();
678 //CORBA
679 PortableGroup::ObjectGroup_ptr
680 TAO::FT_ReplicationManager::remove_member (
681 PortableGroup::ObjectGroup_ptr object_group,
682 const PortableGroup::Location & the_location)
684 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();
686 // Find the object group corresponding to this IOGR
687 TAO::PG_Object_Group * group = 0;
688 if (this->group_factory_.find_group (object_group, group))
690 group->remove_member (the_location);
692 group->minimum_populate ();
693 //@@ how about the case where the member was removed successfully,
694 // but for one reason or another we were unable to bring the group
695 // back up to minimum_number_of_replicas?
697 result = group->reference ();
699 else
701 throw PortableGroup::ObjectGroupNotFound ();
703 return result._retn ();
706 //CORBA
707 PortableGroup::Locations *
708 TAO::FT_ReplicationManager::locations_of_members (
709 PortableGroup::ObjectGroup_ptr object_group)
711 PortableGroup::Locations * result = 0;
713 // Find the object group corresponding to this IOGR
714 TAO::PG_Object_Group * group = 0;
715 if (this->group_factory_.find_group (object_group, group))
717 result = group->locations_of_members ();
719 else
721 if (TAO_debug_level > 0)
723 ORBSVCS_ERROR ( (LM_ERROR,
724 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::locations_of_members: unknown group\n")
727 throw PortableGroup::ObjectGroupNotFound ();
729 return result;
732 //CORBA
733 PortableGroup::ObjectGroups *
734 TAO::FT_ReplicationManager::groups_at_location (
735 const PortableGroup::Location & the_location)
737 return this->group_factory_.groups_at_location (the_location);
740 //CORBA
741 PortableGroup::ObjectGroupId
742 TAO::FT_ReplicationManager::get_object_group_id (
743 PortableGroup::ObjectGroup_ptr object_group)
745 PortableGroup::ObjectGroupId result = 0;
746 TAO::PG_Object_Group * group = 0;
747 if (this->group_factory_.find_group (object_group, group))
749 group->get_object_group_id ();
750 result = group->get_object_group_id ();
752 else
754 if (TAO_debug_level > 0)
756 ORBSVCS_ERROR ( (LM_ERROR,
757 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::get_object_group_id: unknown group\n")
760 throw PortableGroup::ObjectGroupNotFound ();
762 return result;
765 //CORBA
766 PortableGroup::ObjectGroup_ptr
767 TAO::FT_ReplicationManager::get_object_group_ref (
768 PortableGroup::ObjectGroup_ptr object_group)
770 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();
772 // Find the object group corresponding to this IOGR
773 TAO::PG_Object_Group * group = 0;
774 if (this->group_factory_.find_group (object_group, group))
776 result = group->reference ();
778 else
780 if (TAO_debug_level > 0)
782 ORBSVCS_ERROR ( (LM_ERROR,
783 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::get_object_group_ref: unknown group\n")
786 throw PortableGroup::ObjectGroupNotFound ();
788 return result._retn();
791 //CORBA, TAO specific
792 PortableGroup::ObjectGroup_ptr
793 TAO::FT_ReplicationManager::get_object_group_ref_from_id (
794 PortableGroup::ObjectGroupId group_id)
796 PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();
798 // Find the object group corresponding to this IOGR
799 TAO::PG_Object_Group * group = 0;
800 if (this->group_factory_.find_group (group_id, group))
802 result = group->reference ();
804 else
806 if (TAO_debug_level > 0)
808 ORBSVCS_ERROR ( (LM_ERROR,
809 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::get_object_group_ref_from_id: unknown group\n")
812 throw PortableGroup::ObjectGroupNotFound ();
814 return result._retn();
817 //CORBA
818 CORBA::Object_ptr
819 TAO::FT_ReplicationManager::get_member_ref (
820 PortableGroup::ObjectGroup_ptr object_group,
821 const PortableGroup::Location & the_location)
823 CORBA::Object_var result = CORBA::Object::_nil();
825 // Find the object group corresponding to this IOGR
826 TAO::PG_Object_Group * group = 0;
827 if (this->group_factory_.find_group (object_group, group))
829 result = group->get_member_reference (the_location);
831 else
833 if (TAO_debug_level > 0)
835 ORBSVCS_ERROR ( (LM_ERROR,
836 ACE_TEXT ("%T %n (%P|%t) - FT_ReplicationManager::get_member_ref: unknown group\n")
839 throw PortableGroup::ObjectGroupNotFound ();
841 return result._retn();
845 //////////////////////////////////////////////////////
846 // PortableGroup::GenericFactory methods
848 //CORBA
849 CORBA::Object_ptr
850 TAO::FT_ReplicationManager::create_object (
851 const char * type_id,
852 const PortableGroup::Criteria & the_criteria,
853 PortableGroup::GenericFactory::FactoryCreationId_out factory_creation_id)
855 METHOD_ENTRY (TAO::FT_ReplicationManager::create_object)
857 ////////////////////////////////
858 // find the properties for this
859 // type of object group
860 TAO::PG_Property_Set_var typeid_properties
861 = this->properties_support_.find_typeid_properties (
862 type_id);
864 TAO::PG_Object_Group * group
865 = this->group_factory_.create_group (
866 type_id,
867 the_criteria,
868 typeid_properties);
870 group->initial_populate ();
871 //@@ on error we should remove the group from the Group_Factory
872 // doing this "right" will require a var-type pointer to the object group
873 // that knows about the factory, too.
875 // Allocate a new FactoryCreationId for use as an "out" parameter.
876 PortableGroup::GenericFactory::FactoryCreationId_ptr factory_id_ptr = 0;
877 ACE_NEW_THROW_EX (factory_id_ptr,
878 PortableGroup::GenericFactory::FactoryCreationId,
879 CORBA::NO_MEMORY (
880 CORBA::SystemException::_tao_minor_code (
881 TAO::VMCID,
882 ENOMEM),
883 CORBA::COMPLETED_NO));
884 PortableGroup::GenericFactory::FactoryCreationId_var factory_id = factory_id_ptr;
885 PortableGroup::ObjectGroupId group_id = group->get_object_group_id ();
886 factory_id <<= group_id;
887 factory_creation_id = factory_id._retn();
889 METHOD_RETURN (TAO::FT_ReplicationManager::create_object) group->reference ();
892 //CORBA
893 void
894 TAO::FT_ReplicationManager::delete_object (
895 const PortableGroup::GenericFactory::FactoryCreationId & factory_creation_id)
898 PortableGroup::ObjectGroupId group_id = 0;
899 if (factory_creation_id >>= group_id)
901 this->group_factory_.delete_group (
902 group_id);
904 else
906 throw PortableGroup::ObjectNotFound ();
910 //private
911 int TAO::FT_ReplicationManager::write_ior ()
913 int result = -1;
914 FILE* out = ACE_OS::fopen (this->ior_output_file_, "w");
915 if (out)
917 CORBA::String_var ior_str = this->orb_->object_to_string (
918 this->replication_manager_ref_.in ());
919 ACE_OS::fprintf (out, "%s", ior_str.in ());
920 ACE_OS::fclose (out);
921 result = 0;
923 else
925 ORBSVCS_ERROR ( (LM_ERROR,
926 ACE_TEXT ("%T %n (%P|%t) - Open failed for %s\n"), this->ior_output_file_
929 return result;
932 TAO_END_VERSIONED_NAMESPACE_DECL