summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/LoadBalancing/LoadBalancingI.cpp
blob: f8500c09cf2527ab9b8e93a4b259519ac2900d52 (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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
// -*- C++ -*-
//
// $Id$

#include "LoadBalancingI.h"

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


// Implementation skeleton constructor
TAO_LoadBalancing_ReplicationManager_i::TAO_LoadBalancing_ReplicationManager_i
(void)
  : locator_ (this),
    poa_ (),
    next_oid_ (0),
    object_group_map_ ()
{
  (void) this->init ();
}

// Implementation skeleton destructor
TAO_LoadBalancing_ReplicationManager_i::~TAO_LoadBalancing_ReplicationManager_i (void)
{
}

void
TAO_LoadBalancing_ReplicationManager_i::register_load_notifier (
    TAO_LoadBalancing::LoadNotifier_ptr /* load_notifier */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_THROW (CORBA::NO_IMPLEMENT());
}

TAO_LoadBalancing::LoadNotifier_ptr
TAO_LoadBalancing_ReplicationManager_i::get_load_notifier (
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
    TAO_LoadBalancing::InterfaceNotFound))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

void
TAO_LoadBalancing_ReplicationManager_i::set_default_properties (
    const TAO_LoadBalancing::Properties & /* props */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::InvalidProperty,
                   TAO_LoadBalancing::UnsupportedProperty))
{
  ACE_THROW (CORBA::NO_IMPLEMENT());
}

TAO_LoadBalancing::Properties *
TAO_LoadBalancing_ReplicationManager_i::get_default_properties (
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

void
TAO_LoadBalancing_ReplicationManager_i::remove_default_properties (
    const TAO_LoadBalancing::Properties & /* props */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::InvalidProperty,
                   TAO_LoadBalancing::UnsupportedProperty))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

void
TAO_LoadBalancing_ReplicationManager_i::set_type_properties (
    const char * /* type_id */,
    const TAO_LoadBalancing::Properties & /* overrides */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::InvalidProperty,
                   TAO_LoadBalancing::UnsupportedProperty))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::Properties *
TAO_LoadBalancing_ReplicationManager_i::get_type_properties (
    const char * /* type_id */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

void
TAO_LoadBalancing_ReplicationManager_i::remove_type_properties (
    const char * /* type_id */,
    const TAO_LoadBalancing::Properties & /* props */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::InvalidProperty,
                   TAO_LoadBalancing::UnsupportedProperty))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

void
TAO_LoadBalancing_ReplicationManager_i::set_properties_dynamically (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    const TAO_LoadBalancing::Properties & /* overrides */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound,
                   TAO_LoadBalancing::InvalidProperty,
                   TAO_LoadBalancing::UnsupportedProperty))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::Properties *
TAO_LoadBalancing_ReplicationManager_i::get_properties (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::ObjectGroup_ptr
TAO_LoadBalancing_ReplicationManager_i::create_member (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    const TAO_LoadBalancing::Location & /* the_location */,
    const char * /* type_id */,
    const TAO_LoadBalancing::Criteria & /* the_criteria */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound,
                   TAO_LoadBalancing::MemberAlreadyPresent,
                   TAO_LoadBalancing::NoFactory,
                   TAO_LoadBalancing::ObjectNotCreated,
                   TAO_LoadBalancing::InvalidCriteria,
                   TAO_LoadBalancing::CannotMeetCriteria))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::ObjectGroup_ptr
TAO_LoadBalancing_ReplicationManager_i::add_member (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    const TAO_LoadBalancing::Location & /* the_location */,
    CORBA::Object_ptr /* member */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound,
                   TAO_LoadBalancing::MemberAlreadyPresent,
                   TAO_LoadBalancing::ObjectNotAdded))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::ObjectGroup_ptr
TAO_LoadBalancing_ReplicationManager_i::remove_member (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    const TAO_LoadBalancing::Location & /* the_location */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound,
                   TAO_LoadBalancing::MemberNotFound))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::ObjectGroup_ptr
TAO_LoadBalancing_ReplicationManager_i::set_primary_member (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    const TAO_LoadBalancing::Location & /* the_location */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound,
                   TAO_LoadBalancing::MemberNotFound,
                   TAO_LoadBalancing::PrimaryNotSet,
                   TAO_LoadBalancing::BadReplicationStyle))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::Locations *
TAO_LoadBalancing_ReplicationManager_i::locations_of_members (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::ObjectGroupId
TAO_LoadBalancing_ReplicationManager_i::get_object_group_id (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

TAO_LoadBalancing::ObjectGroup_ptr
TAO_LoadBalancing_ReplicationManager_i::get_object_group_ref (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

CORBA::Object_ptr
TAO_LoadBalancing_ReplicationManager_i::get_member_ref (
    TAO_LoadBalancing::ObjectGroup_ptr /* object_group */,
    const TAO_LoadBalancing::Location & loc,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectGroupNotFound,
                   TAO_LoadBalancing::MemberNotFound))
{
  ACE_THROW (CORBA::NO_IMPLEMENT ());
}

CORBA::Object_ptr
TAO_LoadBalancing_ReplicationManager_i::create_object (
    const char * type_id,
    const TAO_LoadBalancing::Criteria & the_criteria,
    TAO_LoadBalancing::GenericFactory::FactoryCreationId_out
      factory_creation_id,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::NoFactory,
                   TAO_LoadBalancing::ObjectNotCreated,
                   TAO_LoadBalancing::InvalidCriteria,
                   TAO_LoadBalancing::InvalidProperty,
                   TAO_LoadBalancing::CannotMeetCriteria))
{
  // Check if an ObjectGroup for the given type hasn't already been
  // created.
  if (this->object_group_map_.find_type_id (type_id) == 0)
    ACE_THROW_RETURN (TAO_LoadBalancing::ObjectNotCreated ());    

  // List of invalid criteria.  If this list has a length greater than
  // zero, then the TAO_LoadBalancing::InvalidCriteria exception will
  // be thrown.
  TAO_Loadbalancing::Criteria invalid_criteria;

  int found_factory = 0; // If factory was found in the_criteria, then
                         // set to 1.

  // Parse the criteria.
  int criteria_count = the_criteria.length ();
  for (int i = 0; i < criteria_size; ++i)
    {
      CORBA::UShort initial_number_replicas = 0;
      TAO_LoadBalancing::FactoryInfos factory_infos;

      // Obtain the InitialNumberReplicas from the_criteria.
      if (this->get_initial_number_replicas (type_id,
                                             the_criteria[i],
                                             initial_number_replicas) != 0)
        {
          size_t length = invalid_criteria.length ();
          invalid_criteria.length (length + 1);
          invalid_criteria[length] = the_criteria[i];
        }

      // Obtain the FactoryInfos from the_criteria.  This method also
      // ensures that GenericFactories at different locations are used.
      else if (this->get_factory_infos (type_id,
                                        the_criteria[i],
                                        factory_infos) == 0)
        found_factory = 1;

      // Unknown property
      else
        ACE_THROW_RETURN (TAO_LoadBalancer::InvalidProperty (
                            the_criteria[i].nam,
                            the_criteria[i].val),
                          CORBA::Object::_nil ());
    }

  if (invalid_criteria.length () != 0)
    ACE_THROW_RETURN (TAO_LoadBalancing::InvalidCriteria (invalid_criteria),
                      CORBA::Object::_nil ());

  if (found_factory == 0)
    ACE_THROW_RETURN (TAO_LoadBalancing::NoFactory (),
                      CORBA::Object::_nil ());

  return this->create_object_i (type_id,
                                initial_number_replicas,
                                factory_infos,
                                ACE_TRY_ENV);
}

CORBA::Object_ptr
TAO_LoadBalancing_ReplicationManager_i::create_object_i (
    const char *type_id,
    CORBA::UShort initial_number_replicas,
    TAO_LoadBalancing::FactoryInfos &factory_infos,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::NoFactory,
                   TAO_LoadBalancing::ObjectNotCreated,
                   TAO_LoadBalancing::InvalidCriteria,
                   TAO_LoadBalancing::InvalidProperty,
                   TAO_LoadBalancing::CannotMeetCriteria))
{
  size_t factory_infos_count = factory_infos.length ();

  // If the number of factories is less than the initial number of
  // replicas, then the desired number of replicas cannot possibly be
  // created.
  if (factory_infos_count < initial_number_replicas)
    ACE_THROW_RETURN (TAO_LoadBalancing::CannotMeetCriteria (),
                      CORBA::Object::_nil ());

  TAO_LB_ObjectGroup_Map::Map_Entry *object_group_entry = 0;
  ACE_NEW_THROW_EX (object_group_entry,
                    TAO_LB_ObjectGroup_Map::Map_Entry,
                    CORBA::NO_MEMORY ());
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  auto_ptr<TAO_LB_ObjectGroup_Map> safe_object_group_entry (
    object_group_entry);

  for (int j = 0; j < factory_infos_count; ++j)
    {
      // The FactoryInfo::the_location member was used when
      // determining which FactoryInfo 
      //    member?
      // @@ It looks like it is only used when the application
      //    control membership style is used.  The application
      //    requests that a replica be created at a given
      //    "location," at which point the ReplicationManager
      //    searches through its registered FactoryInfos for a
      //    FactoryInfo with a "Location" member that matches
      //    the location at which to create the desired
      //    replica.
      // @@ It is also used to ensure that only one replica of
      //    a given type is created at a given location.


      TAO_LoadBalancing::FactoryInfo &factory_info =
        factory_infos[j];

      TAO_LoadBalancer::GenericFactory_ptr factory =
        factory_info.factory;

      TAO_LoadBalancing::GenericFactory::FactoryCreationId_out
        replica_factory_creation_id;

      CORBA::Object_var replica =
        factory->create_object (type_id,
                                factory_info.the_criteria,
                                replica_factory_creation_id,
                                ACE_TRY_ENV);
      ACE_CHECK_RETURN (CORBA::Object::_nil ());

      // @@ Should an "_is_a()" be performed here?  While it appears
      //    to be the right thing to do, it can be expensive.
      //
      // Make sure an Object of the correct type was created.  It is
      // possible that an object of the wrong type was created if the
      // type_id parameter does not match the type of object the
      // GenericFactory creates.
      CORBA::Boolean right_type_id =
        replica->_is_a (type_id, ACE_TRY_ENV);
      ACE_CHECK_RETURN (CORBA::Object::_nil ());

      if (!right_type_id)
        {
          // An Object of incorrect type was created.  Delete it, and
          // throw a NoFactory exception.
          factory->delete_object (replica_factory_creation_id,
                                  ACE_TRY_ENV);
          ACE_CHECK_RETURN (CORBA::Object::_nil ());

          ACE_THROW_RETURN (TAO_LoadBalancer::NoFactory (),
                            CORBA::Object::_nil ());
        }

      // Create a new Replica_Map map entry.
      TAO_LB_Replica_Map::Map_Entry *replica_entry = 0;
      ACE_NEW_THROW_EX (replica_entry,
                        TAO_LB_Replica_Map::Map_Entry,
                        CORBA::NO_MEMORY ());
      ACE_CHECK_RETURN (CORBA::Object::_nil ());

      auto_ptr<TAO_LB_Replica_Map> safe_replica_entry (replica_entry);

      replica_entry->replica = replica;

      TAO_LoadBalancer::FactoryInfo *new_factory_info = 0;
      ACE_NEW_THROW_EX (new_factory_info,
                        TAO_LoadBalancer::FactoryInfo,
                        CORBA::NO_MEMORY ());
      ACE_CHECK_RETURN (CORBA::Object::_nil ());

      replica_entry->factory_info = new_factory_info;

      // Copy the FactoryInfo structure.  A deep copy is actually
      // performed here.
      *new_factory_info = factory_info;

      replica_entry->factory_creation_id = replica_factory_creation_id;

      if (object_group_entry.replica_map.bind (replica_entry) != 0)
        {
          // An Object of incorrect type was created.  Delete it, and
          // throw a NoFactory exception.
          factory->delete_object (replica_factory_creation_id,
                                  ACE_TRY_ENV);
          ACE_CHECK_RETURN (CORBA::Object::_nil ());

          ACE_THROW_RETURN (TAO_LoadBalancer::ObjectNotCreated (),
                            CORBA::Object::_nil ());
        }

      // No longer need to protect the allocated Replica_Map.
      safe_replica_entry.release ();
    }

  // Create a reference for the ObjectGroup corresponding to the
  // RepositoryId of the object being created.

  PortableServer::ObjectId_var oid;
  this->get_ObjectId (oid.out ());

  CORBA::Object_var object_group =
    this->poa_->create_reference_with_id (oid.in (),
                                          type_id,
                                          ACE_TRY_ENV);
  ACE_CHECK_RETURN (CORBA::Object::_nil ());

  object_group_entry.type_id = CORBA::string_dup (type_id);
  object_group_entry.object_group = object_group;

  // @@ This is ugly, and needs to be cleaned up.
  object_group_entry.factory_creation_id = this->next_oid_ - 1;

  // Now (indirectly) associate the ObjectId with the ObjectGroup
  // reference.
  if (this->object_group_map_.bind (type_id, object_group_entry) != 0)
    ACE_THROW_RETURN (TAO_LoadBalancer::ObjectNotCreated (),
                      CORBA::Object::_nil ());

  // No longer need to protect the allocated ObjectGroup_Map.
  safe_object_group_entry.release ();

  return CORBA::Object::_duplicate (object_group.in ());
}

void
TAO_LoadBalancing_ReplicationManager_i::get_initial_number_replicas ()
{

}

void
TAO_LoadBalancing_ReplicationManager_i::get_factory_infos ()
{

}

void
TAO_LoadBalancing_ReplicationManager_i::delete_object (
    const TAO_LoadBalancing::GenericFactory::FactoryCreationId &
      factory_creation_id,
    CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   TAO_LoadBalancing::ObjectNotFound))
{
  ObjectGroup = this->object_groups_.find (factory_creation_id);
  if (ObjectGroup == -1)
    ACE_THROW (TAO_LoadBalancing::ObjectNotFound ());

  // Delete the individual replicas at their local factories.
  for (int i = 0; i < ObjectGroup.size (); ++i)
    {
      TAO_LoadBalancing::GenericFactory_ptr factory =
        ObjectGroup[i].factory;
      TAO_LoadBalancing::GenericFactory::FactoryCreationId
        replica_factory_id = ObjectGroup[i].replica_factory_id;
      factory->delete_object (replica_factory_id);
    }

  // Now delete the ObjectGroup from the set of ObjectGroups.
  this->object_groups_.unbind (factory_creation_id);
}

int
TAO_LoadBalancing_ReplicationManager_i::init (
  PortableServer::POA_ptr root_poa)
{
  ACE_TRY_NEW_ENV
    {
      // Create a new transient servant manager object in the Root
      // POA.
      PortableServer::ServantManager_var servant_manager =
        this->locator_._this (ACE_TRY_ENV);
      ACE_TRY_CHECK;

      // Create the appropriate RequestProcessingPolicy
      // (USE_SERVANT_MANAGER) and ServantRetentionPolicy (NON_RETAIN)
      // for a ServantLocator.
      PortableServer::RequestProcessingPolicy_var request =
        root_poa->create_request_processing_policy (
          PortableServer::USE_SERVANT_MANAGER,
          ACE_TRY_ENV);
      ACE_TRY_CHECK;

      PortableServer::ServantRetentionPolicy_var retention =
        root_poa->create_servant_retention_policy (
          PortableServer::NON_RETAIN,
          ACE_TRY_ENV);
      ACE_TRY_CHECK;

      // Create the PolicyList.
      CORBA::PolicyList policy_list;
      policy_list.length (2);
      policy_list[0] =
        PortableServer::RequestProcessingPolicy::_duplicate (
          request.in ());
      policy_list[1] =
        PortableServer::ServantRetentionPolicy::_duplicate (
           retention.in ());

      // Create the child POA with the above ServantManager policies.
      // The ServantManager will be the ReplicaLocator.
      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager (ACE_TRY_ENV);
      ACE_TRY_CHECK;
      this->poa_ = root_poa->create_POA ("TAO_LB_ReplicationManager_POA",
                                         poa_manager.in (),
                                         policy_list,
                                         ACE_TRY_ENV);
      ACE_TRY_CHECK;

      // Activate the child POA.
      poa_manager->activate (ACE_TRY_ENV);
      ACE_TRY_CHECK;

      request->destroy (ACE_TRY_ENV);
      ACE_TRY_CHECK;

      retention->destroy (ACE_TRY_ENV);
      ACE_TRY_CHECK;

      // Now set the ReplicaLocator as the child POA's Servant
      // Manager.
      this->poa_->set_servant_manager (servant_manager.in (),
                                       ACE_TRY_ENV);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      // @@ Should we do anything here?

      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                           "(%P|%t) TAO_LB_ReplicationManager_i::init:");

      return -1;
    }
  ACE_ENDTRY;

  return 0;
}

void
TAO_LoadBalancing_ReplicationManager_i::get_ObjectId (
  PortableServer::ObjectId_out &oid)
{
  // Since the POA used by the ReplicationManager uses the NON_RETAIN
  // policy, explicitly choose an ObjectId that is unique to a given
  // type.

  // Make the ObjectId be the next value of the number of types that
  // have been registered with the ReplicationManager.  For example,
  // if two types of objects have been registered with the
  // ReplicationManager, then the ObjectId for the object currently
  // being registered will be "3" since the object will be the third
  // type of object registered with the ReplicationManager.
  // Previously used values will not be reused to ensure that a
  // ServantLocator does not inadvertently return a reference to an
  // object that had a previously used ObjectId.  Specifcally, the
  // numerical value used for the ObjectId increases monotonically.

  char oid_str[BUFSIZ] = { 0 };
  ACE_OS::sprintf (oid_str,
                   "%ul",
                   this->next_oid_);

  oid = PortableServer::string_to_ObjectId (oid_str);

  // Increment the value for the next ObjectId.
  this->next_oid_++;
}

void
TAO_LoadBalancing_ReplicationManager_i::operator= (
  TAO_LoadBalancing::FactoryInfo &lhs,
  const TAO_LoadBalancing::FactoryInfo &rhs)
{
  lhs.factory =
    TAO_LoadBalancing::GenericFactory::_duplicate (rhs.factory);

  lhs.the_location = rhs.the_location;

  lhs.the_criteria = rhs.the_criteria;
}