summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h
blob: ae7868261e6b96691af23c1e26bb1a73ea33aa84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
// -*- C++ -*-

//=============================================================================
/**
 * @file   FT_Naming_Manager.h
 *
 *
 * @author Kevin Stanley <stanleyk@ociweb.com>
 */
//=============================================================================


#ifndef TAO_FT_NAMING_MANAGER_H
#define TAO_FT_NAMING_MANAGER_H

#include /**/ "ace/pre.h"

#include "orbsvcs/Naming/FaultTolerant/ftnaming_export.h"

#include "orbsvcs/FT_NamingManagerS.h"
#include "orbsvcs/FT_NamingManagerC.h"
#include "orbsvcs/Naming/FaultTolerant/FT_Naming_Replication_Manager.h"
#include "orbsvcs/PortableGroup/PG_FactoryRegistry.h"
#include "orbsvcs/PortableGroup/PG_Properties_Support.h"
#include "orbsvcs/Naming/FaultTolerant/FT_PG_Group_Factory.h"
#include "orbsvcs/Naming/FaultTolerant/FT_Random.h"
#include "orbsvcs/Naming/FaultTolerant/FT_Round_Robin.h"
#include "tao/Condition.h"

#include "ace/Task.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
#pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */


TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
  class Storable_Factory;
}

class TAO_FT_Naming_Replication_Manager;

/**
 * @class TAO_FT_Naming_Manager
 * @brief Implements the NamingManager interface for the Fault
 * tolerant naming service.
 *
 * This class implements the NamingManager interface in support
 * of the load balancing features of the FaultTolerant Naming
 * Service. Uses can create and manage object groups which can be
 * bound in the Naming Service, which will provide the load balancing
 * functionality.
 */
class TAO_FtNaming_Export TAO_FT_Naming_Manager
  : public virtual POA_FT_Naming::NamingManager,
    public ACE_Task_Base
{
public:

  /// Constructor.
  TAO_FT_Naming_Manager (void);

  void set_replicator (TAO_FT_Naming_Replication_Manager *repl);

  /**
   * @name FT::NamingManager Methods
   *
   *
   */

  /// Creates an object group with the specified name and load
  /// balancing strategy.
  /// @param[in] group_name The symbolic name of the group that can
  /// be used to refer to the group in other operations.
  /// @param[in] lb_strategy The strategy to be used by the Naming
  /// Service when this object group is resolved. Currently only
  /// FT_Naming::ROUND_ROBIN is supported.
  ///@param[in] the_criteria Properties to be used by the object group.
  virtual PortableGroup::ObjectGroup_ptr create_object_group (
    const char * group_name,
    ::FT_Naming::LoadBalancingStrategyValue lb_strategy,
    const ::PortableGroup::Criteria & the_criteria);

  /// Deletes the object group with the provided group_name.
  virtual void delete_object_group (
    const char * group_name);

  /// Retrieves a reference to a group with the specified name
  virtual PortableGroup::ObjectGroup_ptr get_object_group_ref_from_name (
    const char * group_name);

  /// Provide a new load balancing strategy for the group with the provided
  /// name.
  virtual void set_load_balancing_strategy (
      const char * group_name,
      ::FT_Naming::LoadBalancingStrategyValue lb_strategy);

  /// Retrieve the names of the groups with the specified load balancing
  /// strategy that have been created in this Naming Manager.
  virtual ::FT_Naming::GroupNames * groups (
     ::FT_Naming::LoadBalancingStrategyValue target_strategy);

  /**
   * @name PortableGroup::PropertyManager Methods
   *
   * Methods required by the PortableGroup::PropertyManager interface.
   */
  //@{

  /// Set the default properties to be used by all object groups.
  virtual void set_default_properties (
      const PortableGroup::Properties & props);

  /// Get the default properties used by all object groups.
  virtual PortableGroup::Properties * get_default_properties ();

  /// Remove default properties.
  virtual void remove_default_properties (
      const PortableGroup::Properties & props);

  /// Set properties associated with a given Replica type.  These
  /// properties override the default properties.
  virtual void set_type_properties (
      const char * type_id,
      const PortableGroup::Properties & overrides);

  /**
   * Return the properties associated with a give Replica type.  These
   * properties include the type-specific properties in use, in
   * addition to the default properties that were not overridden.
   */
  virtual PortableGroup::Properties * get_type_properties (
      const char * type_id);

  /// Remove the given properties associated with the Replica type ID.
  virtual void remove_type_properties (
      const char * type_id,
      const PortableGroup::Properties & props);

  /**
   * Dynamically set the properties associated with a given object
   * group as the load balancer and replicas are being executed.
   * These properties override the type-specific and default
   * properties.
   */
  virtual void set_properties_dynamically (
      PortableGroup::ObjectGroup_ptr object_group,
      const PortableGroup::Properties & overrides);

  /**
   * Return the properties currently in use by the given object
   * group.  These properties include those that were set dynamically,
   * type-specific properties that weren't overridden, properties that
   * were used when the Replica was created, and default properties
   * that weren't overridden.
   */
  virtual PortableGroup::Properties * get_properties (
      PortableGroup::ObjectGroup_ptr object_group);

  //@}

  /**
   * @name PortableGroup::ObjectGroupManager methods
   *
   * Methods required by the PortableGroup::ObjectGroupManager
   * interface.
   */
  //@{

  /// Create a member using the load balancer ObjectGroupManager, and
  /// add the created object to the ObjectGroup.
  virtual PortableGroup::ObjectGroup_ptr create_member (
      PortableGroup::ObjectGroup_ptr object_group,
      const PortableGroup::Location & the_location,
      const char * type_id,
      const PortableGroup::Criteria & the_criteria);

  /// Add an existing object to the ObjectGroup.
  /// @param[in] object_group A reference for the group to which the
  /// specified member is to be added.
  /// @param[in] the_location The symbolic value that specifies this
  /// specific member. The location can be any string value.
  /// @param[in] member The object reference for the member. The first
  /// member's type is used to defined the object group type. All subsequence
  /// members must have the same type.
  virtual PortableGroup::ObjectGroup_ptr add_member (
      PortableGroup::ObjectGroup_ptr object_group,
      const PortableGroup::Location & the_location,
      CORBA::Object_ptr member);

  /**
   * Remove an object at a specific location from the given
   * ObjectGroup.  Deletion of application created objects must be
   * deleted by the application.  Objects created by the
   * infrastructure (load balancer) will be deleted by the
   * infrastructure.
   */
  virtual PortableGroup::ObjectGroup_ptr remove_member (
      PortableGroup::ObjectGroup_ptr object_group,
      const PortableGroup::Location & the_location);

  /// Return the locations of the members in the given ObjectGroup.
  virtual PortableGroup::Locations * locations_of_members (
      PortableGroup::ObjectGroup_ptr object_group);

  /// Return the locations of the members in the given ObjectGroup.
  virtual PortableGroup::ObjectGroups * groups_at_location (
      const PortableGroup::Location & the_location);

  /// Return the ObjectGroupId for the given ObjectGroup.
  virtual PortableGroup::ObjectGroupId get_object_group_id (
      PortableGroup::ObjectGroup_ptr object_group);

  /// TAO specific method
  virtual PortableGroup::ObjectGroup_ptr get_object_group_ref_from_id (
      PortableGroup::ObjectGroupId group_id);

  /// Return the reference corresponding to the Replica of a given
  /// ObjectGroup at the given location.
  virtual CORBA::Object_ptr get_member_ref (
      PortableGroup::ObjectGroup_ptr object_group,
      const PortableGroup::Location & loc);

  //@}

  /**
   * @name PortableGroup::GenericFactory methods
   *
   * Methods required by the PortableGroup::GenericFactory interface.
   */
  //@{

  /**
   * Create an object of the specified type that adheres to the
   * restrictions defined by the provided Criteria.  The out
   * FactoryCreationId parameter may be passed to the delete_object()
   * method to delete the object.  This signature is modified from
   * the generic factory operation to support the use of an object
   * name in addition to the factory_creation_id.
   */
  virtual CORBA::Object_ptr create_object (
      const char * object_name,
      const char * type_id,
      const PortableGroup::Criteria & the_criteria,
      PortableGroup::GenericFactory::FactoryCreationId_out
        factory_creation_id);

  /**
   * Delete the object corresponding to the provided
   * FactoryCreationId.  If the object is actually an ObjectGroup,
   * then all members within the ObjectGroup will be deleted.
   * Afterward, the ObjectGroup itself will be deleted.
   */
  virtual void delete_object (
      const PortableGroup::GenericFactory::FactoryCreationId &
        factory_creation_id);

  //@}

  /// Initialize the naming manager. This will provide the poa to
  /// the naming manager and underlying components for use in
  /// managing the object groups.
  void initialize (CORBA::ORB_ptr orb,
                   PortableServer::POA_ptr root_poa);


  /// Utilizing the load balancing strategy identified by the object
  /// group property, return the next object reference from the object
  /// group which should be used to service the next CORBA request
  CORBA::Object_ptr next_member (PortableGroup::ObjectGroup_ptr object_group);

  /// Load/save state of object groups from/to file for fault
  /// tolerant purposes.
  void
  set_object_group_storable_factory (TAO::Storable_Factory *
    factory);

  /// Indicate the object group state is stale.
  /// Only valid when object group persistence is enabled.
  void set_object_group_stale (const FT_Naming::ObjectGroupUpdate & group_info);

  /// Initialize a global load balancing strategy
  void set_global_strategy (const ACE_TCHAR *strat_name);

  /// Destructor.
  ~TAO_FT_Naming_Manager (void);

private:
  /// A utility to ensure we can access the latest object reference for
  /// the object group when referenced externally.
  virtual PortableGroup::ObjectGroup_ptr get_object_group_ref (
      PortableGroup::ObjectGroup_ptr object_group);

  /// TAO specific method  /// Preprocess Strategy or CustomStrategy properties.
  /**
   * This method takes care of converting StrategyInfo properties to
   * Strategy properties, and verifying that CustomStrategy references
   * are not nil.
   */
  void preprocess_properties (PortableGroup::Properties & props);

  /// Utility for accessing the object group name.  Returns true if a
  /// name is found and allocates a string with the name assigned to
  /// the name parameter.
  bool group_name (PortableGroup::ObjectGroup_ptr group, char*& name);

  /// an object that manages default and type_id related properties
  TAO::PG_Properties_Support properties_support_;

  /// Registry used by the PG_Group_Factory
  TAO::PG_FactoryRegistry factory_registry_;

  /// The group factory responsible for creating object groups
  TAO::FT_PG_Group_Factory group_factory_;

  /**
   * @name Built-in load balancing strategy implementations
   *
   * "Built-in" load balancing strategies. Currently RoundRobin
   * and Random are supported.
   */
  //@{

  /// The "RoundRobin" load balancing strategy.
  TAO_FT_Round_Robin round_robin_;
  /// The "Random" load balancing strategy.
  TAO_FT_Random random_;
  /// A flag indicating that strategy is selected by the group if false
  /// or the globally set strategy if true
  bool use_global_;
  /// The global strategy
  ::FT_Naming::LoadBalancingStrategyValue global_strategy_;
  //@}

  /// Cached instance of the Property name
  /// "org.omg.CosLoadBalancing.Strategy".
  PortableGroup::Name built_in_balancing_strategy_name_;

  PortableGroup::Name object_group_property_name_;

};


TAO_END_VERSIONED_NAMESPACE_DECL

#include /**/ "ace/post.h"

#endif  /* TAO_FT_NAMING_MANAGER_H */