Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / FT_ReplicationManager / FT_ReplicationManager.h
blob462c98a8168e8e61007d8b00e9b6552dbd3ae303
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
4 * @file FT_ReplicationManager.h
6 * This file is part of Fault Tolerant CORBA.
8 * @author Curt Hibbs <hibbs_c@ociweb.com>
9 */
10 //=============================================================================
13 #ifndef FT_REPLICATION_MANAGER_H_
14 #define FT_REPLICATION_MANAGER_H_
16 #include /**/ "ace/pre.h"
17 #include <ace/ACE.h>
19 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #pragma once
21 #endif /* ACE_LACKS_PRAGMA_ONCE */
23 #include <orbsvcs/FT_ReplicationManagerS.h>
24 //#include <orbsvcs/PortableGroup/PG_PropertyManager.h>
25 //#include <orbsvcs/PortableGroup/PG_GenericFactory.h>
26 //#include <orbsvcs/PortableGroup/PG_ObjectGroupManager.h>
27 // Note: the new, improved versions...
28 //#include <orbsvcs/PortableGroup/PG_Object_Group_Map.h>
29 #include <orbsvcs/PortableGroup/PG_Properties_Support.h>
30 #include <orbsvcs/PortableGroup/PG_Group_Factory.h>
32 #include <orbsvcs/PortableGroup/PG_FactoryRegistry.h>
33 #include <orbsvcs/FT_ReplicationManager/FT_FaultConsumer.h>
35 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
37 namespace TAO
39 /**
40 * Implement the ReplicationManager interfaces.
42 * The ReplicationManager does most of its work by delegating to
43 * support objects. These include:
45 * TAO::PG_Group_Factory group_factory_;
46 * The group factory contains a collection of TAO::PG_Object_Groups
47 * It provides methods to create new groups, destroy old groups and
48 * find existing groups.
50 * TAO::PG_Object_Group
51 * These objects which can be found through the group factory provde
52 * methods to create and add group members, remove and delete group
53 * members and set group properties.
55 * TAO::PG_Properties_Support properties_support_;
56 * This object maintains sets of properties(TAO::PG_Property_Set).
57 * In particular it has one default property set, and a collection of
58 * property sets indexed by type_id.
59 * The default property set acts as a parent to the type_id property
60 * sets and the type_id property sets act as parents to the property
61 * sets contained in PG_Object_Group.
63 * FT::FaultNotifier_var fault_notifier_;
64 * This notification channel is "the" source of fault notifications.
66 * TAO::FT_FaultConsumer fault_consumer_;
67 * This object subscribes to the fault_notifier_as a fault consumer. It
68 * analyzes incoming fault notifications and calls appropriate ReplicationManager
69 * methods to respond to the fault.
71 * TAO::PG_FactoryRegistry factory_registry_;
72 * This object maintains a collection of factory registrations. When a factory
73 * is started it registeres itself with the ReplicationManager (delegated to this
74 * object). When a member needs to be created in an object group this factory
75 * registry is queried to find factories that can create the member.
77 class FT_ReplicationManager
78 : public virtual POA_FT::ReplicationManager
81 //////////////////////
82 // non-CORBA interface
84 public:
85 /**
86 * Default constructor.
87 * Call init after constructing the object to prepare it for use.
89 FT_ReplicationManager ();
91 /**
92 * Destructor.
93 * Actual cleanup happens in the fini function.
95 virtual ~FT_ReplicationManager ();
97 public:
99 /**
100 * Parse command line arguments.
101 * @param argc traditional C argc
102 * @param argv traditional C argv
103 * @return zero for success; nonzero is process return code for failure.
105 int parse_args (int argc, ACE_TCHAR * argv[]);
108 * Initialize this object.
109 * @param orb Our CORBA::ORB -- we keep var to it.
110 * @return zero for success; nonzero is process return code for failure.
112 int init (CORBA::ORB_ptr orb);
115 * Prepare to exit.
116 * @return zero for success; nonzero is process return code for failure.
118 int fini (void);
121 * Idle-time activity.
123 * @param result is set to process return code if return value is non-zero.
124 * @return zero to continue; nonzero to exit
126 int idle (int & result);
130 * Identify this fault detector factory.
131 * @return a string to identify this object for logging/console message purposes.
133 const char * identity () const;
136 * Get the type_id associated with an object group.
137 * @param object_group The ObjectGroup.
138 * @return String identifying the type id associated with the ObjectGroup.
140 char * type_id (PortableGroup::ObjectGroup_ptr object_group);
143 //////////////////////
144 // CORBA interface(s)
146 public:
149 * @name POA_FT::ReplicationManager Methods
151 * Methods required by the POA_FT::ReplicationManager interface.
153 //@{
155 /// Registers the Fault Notifier with the Replication Manager.
156 virtual void register_fault_notifier (
157 FT::FaultNotifier_ptr fault_notifier);
159 /// Returns the reference of the Fault Notifier.
160 virtual FT::FaultNotifier_ptr get_fault_notifier ();
162 /// TAO-specific find factory registry
163 virtual ::PortableGroup::FactoryRegistry_ptr get_factory_registry (
164 const PortableGroup::Criteria & selection_criteria);
166 /// TAO-specific shutdown operation.
167 virtual void shutdown ();
169 //@}
172 * @name PortableGroup::PropertyManager Methods
174 * Methods required by the PortableGroup::PropertyManager interface.
176 //@{
178 /// Set the default properties to be used by all object groups.
179 virtual void set_default_properties (
180 const PortableGroup::Properties & props);
182 /// Get the default properties used by all object groups.
183 virtual PortableGroup::Properties * get_default_properties ();
185 /// Remove default properties.
186 virtual void remove_default_properties (
187 const PortableGroup::Properties & props);
190 * Set properties associated with a given Replica type. These
191 * properties override the default properties on a name-by-name basis.
193 virtual void set_type_properties (
194 const char * type_id,
195 const PortableGroup::Properties & overrides);
198 * Return the properties associated with a given Replica type. These
199 * properties include the type-specific properties in use, in
200 * addition to the default properties that were not overridden.
202 virtual PortableGroup::Properties * get_type_properties (
203 const char * type_id);
205 /// Remove the given properties associated with the Replica type ID.
206 virtual void remove_type_properties (
207 const char * type_id,
208 const PortableGroup::Properties & props);
211 * Dynamically set the properties associated with a given object
212 * group as the replication manager and replicas are being executed.
213 * These properties override the type-specific and default
214 * properties.
216 virtual void set_properties_dynamically (
217 PortableGroup::ObjectGroup_ptr object_group,
218 const PortableGroup::Properties & overrides);
221 * Return the properties currently in use by the given object
222 * group. These properties include those that were set dynamically,
223 * type-specific properties that weren't overridden, properties that
224 * were used when the Replica was created, and default properties
225 * that weren't overridden.
227 virtual PortableGroup::Properties * get_properties (
228 PortableGroup::ObjectGroup_ptr object_group);
230 //@}
233 * @name FT::FTObjectGroupManager methods
235 * Methods required by the FT::FTObjectGroupManager
236 * interface.
238 //@{
240 /// Create a member in an object group.
241 virtual PortableGroup::ObjectGroup_ptr create_member (
242 PortableGroup::ObjectGroup_ptr object_group,
243 const PortableGroup::Location & the_location,
244 const char * type_id,
245 const PortableGroup::Criteria & the_criteria);
247 /// Add an existing object to the ObjectGroup.
248 virtual PortableGroup::ObjectGroup_ptr add_member (
249 PortableGroup::ObjectGroup_ptr object_group,
250 const PortableGroup::Location & the_location,
251 CORBA::Object_ptr member);
254 * Remove the member at a specific location from an
255 * ObjectGroup. Application created objects must be
256 * deleted by the application. Objects created by the
257 * infrastructure (replication manager) will be deleted by the
258 * infrastructure.
259 * For infrastructure-controlled membership: After the member
260 * is removed from the group the minumum number of members
261 * parameter will be checked and new members will be created
262 * as necessary (if possible.)
264 virtual PortableGroup::ObjectGroup_ptr remove_member (
265 PortableGroup::ObjectGroup_ptr object_group,
266 const PortableGroup::Location & the_location);
268 /// Return the locations of the members in the given ObjectGroup.
269 virtual PortableGroup::Locations * locations_of_members (
270 PortableGroup::ObjectGroup_ptr object_group);
272 /// Return the locations of the members in the given ObjectGroup.
273 virtual PortableGroup::ObjectGroups * groups_at_location (
274 const PortableGroup::Location & the_location);
276 /// Return the ObjectGroupId for the given ObjectGroup.
277 virtual PortableGroup::ObjectGroupId get_object_group_id (
278 PortableGroup::ObjectGroup_ptr object_group);
281 * Return an update the IOGR for an object group. If no changes have
282 * been made in the group the return value will be the same as the object_group
283 * parameter.
285 virtual PortableGroup::ObjectGroup_ptr get_object_group_ref (
286 PortableGroup::ObjectGroup_ptr object_group);
289 * TAO-specific extension.
290 * Return the ObjectGroup reference for the given ObjectGroupId.
292 virtual PortableGroup::ObjectGroup_ptr get_object_group_ref_from_id (
293 PortableGroup::ObjectGroupId group_id);
296 * Return the reference corresponding to the Replica of a given
297 * ObjectGroup at the given location.
299 virtual CORBA::Object_ptr get_member_ref (
300 PortableGroup::ObjectGroup_ptr object_group,
301 const PortableGroup::Location & loc);
303 /// Sets the primary member of a group.
304 virtual PortableGroup::ObjectGroup_ptr set_primary_member (
305 PortableGroup::ObjectGroup_ptr object_group,
306 const PortableGroup::Location & the_location
309 //@}
312 * @name PortableGroup::GenericFactory methods
314 * Methods required by the PortableGroup::GenericFactory interface.
316 //@{
319 * Create an object of the specified type that adheres to the
320 * restrictions defined by the provided Criteria. The out
321 * FactoryCreationId parameter may be passed to the delete_object()
322 * method to delete the object.
324 * Infrastructure controlled membership: The initial number of members
325 * property will be honored by creating new members and adding them to
326 * the group.
328 virtual CORBA::Object_ptr create_object (
329 const char * type_id,
330 const PortableGroup::Criteria & the_criteria,
331 PortableGroup::GenericFactory::FactoryCreationId_out
332 factory_creation_id);
335 * Delete the object group corresponding to the provided
336 * FactoryCreationId. For infratructure-controlled membership
337 * all members will be deleted. For application-controlled membership
338 * the application is responsible for deleting group members.
340 virtual void delete_object (
341 const PortableGroup::GenericFactory::FactoryCreationId &
342 factory_creation_id);
344 //@}
346 /////////////////////////
347 // Implementation methods
348 private:
350 * Write this factory's IOR to a file
352 int write_ior (void);
354 /// Registers the Fault Notifier with the Replication Manager.
355 void register_fault_notifier_i (
356 FT::FaultNotifier_ptr fault_notifier
359 ////////////////
360 // Forbidden methods
361 FT_ReplicationManager (const FT_ReplicationManager & rhs);
362 FT_ReplicationManager & operator = (const FT_ReplicationManager & rhs);
364 ///////////////
365 // Data Members
366 private:
368 /// The orb
369 CORBA::ORB_var orb_;
371 /// The POA.
372 PortableServer::POA_var poa_;
374 /// A file to which the factory's IOR should be written.
375 const ACE_TCHAR * ior_output_file_;
377 /// A name to be used to register the factory with the name service.
378 ACE_CString ns_name_;
379 CosNaming::NamingContext_var naming_context_;
380 CosNaming::Name this_name_;
382 /// Our object reference.
383 FT::ReplicationManager_var replication_manager_ref_;
385 /// A human-readable string to identify this Replication Manager.
386 ACE_CString identity_;
388 /// an object that manages a collection of object groups
389 TAO::PG_Group_Factory group_factory_;
391 /// an object that manages default and type_id related properties
392 TAO::PG_Properties_Support properties_support_;
394 /// The fault notifier.
395 FT::FaultNotifier_var fault_notifier_;
396 /// set by command line -f option
397 const ACE_TCHAR * fault_notifier_ior_string_;
399 /// The fault consumer.
400 TAO::FT_FaultConsumer fault_consumer_;
402 /// The factory registry
403 TAO::PG_FactoryRegistry factory_registry_;
405 /// Quit flag.
406 int quit_;
409 } // namespace TAO
411 TAO_END_VERSIONED_NAMESPACE_DECL
413 #include /**/ "ace/post.h"
415 #endif /* FT_REPLICATION_MANAGER_H_ */