summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_PropertyManager.h
blob: 06260ad4a49a3a9c19078c05d699ac8cc47d3df3 (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
// -*- C++ -*-

//=============================================================================
/**
 * @file LB_PropertyManager.h
 *
 * $Id$
 *
 * @author Ossama Othman <ossama@uci.edu>
 */
//=============================================================================


#ifndef TAO_LB_PROPERTY_MANAGER_H
#define TAO_LB_PROPERTY_MANAGER_H

#include "ace/pre.h"

#include "ace/config-all.h"

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

#include "ace/Functor.h"
#include "ace/Hash_Map_Manager_T.h"
#include "orbsvcs/LoadBalancingC.h"


/// Forward declarations.
class TAO_LB_ObjectGroup_Map;


/**
 * @class TAO_LB_PropertyManager
 *
 * @brief Class that implements the LoadBalancing::PropertyManager
 *        interface.
 *
 * Only the default and type-specific properties are housed in this
 * class.  The properties used at creation time of an object group and
 * those set dynamically after object group creation are stored in the
 * TAO_LB_ObjectGroup_Map_Entry structure.  However, the
 * PropertyManager is still used to manage those properties.
 */
class TAO_LB_PropertyManager
  : public virtual LoadBalancing::PropertyManager
{
public:

  /// Constructor.
  TAO_LB_PropertyManager (TAO_LB_ObjectGroup_Map &object_group_map);

  /**
   * @name TAO_LoadBalancer::PropertyManager methods
   */
  //@{

  /// Set the default properties to be used by all object groups.
  virtual void set_default_properties (
      const LoadBalancing::Properties & props,
      CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     LoadBalancing::InvalidProperty,
                     LoadBalancing::UnsupportedProperty));

  /// Get the default properties used by all object groups.
  virtual LoadBalancing::Properties * get_default_properties (
      CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException));

  /// Remove default properties.
  virtual void remove_default_properties (
      const LoadBalancing::Properties & props,
      CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     LoadBalancing::InvalidProperty,
                     LoadBalancing::UnsupportedProperty));

  /// Set properties associated with a given Replica type.  These
  /// properties override the default properties.
  virtual void set_type_properties (
      const char * type_id,
      const LoadBalancing::Properties & overrides,
      CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     LoadBalancing::InvalidProperty,
                     LoadBalancing::UnsupportedProperty));

  /**
   * 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 LoadBalancing::Properties * get_type_properties (
      const char * type_id,
      CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException));

  /// Remove the given properties associated with the Replica type ID.
  virtual void remove_type_properties (
      const char * type_id,
      const LoadBalancing::Properties & props,
      CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     LoadBalancing::InvalidProperty,
                     LoadBalancing::UnsupportedProperty));

  /**
   * 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 (
      LoadBalancing::ObjectGroup_ptr object_group,
      const LoadBalancing::Properties & overrides,
      CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     LoadBalancing::ObjectGroupNotFound,
                     LoadBalancing::InvalidProperty,
                     LoadBalancing::UnsupportedProperty));

  /**
   * 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 LoadBalancing::Properties * get_properties (
      LoadBalancing::ObjectGroup_ptr object_group,
      CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ())
    ACE_THROW_SPEC ((CORBA::SystemException,
                     LoadBalancing::ObjectGroupNotFound));

  //@}


  /// Verify that the given properties are valid and/or supported by
  /// the Load Balancer.
  void validate_properties (const LoadBalancing::Properties &props,
                            CORBA::Environment &ACE_TRY_ENV)
    ACE_THROW_SPEC ((LoadBalancing::InvalidProperty,
                     LoadBalancing::UnsupportedProperty));

  /**
   * @name TAO-specific Load Balancing PropertyManager Helper Methods
   *
   * These methods are used to avoid the allocations indirectly caused
   * by conformance to the C++ mapping.  Specifically, the IDL defined
   * PropertyManager methods above must return a set of properties
   * whose storage must be released by the caller.
   */
  //@{

  /// Return the membership style for the given object group.
  LoadBalancing::MembershipStyle membership_style (
    CORBA::Object_ptr object_group) const;

  /// Return the load monitoring style for the given object group.
  LoadBalancing::MonitoringStyle load_monitoring_style (
    CORBA::Object_ptr object_group) const;

  /// Return the load monitoring granularity for the given object
  /// group.
  LoadBalancing::MonitoringGranularity
    load_monitoring_granularity (CORBA::Object_ptr object_group) const;

  /// Return the initial number of replicas for the given object
  /// group.
  LoadBalancing::InitialNumberReplicas
    initial_number_replicas (const char *type_id,
                             const LoadBalancing::Criteria &the_criteria,
                             CORBA::Environment &ACE_TRY_ENV) const;

  /// Return the minimum number of replicas for the given object
  /// group.
  LoadBalancing::MinimumNumberReplicas
    minimum_number_replicas (CORBA::Object_ptr object_group) const;

  /// Return the sequence FactoryInfos associated with the given
  /// object group.
  LoadBalancing::FactoryInfos *
    factory_infos (const char *type_id,
                   const LoadBalancing::Criteria &the_criteria,
                   CORBA::Environment &ACE_TRY_ENV) const;

  //@}

  /// Type-specific property hash map.
  typedef ACE_Hash_Map_Manager_Ex<
    const char *,
    LoadBalancing::Properties,
    ACE_Hash<const char *>,
    ACE_Equal_To<const char *>,
    ACE_Null_Mutex> Type_Prop_Table;

private:

  /// Table that maps ObjectId to Object Group related information.
  TAO_LB_ObjectGroup_Map &object_group_map_;

  /// Default properties.
  LoadBalancing::Properties default_properties_;

  /// Table of type-specific object group properties.
  Type_Prop_Table type_properties_;

  /// Lock used to synchronize access to the default properties and
  /// the type-specific properties.
  TAO_SYNCH_MUTEX lock_;

};


#include "ace/post.h"

#endif /* TAO_LB_PROPERTY_MANAGER_H */