summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/LB_PropertyManager.cpp
blob: 2454edd0d63510aacd2b1d107f46fb8adcc426e7 (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
// -*- C++ -*-

#include "LB_PropertyManager.h"

ACE_RCSID (LoadBalancing,
           LB_PropertyManager,
           "$Id$")

TAO_LB_PropertyManager::TAO_LB_PropertyManager (
  TAO_LB_ObjectGroup_Map &object_group_map)
  : object_group_map_ (object_group_map),
    default_properties_ (),
    type_properties_ (),
    lock_ ()
{
}

void
TAO_LB_PropertyManager::set_default_properties (
    const LoadBalancing::Properties & props,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   LoadBalancing::InvalidProperty,
                   LoadBalancing::UnsupportedProperty))
{
  this->validate_properties (props, ACE_TRY_ENV);
  ACE_CHECK;

  {
    ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->lock_);

    this->default_properties_ = props;
  }
}

LoadBalancing::Properties *
TAO_LB_PropertyManager::get_default_properties (
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->lock_, 0);

  LoadBalancing::Properties *props = 0;
  ACE_NEW_THROW_EX (props,
                    LoadBalancing::Properties (this->default_properties_),
                    CORBA::NO_MEMORY (
                      CORBA::SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        ENOMEM),
                      CORBA::COMPLETED_NO));
  ACE_CHECK_RETURN (0);

  return props;
}

void
TAO_LB_PropertyManager::remove_default_properties (
    const LoadBalancing::Properties &props,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   LoadBalancing::InvalidProperty,
                   LoadBalancing::UnsupportedProperty))
{
  this->validate_properties (props, ACE_TRY_ENV);
  ACE_CHECK;

  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

void
TAO_LB_PropertyManager::set_type_properties (
    const char * /* type_id */,
    const LoadBalancing::Properties & overrides,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   LoadBalancing::InvalidProperty,
                   LoadBalancing::UnsupportedProperty))
{
  this->validate_properties (overrides, ACE_TRY_ENV);
  ACE_CHECK;

  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

LoadBalancing::Properties *
TAO_LB_PropertyManager::get_type_properties (
    const char * /* type_id */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_THROW_RETURN (CORBA::NO_IMPLEMENT (), 0);
}

void
TAO_LB_PropertyManager::remove_type_properties (
    const char * /* type_id */,
    const LoadBalancing::Properties & props,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   LoadBalancing::InvalidProperty,
                   LoadBalancing::UnsupportedProperty))
{
  this->validate_properties (props, ACE_TRY_ENV);
  ACE_CHECK;

  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

void
TAO_LB_PropertyManager::set_properties_dynamically (
    LoadBalancing::ObjectGroup_ptr object_group,
    const LoadBalancing::Properties & overrides,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   LoadBalancing::ObjectGroupNotFound,
                   LoadBalancing::InvalidProperty,
                   LoadBalancing::UnsupportedProperty))
{
  this->validate_properties (overrides, ACE_TRY_ENV);
  ACE_CHECK;

  
}

LoadBalancing::Properties *
TAO_LB_PropertyManager::get_properties (
    LoadBalancing::ObjectGroup_ptr object_group,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   LoadBalancing::ObjectGroupNotFound))
{
  TAO_LB_ObjectGroup_Map *entry =
    this->object_group_map_.get_group_entry (object_group, ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  //  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, group_map_guard, entry->lock, 0);

  //  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, property_map_guard, this->lock_, 0);

  // Merge the type-properties into the list.
  LoadBalancing::Properties &type_properties;
  if (this->type_properties_.find (entry.in (), type_properties == 0))
    {
    }

  // Merge the default properties into the property list.

  return properties._retn ();
}

void
TAO_LB_PropertyManager::validate_properties (
    const LoadBalancing::Properties & props,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((LoadBalancing::InvalidProperty,
                   LoadBalancing::UnsupportedProperty))
{
  // @todo FIXME!  Just a hack to get things going...

  CORBA::ULong len = props.length ();
  for (CORBA::ULong i = 0; i < len; ++i)
    {
      if (ACE_OS::strcmp (props[i].nam.id[0],
                          "Factories") == 0)
        return;
      else if (ACE_OS::strcmp (props[i].nam.id[0],
                          "InitialNumberReplicas") == 0)
        return;
      else if (ACE_OS::strcmp (props[i].nam.id[0],
                          "MinimumNumberReplicas") == 0)
        return;
      else
        ACE_THROW (LoadBalancing::UnsupportedProperty (props[i].nam));
    }
}

LoadBalancing::InitialNumberReplicas
TAO_LB_PropertyManager::get_initial_number_replicas (
  const char * /* type_id */,
  const LoadBalancing::Criteria &the_criteria,
  CORBA::Environment &ACE_TRY_ENV)
{
  // @@ Hack to get things going.

  // First, check if the given criteria has a desired number of
  // initial replicas.
  CORBA::ULong len = the_criteria.length ();
  for (CORBA::ULong i = 0; i < len; ++i)
    {
      if (ACE_OS::strcmp (the_criteria[i].nam.id[0],
                          "InitialNumberReplicas") == 0)
        {
          LoadBalancing::InitialNumberReplicas initial_number_replicas = 0;

          if (the_criteria[i].val >>= initial_number_replicas)
            return initial_number_replicas;
          else
            ACE_THROW_RETURN (LoadBalancing::Property (
                                the_criteria[i].nam,
                                the_criteria[i].val),
                              0);
        }
    }

  // Second, check if a type-specific number of initial replicas was
  // set.

  // Third, check if a default number of initial replicas was set.

  return 0;  // @@ FIXME
}


// -----------------------------------------------------------

CORBA::Boolean
operator== (const LoadBalancing::Property &lhs,
            const LoadBalancing::Property &rhs)
{
  // @todo Interim implementation until we figure out what to do when a
  //       property has multiple components.
  CORBA::ULong lhs_len = lhs.length ();
  CORBA::ULong rhs_len = rhs.length ();

  if (lhs_len != rhs_len)
    return 0;

  for (CORBA::ULong i = 0; i < lhs_len; ++i)
    if (ACE_OS::strcmp (lhs[i].id, rhs[i].id) != 0
        || ACE_OS::strcmp (lhs[i].kind, rhs[i].kind) != 0)
      return 0;

  return 1;
}

// -----------------------------------------------------------

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

// Type-specific property hash map template instantiations
template class ACE_Hash_Map_Entry<const char *, LoadBalancing::Properties>;
template class ACE_Hash_Map_Manager_Ex<const char *, LoadBalancing::Properties, TAO_ObjectId_Hash, ACE_Equal_To<const char *>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Base_Ex<const char *, LoadBalancing::Properties, TAO_ObjectId_Hash, ACE_Equal_To<const char *>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Ex<const char *, LoadBalancing::Properties, TAO_ObjectId_Hash, ACE_Equal_To<const char *>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Reverse_Iterator_Ex<const char *, LoadBalancing::Properties, TAO_ObjectId_Hash, ACE_Equal_To<const char *>, ACE_Null_Mutex>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

// Type-specific property hash map template instantiations
#pragma instantiate ACE_Hash_Map_Entry<const char *, LoadBalancing::Properties>
#pragma instantiate ACE_Hash_Map_Manager_Ex<const char *, LoadBalancing::Properties, TAO_ObjectId_Hash, ACE_Equal_To<const char *>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<const char *, LoadBalancing::Properties, TAO_ObjectId_Hash, ACE_Equal_To<const char *>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Ex<const char *, LoadBalancing::Properties, TAO_ObjectId_Hash, ACE_Equal_To<const char *>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<const char *, LoadBalancing::Properties, TAO_ObjectId_Hash, ACE_Equal_To<const char *>, ACE_Null_Mutex>

#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */