summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.cpp
blob: 4a3c0bafc58ca5e4514886cbfd877e89328957f9 (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
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
// -*- C++ -*-

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

#include "orbsvcs/Log_Macros.h"
#include "orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h"
#include "orbsvcs/FT_NamingManagerC.h"
#include "orbsvcs/PortableGroup/PG_Property_Utils.h"
#include "orbsvcs/PortableGroup/PG_Property_Set.h"
#include "orbsvcs/PortableGroup/PG_Object_Group.h"
#include "orbsvcs/PortableGroup/PG_conf.h"
#include "orbsvcs/PortableGroup/PG_Utils.h"

#include "tao/debug.h"
#include "tao/ORB_Constants.h"

#include "ace/SString.h"
#include "ace/OS_NS_sys_time.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_string.h"
#include "ace/OS_NS_strings.h"

// Use this macro at the beginning of CORBA methods
// to aid in debugging.
#define METHOD_ENTRY(name)    \
  if (TAO_debug_level > 6)    \
  {                           \
    ORBSVCS_DEBUG (( LM_DEBUG,    \
    "Enter %s\n", #name       \
      ));                     \
  }

// Use this macro to return from CORBA methods
// to aid in debugging.  Note that you can specify
// the return value after the macro, for example:
// METHOD_RETURN(Plugh::plover) xyzzy; is equivalent
// to return xyzzy;
// METHOD_RETURN(Plugh::troll); is equivalent to
// return;
// WARNING: THIS GENERATES TWO STATEMENTS!!! THE FOLLOWING
// will not do what you want it to:
//  if (cave_is_closing) METHOD_RETURN(Plugh::pirate) aarrggh;
// Moral:  Always use braces.
#define METHOD_RETURN(name)   \
  if (TAO_debug_level > 6)    \
  {                           \
    ORBSVCS_DEBUG (( LM_DEBUG,    \
      "Leave %s\n", #name     \
      ));                     \
  }                           \
  return /* value goes here */


TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_FT_Naming_Manager::TAO_FT_Naming_Manager ()
  : factory_registry_ ("NamingManager::FactoryRegistry"),
    group_factory_ (),
    use_global_ (false),
    global_strategy_ (::FT_Naming::ROUND_ROBIN),
    built_in_balancing_strategy_name_ (1),
    object_group_property_name_ (1)
{
  // The name for the property which contains the load balancing strategy value
  this->built_in_balancing_strategy_name_.length (1);
  this->built_in_balancing_strategy_name_[0].id =
    ::FT_Naming::TAO_FT_LOAD_BALANCING_STRATEGY;

  // The name for the property which contains the object group name
  this->object_group_property_name_.length (1);
  this->object_group_property_name_[0].id =
    ::FT_Naming::TAO_FT_OBJECT_GROUP_NAME;
}

TAO_FT_Naming_Manager::~TAO_FT_Naming_Manager ()
{
  this->object_group_property_name_.length (0);
  this->built_in_balancing_strategy_name_.length (0);
}

void
TAO_FT_Naming_Manager::set_global_strategy (const ACE_TCHAR *name)
{
  if (ACE_OS::strcasecmp (name, ACE_TEXT ("round")) == 0 ||
      ACE_OS::strcasecmp (name, ACE_TEXT ("round_robin")) == 0)
    {
      this->use_global_ = true;
      this->global_strategy_ = ::FT_Naming::ROUND_ROBIN;
    }
  else if (ACE_OS::strcasecmp (name, ACE_TEXT ("random")) == 0)
    {
      this->use_global_ = true;
      this->global_strategy_ = ::FT_Naming::RANDOM;
    }
  else
    {
      this->use_global_ = false;
      ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) Unrecognized load balancing ")
                      ACE_TEXT ("strategy %C\n"),
                      name));
    }
}

CORBA::Object_ptr
TAO_FT_Naming_Manager::create_object_group (
    const char * group_name,
    ::FT_Naming::LoadBalancingStrategyValue lb_strategy,
    const ::PortableGroup::Criteria & the_criteria)
{
  // Make sure the object group does not already exist.
  TAO::PG_Object_Group* group;
  if (this->group_factory_.find_group_with_name (group_name,
                                                 group))
    {
      throw PortableGroup::ObjectNotCreated ();
    }

  if (lb_strategy != FT_Naming::ROUND_ROBIN &&
      lb_strategy != FT_Naming::RANDOM)
    {
      throw PortableGroup::ObjectNotCreated ();
    }

  // When creating the object group, it starts as a generic
  // CORBA Object. It will become the type of the first added
  // member.
  const char * type_id = "IDL:omg.org:CORBA/Object:1.0";

  // Add the group name to the criteria and create the object
  TAO::PG_Property_Set property_set (the_criteria);
  PortableGroup::Value value;
  value <<= group_name;
  property_set.set_property (::FT_Naming::TAO_FT_OBJECT_GROUP_NAME, value);

  // Add the load balancing strategy to the properties
  value <<= lb_strategy;
  property_set.set_property (::FT_Naming::TAO_FT_LOAD_BALANCING_STRATEGY, value);

  PortableGroup::Criteria new_criteria;
  property_set.export_properties (new_criteria);
  PortableGroup::GenericFactory::FactoryCreationId_var fcid;

  return this->create_object (group_name, type_id, new_criteria, fcid.out());
}

void
TAO_FT_Naming_Manager::delete_object_group (const char * group_name)
{
  // Find the object group with the specified name and delete the object
  PortableGroup::ObjectGroup_var group =
    this->get_object_group_ref_from_name (group_name);

  if (!CORBA::is_nil (group.in()))
  {
    PortableGroup::ObjectGroupId group_id =
      this->get_object_group_id (group.in ());

    // Delete the object group from the factory
    this->group_factory_.delete_group (group_id);
  }
  else
  {
    throw PortableGroup::ObjectGroupNotFound ();
  }

}

PortableGroup::ObjectGroup_ptr
TAO_FT_Naming_Manager::get_object_group_ref_from_name (const char * group_name)
{
  TAO::PG_Object_Group* group;
  if (this->group_factory_.find_group_with_name (group_name, group))
  {
    return group->reference ();
  }
  else
  {
    throw PortableGroup::ObjectGroupNotFound ();
  }
}

::FT_Naming::GroupNames *
TAO_FT_Naming_Manager::groups (::FT_Naming::LoadBalancingStrategyValue target_strategy)
{
  PortableGroup::ObjectGroups_var all_groups = this->group_factory_.all_groups ();
  int num_groups = all_groups->length ();

  ::FT_Naming::GroupNames* group_names;
  ACE_NEW_THROW_EX (
    group_names,
    ::FT_Naming::GroupNames (num_groups),
    CORBA::NO_MEMORY());

  int matching_groups = 0;
  for (int i = 0; i < num_groups; ++i)
  {
    PortableGroup::ObjectGroup_var obj_group = (all_groups.in ())[i].in ();

    // Extract the group's Load Balancing property
    PortableGroup::Name lb_strat_property_name (1);
    lb_strat_property_name.length (1);
    lb_strat_property_name[0].id =
      CORBA::string_dup (::FT_Naming::TAO_FT_LOAD_BALANCING_STRATEGY);
    PortableGroup::Properties_var props =
      this->get_properties (obj_group.in ());
    PortableGroup::Value value;
    if (!TAO_PG::get_property_value (lb_strat_property_name, props.in (), value))
      {
        (*group_names)[i] =
          CORBA::string_dup ("<group without LB property>");
        ORBSVCS_ERROR ((LM_ERROR,
                    ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::groups: no LB ")
                    ACE_TEXT ("property set on group.\n")
                    ));
        continue;
      }

    ::FT_Naming::LoadBalancingStrategyValue lb_strategy_val;
    value >>= lb_strategy_val;

    if (lb_strategy_val == target_strategy)
    { // Groups load balancing strategy matches the target
      // Increment the count of matching groups
      ++matching_groups;
      char* name;

      // Get the group name and add it to the list to return.
      if (this->group_name (obj_group.in (), name))
      { // Group does have a name
        group_names->length (matching_groups);
        (*group_names)[matching_groups-1] = name;
      }
      else
      {
        { // Group has no name
          (*group_names)[i] = CORBA::string_dup ("<unnamed group>");
          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::groups: no name ")
                      ACE_TEXT ("property set on group.\n")
            ));
        }
      }
    }
  }
  // Set the length to the actual num added
  group_names->length (matching_groups);
  return group_names;
}

void
TAO_FT_Naming_Manager::set_load_balancing_strategy (
  const char * group_name,
  ::FT_Naming::LoadBalancingStrategyValue lb_strategy)
{
  CORBA::Object_var group = this->get_object_group_ref_from_name (group_name);

  TAO::PG_Property_Set property_set;
  PortableGroup::Value value;
  // Add the load balancing strategy to the properties
  value <<= lb_strategy;
  property_set.set_property (::FT_Naming::TAO_FT_LOAD_BALANCING_STRATEGY,
                             value);
  PortableGroup::Properties properties;
  property_set.export_properties (properties);
  this->set_properties_dynamically (group.in (), properties);
}


bool
TAO_FT_Naming_Manager::group_name (PortableGroup::ObjectGroup_ptr group,
                                   char*& name)
{
  if (CORBA::is_nil (group))
  {
    ORBSVCS_ERROR ((LM_ERROR,
                ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::group_name: ")
                ACE_TEXT ("cannot get name for a null object.\n")
      ));
    return false;
  }

  TAO::PG_Object_Group* pg_group;
  if (this->group_factory_.find_group (group, pg_group))
  { // Found the object group in the factory
    const char* grp_name = pg_group->get_name ();
    if (grp_name != 0)
    { // Valid group name defined
      name = CORBA::string_dup (grp_name);
      return true;
    }
    else
    { // The group has no name
      ORBSVCS_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("TAO_FT_Naming_Manager::group_name - ")
                         ACE_TEXT ("object group does not have a name")),
                        false);
    }
  }
  else
  { // The factory does not know about the group
    return false;
  }
}

void
TAO_FT_Naming_Manager::set_default_properties (
    const PortableGroup::Properties & props)
{

  this->properties_support_.set_default_properties (props);
  //@@ validate properties?
}

PortableGroup::Properties *
TAO_FT_Naming_Manager::get_default_properties ()
{
  return this->properties_support_.get_default_properties ();
}

void
TAO_FT_Naming_Manager::remove_default_properties (
    const PortableGroup::Properties & props)
{
  this->properties_support_.remove_default_properties (props);
}

void
TAO_FT_Naming_Manager::set_type_properties (
    const char *type_id,
    const PortableGroup::Properties & overrides)
{
  this->properties_support_.set_type_properties (
    type_id,
    overrides);
}

PortableGroup::Properties *
TAO_FT_Naming_Manager::get_type_properties (
    const char *type_id)
{
  return this->properties_support_.get_type_properties (type_id);
}

void
TAO_FT_Naming_Manager::remove_type_properties (
    const char *type_id,
    const PortableGroup::Properties & props)
{
  this->properties_support_.remove_type_properties (
    type_id,
    props);
}

void
TAO_FT_Naming_Manager::set_properties_dynamically (
    PortableGroup::ObjectGroup_ptr object_group,
    const PortableGroup::Properties & overrides)
{

  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    group->set_properties_dynamically (overrides);
  }
  else
  {
    throw PortableGroup::ObjectGroupNotFound ();
  }
}

PortableGroup::Properties *
TAO_FT_Naming_Manager::get_properties (
    PortableGroup::ObjectGroup_ptr object_group)
{
  PortableGroup::Properties_var result;
  ACE_NEW_THROW_EX (result, PortableGroup::Properties(), CORBA::NO_MEMORY ());

  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    group->get_properties (result);
  }
  else
  {
    throw PortableGroup::ObjectGroupNotFound ();
  }
  return result._retn();
}

PortableGroup::ObjectGroup_ptr
TAO_FT_Naming_Manager::create_member (
    PortableGroup::ObjectGroup_ptr object_group,
    const PortableGroup::Location & the_location,
    const char * type_id,
    const PortableGroup::Criteria & the_criteria)
{
  PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil();
  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    group->create_member (the_location, type_id, the_criteria);
    result = group->reference ();
  }
  else
  {
    if (TAO_debug_level > 0)
    {
      ORBSVCS_ERROR ( (LM_ERROR,
                   ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::create_member: ")
                   ACE_TEXT ("unknown group\n")
        ));
    }
    throw PortableGroup::ObjectGroupNotFound ();
  }
  return result._retn();
}

PortableGroup::ObjectGroup_ptr
TAO_FT_Naming_Manager::add_member (
    PortableGroup::ObjectGroup_ptr object_group,
    const PortableGroup::Location & the_location,
    CORBA::Object_ptr member)
{
  METHOD_ENTRY (TAO::FT_Naming_Manager::add_member);

  if (CORBA::is_nil (object_group))
    {
      if (TAO_debug_level > 3)
        {
          ORBSVCS_ERROR (
            (LM_ERROR,
             ACE_TEXT ("TAO (%P|%t) - TAO_FT_Naming_Manager::add_member")
             ACE_TEXT ("Null object group provided.\n")
             ));
        }
      throw PortableGroup::ObjectGroupNotFound ();
    }

  PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();

  // Find the object group corresponding to this IOGR
  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    try {

      group->add_member (the_location,
                         member);
    }
    catch (...)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO_FT_Naming_Manager::add_member - ")
                  ACE_TEXT ("Issue with IOR of group or member.\n")));
      throw PortableGroup::ObjectNotAdded ();
    }

    result = group->reference ();

  }
  else
  {
    if (TAO_debug_level > 0)
    {
      ORBSVCS_ERROR ( (LM_ERROR,
                   ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::add_member ")
                   ACE_TEXT ("to unknown group\n")
        ));
    }
    throw PortableGroup::ObjectGroupNotFound ();
  }
  METHOD_RETURN (TAO::FT_Naming_Manager::add_member) result._retn ();
}


PortableGroup::ObjectGroup_ptr
TAO_FT_Naming_Manager::remove_member (
    PortableGroup::ObjectGroup_ptr object_group,
    const PortableGroup::Location & the_location)
{
  if (CORBA::is_nil (object_group))
    {
      if (TAO_debug_level > 3)
        {
          ORBSVCS_ERROR (
            (LM_ERROR,
             ACE_TEXT ("TAO (%P|%t) - TAO_FT_Naming_Manager::add_member")
             ACE_TEXT ("Null object group provided.\n")
             ));
        }
      throw PortableGroup::ObjectGroupNotFound ();
    }

  PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();

  // Find the object group corresponding to this IOGR
  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    group->remove_member (the_location);

    group->minimum_populate ();
      //@@ how about the case where the member was removed successfully,
      // but for one reason or another we were unable to bring the group
      // back up to minimum_number_of_replicas?

    result = group->reference ();
  }
  else
  {
    throw PortableGroup::ObjectGroupNotFound ();
  }
  return result._retn ();
}


PortableGroup::Locations *
TAO_FT_Naming_Manager::locations_of_members (
    PortableGroup::ObjectGroup_ptr object_group)
{
  if (CORBA::is_nil (object_group))
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO_FT_Naming_Manager::locations_of_members ")
                  ACE_TEXT ("- null object group passed.\n")));
      throw PortableGroup::ObjectGroupNotFound ();
    }

  PortableGroup::Locations_var result = 0;

  // Find the object group corresponding to this IOGR
  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    result = group->locations_of_members ();
  }
  else
  {
    if (TAO_debug_level > 0)
    {
      ORBSVCS_ERROR ( (LM_ERROR,
                   ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::")
                   ACE_TEXT ("locations_of_members: unknown group\n")
        ));
    }
    throw PortableGroup::ObjectGroupNotFound ();
  }
  return result._retn ();
}

PortableGroup::ObjectGroups *
TAO_FT_Naming_Manager::groups_at_location (
    const PortableGroup::Location & the_location)
{
  return this->group_factory_.groups_at_location (the_location);
}

PortableGroup::ObjectGroupId
TAO_FT_Naming_Manager::get_object_group_id (
    PortableGroup::ObjectGroup_ptr object_group)
{

  if (CORBA::is_nil (object_group))
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO_FT_Naming_Manager::get_object_group_id ")
                  ACE_TEXT ("- null object group passed.\n")));
      throw PortableGroup::ObjectGroupNotFound ();
    }

  PortableGroup::ObjectGroupId result = 0;
  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    group->get_object_group_id ();
    result = group->get_object_group_id ();
  }
  else
  {
    if (TAO_debug_level > 0)
    {
      ORBSVCS_ERROR ( (LM_ERROR,
                   ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::")
                   ACE_TEXT ("get_object_group_id: unknown group\n")
        ));
    }
    throw PortableGroup::ObjectGroupNotFound ();
  }
  return result;
}

PortableGroup::ObjectGroup_ptr
TAO_FT_Naming_Manager::get_object_group_ref (
    PortableGroup::ObjectGroup_ptr object_group)
{
  if (CORBA::is_nil (object_group))
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO_FT_Naming_Manager::get_object_group_ref ")
                  ACE_TEXT ("- null object group passed.\n")));
      throw PortableGroup::ObjectGroupNotFound ();
    }

  PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();

  // Find the object group corresponding to this IOGR
  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    result = group->reference ();
  }
  else
  {
    if (TAO_debug_level > 0)
    {
      ORBSVCS_ERROR ( (LM_ERROR,
                   ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::")
                   ACE_TEXT ("get_object_group_ref: unknown group\n")
        ));
    }
    throw PortableGroup::ObjectGroupNotFound ();
  }
  return result._retn();
}

PortableGroup::ObjectGroup_ptr TAO_FT_Naming_Manager::get_object_group_ref_from_id (
    PortableGroup::ObjectGroupId group_id)
{
  PortableGroup::ObjectGroup_var result = PortableGroup::ObjectGroup::_nil ();

  // Find the object group corresponding to this IOGR
  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (group_id, group))
  {
    result = group->reference ();
  }
  else
  {
    if (TAO_debug_level > 0)
    {
      ORBSVCS_ERROR ( (LM_ERROR,
                   ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::")
                   ACE_TEXT ("get_object_group_ref_from_id: unknown group\n")
        ));
    }
    throw PortableGroup::ObjectGroupNotFound ();
  }
  return result._retn();
}

CORBA::Object_ptr
TAO_FT_Naming_Manager::get_member_ref (
    PortableGroup::ObjectGroup_ptr object_group,
    const PortableGroup::Location & the_location)
{

  if (CORBA::is_nil (object_group))
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO_FT_Naming_Manager::get_member_ref ")
                  ACE_TEXT ("- null object group passed.\n")));
      throw PortableGroup::ObjectGroupNotFound ();
    }

  CORBA::Object_var result = CORBA::Object::_nil();

  // Find the object group corresponding to this IOGR
  TAO::PG_Object_Group * group = 0;
  if (this->group_factory_.find_group (object_group, group))
  {
    result = group->get_member_reference (the_location);
  }
  else
  {
    if (TAO_debug_level > 0)
    {
      ORBSVCS_ERROR ( (LM_ERROR,
                   ACE_TEXT ("TAO (%P|%t) - FT_Naming_Manager::")
                   ACE_TEXT ("get_member_ref: unknown group\n")
        ));
    }
    throw PortableGroup::ObjectGroupNotFound ();
  }
  return result._retn();
}

CORBA::Object_ptr
TAO_FT_Naming_Manager::create_object (
    const char * object_name,
    const char * type_id,
    const PortableGroup::Criteria & the_criteria,
    PortableGroup::GenericFactory::FactoryCreationId_out
      factory_creation_id)
{
  METHOD_ENTRY (TAO::FT_Naming_Manager::create_object);

  ////////////////////////////////
  // find the properties for this
  // type of object group
  TAO::PG_Property_Set_var typeid_properties =
    (this->properties_support_.find_typeid_properties (type_id));

  TAO::PG_Object_Group * group = this->group_factory_.create_group
    ( type_id, the_criteria, typeid_properties);

  group->set_name (object_name);

  // Dont distribute the object group for its usage in the FT_Naming_Manager
  group->distribute (0);

  group->initial_populate ();
    //@@ on error we should remove the group from the Group_Factory
    // doing this "right" will require a var-type pointer to the object group
    // that knows about the factory, too.

 // Allocate a new FactoryCreationId for use as an "out" parameter.
  PortableGroup::GenericFactory::FactoryCreationId_ptr factory_id_ptr = 0;
  ACE_NEW_THROW_EX (factory_id_ptr,
                    PortableGroup::GenericFactory::FactoryCreationId,
                    CORBA::NO_MEMORY (
                      CORBA::SystemException::_tao_minor_code (
                        TAO::VMCID,
                        ENOMEM),
                      CORBA::COMPLETED_NO));
  PortableGroup::GenericFactory::FactoryCreationId_var factory_id = factory_id_ptr;
  PortableGroup::ObjectGroupId group_id = group->get_object_group_id ();
  factory_id <<= group_id;
  factory_creation_id = factory_id._retn();

  METHOD_RETURN (TAO::FT_Naming_Manager::create_object) group->reference ();
}

void
TAO_FT_Naming_Manager::delete_object (
    const PortableGroup::GenericFactory::FactoryCreationId &
      factory_creation_id)
{

  PortableGroup::ObjectGroupId group_id = 0;
  if (factory_creation_id >>= group_id)
  {
    this->group_factory_.delete_group (
      group_id);
  }
  else
  {
    throw PortableGroup::ObjectNotFound ();
  }
}

void
TAO_FT_Naming_Manager::initialize (CORBA::ORB_ptr orb,
                                   PortableServer::POA_ptr naming_mgr_poa)
{
  // Initialize the components used to implement the PortableGroup interfaces
  this->factory_registry_.init (orb);
  PortableGroup::FactoryRegistry_var factory_ref =
    factory_registry_.reference ();
  this->group_factory_.init (orb,
                             naming_mgr_poa,
                             factory_ref.in ());
}

CORBA::Object_ptr
TAO_FT_Naming_Manager::next_member (PortableGroup::ObjectGroup_ptr object_group)
{
  if (CORBA::is_nil (object_group))
    {
      if (TAO_debug_level > 3)
        {
          ORBSVCS_ERROR (
            (LM_ERROR,
             ACE_TEXT ("TAO (%P|%t) - TAO_FT_Naming_Manager::next_member ")
             ACE_TEXT ("Null object group provided.\n")
             ));
        }
      throw PortableGroup::ObjectGroupNotFound ();
    }

  ::FT_Naming::LoadBalancingStrategyValue load_bal_strategy = this->global_strategy_;
  if (!this->use_global_)
    {
      ACE_Auto_Ptr<PortableGroup::Properties> props
        (this->get_properties (object_group));
      PortableGroup::Value value;
      CORBA::Boolean found =
        TAO_PG::get_property_value (built_in_balancing_strategy_name_,
                                    *(props.get ()),
                                    value);

      // If there is no TAO_FT_LOAD_BALANCING_STRATEGY property in the object group
      // return failure
      if (!found)
        {
          ORBSVCS_ERROR ((LM_ERROR,
                          ACE_TEXT ("TAO (%P|%t) - TAO_FT_Naming_Manager::next_member: ")
                          ACE_TEXT ("object group has no TAO_FT_LOAD_BALANCING_STRATEGY ")
                          ACE_TEXT ("property.\n")
                          ));

          return CORBA::Object::_nil();
        }

      // Extract the load balancing strategy value
      value >>= load_bal_strategy;
    }
  PortableGroup::Location next_location;

  bool result = false;

  switch (load_bal_strategy)
  {
  case ::FT_Naming::ROUND_ROBIN:
    result = this->round_robin_.next_location (object_group, this, next_location);
    break;
  case ::FT_Naming::RANDOM:
    result = this->random_.next_location (object_group, this, next_location);
    break;
  default:
    ORBSVCS_ERROR ((LM_ERROR,
                ACE_TEXT ("TAO (%P|%t) - TAO_FT_Naming_Manager::next_location: ")
                ACE_TEXT ("unsupported load balancing strategy requested.\n")
               ));

    return CORBA::Object::_nil();
    break;
  }

  if (result == true)
    return this->get_member_ref (object_group, next_location);
  else
    return CORBA::Object::_nil();
}


void
TAO_FT_Naming_Manager::preprocess_properties (PortableGroup::Properties &)
{
  // Nothing to do here for now.
}

void
TAO_FT_Naming_Manager::set_object_group_storable_factory (TAO::Storable_Factory * factory)
{
  this->group_factory_.set_object_group_storable_factory (factory);
}

void
TAO_FT_Naming_Manager::set_object_group_stale (const FT_Naming::ObjectGroupUpdate & group_info)
{
  this->group_factory_.set_object_group_stale (group_info);
}

void
TAO_FT_Naming_Manager::set_replicator (TAO_FT_Naming_Replication_Manager *repl)
{
  this->group_factory_.set_replicator (repl);
}

TAO_END_VERSIONED_NAMESPACE_DECL