summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/FT_ReplicationManager/FT_FaultConsumer.cpp
blob: 22d323e238862f99f8ed51c67448297f75343e3b (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
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file    FT_FaultConsumer.cpp
 *
 *  $Id$
 *
 *  This file is part of TAO's implementation of Fault Tolerant CORBA.
 *  This file provides the implementation of the TAO::FT_FaultConsumer
 *  class.  The TAO::FT_FaultConsumer connects to the FaultNotifier to
 *  receive fault reports.  It interacts with the ReplicationManager
 *  to process fault reports (e.g., to set a new primary on an object
 *  group or to create a new member of an object group).
 *
 *  @author Steve Totten <totten_s@ociweb.com>
 */
//=============================================================================

#include "orbsvcs/FT_ReplicationManager/FT_FaultConsumer.h"
#include "orbsvcs/FT_ReplicationManagerC.h"
#include "orbsvcs/PortableGroup/PG_Property_Utils.h"
#include <tao/debug.h>

ACE_RCSID (FT_FaultConsumer,
           FT_FaultConsumer,
           "$Id$")

/// Default constructor.
TAO::FT_FaultConsumer::FT_FaultConsumer ()
  : poa_ (PortableServer::POA::_nil ())
  , fault_notifier_ (FT::FaultNotifier::_nil ())
  , replication_manager_ (FT::ReplicationManager::_nil ())
  , consumer_id_ (0)
  , consumer_ref_ (CosNotifyComm::StructuredPushConsumer::_nil ())
  , notifications_ (0)
{
}

/// Destructor.
TAO::FT_FaultConsumer::~FT_FaultConsumer ()
{
}

/**
* Connect to the FT::FaultNotifier.
* Note: We make the following assumptions about what the
* application will do:
* - Create an instance of this consumer class.
* - Obtain the object reference of the FaultNotifier to which this
*   consumer should connect.
* - Call this init() method, passing it the POA with which we
*   have been activated, the FaultNotifier, and ReplicationManager
*   object references.
*/
int TAO::FT_FaultConsumer::init (
  PortableServer::POA_ptr poa,
  FT::FaultNotifier_ptr fault_notifier,
  FT::ReplicationManager_ptr replication_manager
  ACE_ENV_ARG_DECL)
{
  ACE_ASSERT (!CORBA::is_nil (poa));
  ACE_ASSERT (!CORBA::is_nil (fault_notifier));
  ACE_ASSERT (!CORBA::is_nil (replication_manager));

  // Duplicate the object references passed in.
  this->poa_ =
    PortableServer::POA::_duplicate (poa);
  this->fault_notifier_ =
    FT::FaultNotifier::_duplicate (fault_notifier);
  this->replication_manager_ =
    FT::ReplicationManager::_duplicate (replication_manager);

  //@@ Should this init() method activate the consumer in the POA, or
  // should the application do that?
  // I don't think this object can activate itself because it doesn't
  // know the policies on the POA.  So, we assume the application has
  // already activated us.
  //@@ For now, let's try just activating it in the POA.

  // Activate this consumer in the POA.
  this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);
  CORBA::Object_var obj =
    this->poa_->id_to_reference (this->object_id_.in() ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Narrow it to CosNotifyComm::StructuredPushConsumer.
  this->consumer_ref_ = CosNotifyComm::StructuredPushConsumer::_narrow (
    obj.in() ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Subscribe to the FaultNotifier.
  CosNotifyFilter::Filter_var filter = CosNotifyFilter::Filter::_nil ();
  this->consumer_id_ = fault_notifier_->connect_structured_fault_consumer (
    this->consumer_ref_.in(), filter ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Success.
  return 0;
}

/**
* Clean house for process shut down.
* - Disconnect from FT::FaultNotifier.
* - Deactivate from the POA.
*/
int TAO::FT_FaultConsumer::fini (ACE_ENV_SINGLE_ARG_DECL)
{
  // Disconnect from the FaultNotifier.
  this->fault_notifier_->disconnect_consumer (this->consumer_id_
                                              ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  //@@ Should this fini() method deactivate the consumer from the POA, or
  // should the application do that?
  //
  // Deactivate ourselves from the POA.
  this->poa_->deactivate_object (this->object_id_.in() ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  this->consumer_ref_ = CosNotifyComm::StructuredPushConsumer::_nil ();

  // Success.
  return 0;
}

CosNotifyComm::StructuredPushConsumer_ptr
TAO::FT_FaultConsumer::consumer_ref ()
{
  return CosNotifyComm::StructuredPushConsumer::_duplicate (
      this->consumer_ref_);
}

size_t TAO::FT_FaultConsumer::notifications () const
{
  return this->notifications_;
}


////////////////
// CORBA methods

// Receive and process an incoming fault event from the Fault Notifier.
// First, we validate the event to make sure it is something we can
// handle.  Then, we analyze it.
// If it is not an event we can handle, we simply log the error and
// drop the event.
void TAO::FT_FaultConsumer::push_structured_event (
  const CosNotification::StructuredEvent &event
  ACE_ENV_ARG_DECL_WITH_DEFAULTS
  )
  ACE_THROW_SPEC ((CORBA::SystemException, CosEventComm::Disconnected))
{
  // Debugging support.
  this->notifications_ += 1;
#if (TAO_DEBUG_LEVEL_NEEDED == 1)
  if (TAO_debug_level > 1)
#endif /* (TAO_DEBUG_LEVEL_NEEDED == 1) */
  {
    ACE_DEBUG ((LM_DEBUG,
      ACE_TEXT (
        "TAO::FT_FaultConsumer::push_structured_event: "
        "Received Fault notification(%d):\n"),
      ACE_static_cast (unsigned int, this->notifications_)
    ));
  }

  int result = 0;

  // Make sure it is an event type we can handle.
  if (result == 0)
  {
    result = this->validate_event_type (event);
    if (result != 0)
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::push_structured_event: "
          "Received invalid fault event type.\n")
      ));
    }
  }

  // Analyze the event.
  if (result == 0)
  {
    TAO::FT_FaultEventDescriptor fault_event_desc;

    // Make sure we catch and swallow any CORBA exceptions locally
    // so they do not propagate back to the Fault Notifier.
    ACE_TRY_NEW_ENV
    {
      result = this->analyze_fault_event (
        event,
        fault_event_desc
        ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
      if (result != 0)
      {
        ACE_ERROR ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_FaultConsumer::push_structured_event: "
            "Could not analyze fault event.\n")
        ));
      }
    }
    ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::push_structured_event: "
          "Could not analyze fault event.\n")
      );
    }
    ACE_CHECK_RETURN (-1);
    ACE_ENDTRY;

    // Debugging support.
#if (TAO_DEBUG_LEVEL_NEEDED == 1)
    if (TAO_debug_level > 6)
#endif /* (TAO_DEBUG_LEVEL_NEEDED == 1) */
    {
      ACE_DEBUG ((LM_DEBUG,
        ACE_TEXT("Getting the location as a string.\n")
      ));

      // Get the location as a string.
      ACE_CString loc_as_string;
      FT::Location_var & loc = fault_event_desc.location;

      for (CORBA::ULong li = 0; li < loc->length(); ++li)
      {
        if (li > 0) loc_as_string += "/";
        // Assume only the "id" field of the CosNaming::Name is used.
        loc_as_string += CORBA::string_dup (loc[li].id);
      }

      if (fault_event_desc.all_at_location_failed == 1)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "All objects at location <%s> failed.\n"),
            loc_as_string.c_str()
        ));
      }

      if (fault_event_desc.all_of_type_at_location_failed == 1)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "All objects of type <%s> at location <%s> failed.\n"),
            fault_event_desc.type_id.in(),
            loc_as_string.c_str()
        ));
      }

      if (fault_event_desc.object_at_location_failed == 1)
      {
        ACE_DEBUG ((LM_DEBUG,
          ACE_TEXT (
            "Replica of type <%s> with ObjectGroupId <%Q> "
            "at location <%s> failed.\n"),
            fault_event_desc.type_id.in(),
            fault_event_desc.object_group_id,
            loc_as_string.c_str()
        ));
      }
    }
  }

  return;
}


void TAO::FT_FaultConsumer::offer_change (
    const CosNotification::EventTypeSeq & added,
    const CosNotification::EventTypeSeq & removed
    ACE_ENV_ARG_DECL_WITH_DEFAULTS
  )
  ACE_THROW_SPEC ((CORBA::SystemException, CosNotifyComm::InvalidEventType))
{
  ACE_DEBUG ((LM_DEBUG,
    ACE_TEXT("TAO::FT_FaultConsumer::offer_change() call ignored.\n")
  ));
}

void TAO::FT_FaultConsumer::disconnect_structured_push_consumer (
    ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS
  )
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  //TODO: For now, we are just ignoring the disconnect callback.
  ACE_DEBUG ((LM_DEBUG,
    ACE_TEXT("TAO::FT_FaultConsumer::disconnect_structured_push_consumer() "
             "call ignored.\n")
    ));
}

//////////////////
// Private methods

// Validate the event to make sure it is one we can handle.
// If it is not an event we can handle, this function logs the error
// and returns -1.
int TAO::FT_FaultConsumer::validate_event_type (
  const CosNotification::StructuredEvent & event)
{
  int result = 0;

  // CORBA 3.0.2, section 23.4.5.1 states:
  //
  //   The fault management specification defines one event type:
  //   ObjectCrashFault. As the name suggests, this event is
  //   generated by a Fault Detector when it detects that an object
  //   has crashed.

  // So, the event header's event_type.domain_name must be "FT_CORBA"
  // and the event header's event_type.type_name must be "ObjectCrashFault".
  CORBA::String_var domain_name = CORBA::string_dup (
    event.header.fixed_header.event_type.domain_name);
  CORBA::String_var type_name = CORBA::string_dup (
      event.header.fixed_header.event_type.type_name);
  CORBA::String_var event_name = CORBA::string_dup (
      event.header.fixed_header.event_name);

  if (result == 0)
  {
    //TODO: Get rid of magic strings (though they come from the spec).
    if (ACE_OS::strcmp (domain_name.in(), "FT_CORBA") != 0 ||
        ACE_OS::strcmp (type_name.in(), "ObjectCrashFault") != 0)
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::validate_event_type: "
          "Received invalid event type.\n"
          "EventType domain: <%s>\n"
          "EventType type: <%s>\n"
          "EventName: <%s>\n"),
        domain_name.in(),
        type_name.in(),
        event_name.in()
      ));
      result = -1;
    }
  }

  // CORBA 3.0.2, section 23.4.5.1 also states:
  //
  //   The filterable_data part of the event body contains the
  //   identity of the crashed object as four name-value pairs: the
  //   fault tolerance domain identifier, the member’s location
  //   identifier, the repository identifier and the object group
  //   identifier. The Fault Notifier filters events based on the
  //   domain_name, the type_name, and the four identifiers.  All
  //   other fields of the structured event may be set to null.
  //
  //   The Fault Detector always sets the following fault event
  //   fields: domain_name, type_name, FTDomainId, and Location.
  //
  // So, at least "FTDomainId" and "Location" must be present:
  if (result == 0)
  {
    if (event.filterable_data.length () >= 2)
    {
      // Check for FTDomainId.
      if (ACE_OS::strcmp (
            event.filterable_data[0].name.in(), "FTDomainId") != 0)
      {
        ACE_ERROR ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_FaultConsumer::validate_event_type: "
            "Received invalid structured event.\n"
            "filterable_data[0] must be \"FTDomainId\", not \"%s\"\n"),
          event.filterable_data[0].name.in()
        ));
        result = -1;
      }
      else if (ACE_OS::strcmp (
            event.filterable_data[1].name.in(), "Location") != 0)
      {
        ACE_ERROR ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_FaultConsumer::validate_event_type: "
            "Received invalid structured event.\n"
            "filterable_data[1] must be \"Location\", not \"%s\"\n"),
          event.filterable_data[1].name.in()
        ));
        result = -1;
      }
    }
    else
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::validate_event_type: "
          "Received invalid structured event.\n"
          "There must be at least two name/value pairs in "
          "the filterable_data field, for \"FTDomainId\" and \"Location\".\n")
      ));
      result = -1;
    }
  }

  return result;
}

/// Analyze a fault event.
int TAO::FT_FaultConsumer::analyze_fault_event (
  const CosNotification::StructuredEvent & event,
  TAO::FT_FaultEventDescriptor & fault_event_desc
  ACE_ENV_ARG_DECL_WITH_DEFAULTS
  )
  ACE_THROW_SPEC ((CORBA::SystemException, CosEventComm::Disconnected))
{
  int result = 0;

  const CosNotification::FilterableEventBody & filterable =
    event.filterable_data;
  CORBA::ULong item_count = filterable.length ();
#if (TAO_DEBUG_LEVEL_NEEDED == 1)
  if (TAO_debug_level > 6)
#endif /* (TAO_DEBUG_LEVEL_NEEDED == 1) */
  {
    for (CORBA::ULong n_prop = 0; n_prop < item_count; ++n_prop)
    {
      ACE_DEBUG ((LM_DEBUG,
        ACE_TEXT("TAO::FT_FaultConsumer::analyze_fault_event: "
                 "Property Name: <%s>\n"),
        filterable[n_prop].name.in()
      ));
    }
  }

  //
  // Populate the TAO::FT_FaultEventDescriptor structure from the
  // properties in the event.
  //

  // Extract the location.
  if (result == 0)
  {
    FT::Location* temp_loc;
    if ((filterable[1].value >>= temp_loc) == 0)
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::analyze_fault_event: "
          "Could not extract Location value from fault event.\n")
      ));
      result = -1;
    }
    else
    {
      // Make a deep copy of the Location.
      FT::Location* copy_loc = 0;
      ACE_NEW_RETURN (copy_loc, FT::Location (*temp_loc), -1);
      fault_event_desc.location = copy_loc;
    }
  }

  // CORBA 3.0.2, section 23.4.5.1 states:
  //
  //   The fault detector may or may not set the TypeId and
  //   ObjectGroupId fields with the following interpretations:
  //   - Neither is set if all objects at the given location have failed.
  //   - TypeId is set and ObjectGroupId is not set if all objects at
  //     the given location with the given type have failed.
  //   - Both are set if the member with the given ObjectGroupId at the
  //     given location has failed.
  if (result == 0)
  {
    // All objects at location failed.
    if (item_count == 2)
    {
      fault_event_desc.all_at_location_failed = 1;
    }

    // All objects of type at location failed.
    if (item_count == 3)
    {
      fault_event_desc.all_of_type_at_location_failed = 1;
      fault_event_desc.type_id = this->extract_type_id (filterable[2].value);
    }

    // An object (replica) at a location failed.
    if (item_count == 4)
    {
      fault_event_desc.object_at_location_failed = 1;
      fault_event_desc.type_id = this->extract_type_id (filterable[2].value);
      fault_event_desc.object_group_id =
        this->extract_object_group_id (filterable[3].value);
    }
  }

  //TODO: Finish the implementation of analyze_fault_event() to:
  // - if the ReplicationStyle of the object group is FT::SEMI_ACTIVE,
  //   and if the failed replica was the primary replica, set a new
  //   primary replica
  // - if the number of replicas falls below MinimumNumberReplicas
  //   property and MembershipStyle of the object group is FT::MEMB_INF_CTRL,
  //   create and add a new member.

  //@@ Q: How do we get the ObjectGroup from the ObjectGroupId?
  //@@ A: Use TAO-specific extension to PortableGroup::ObjectGroupManager
  // interface (get_object_group_ref_from_id()).
#if (INTEGRATED_WITH_REPLICATION_MANAGER == 1)
  if ((fault_event_desc.object_at_location_failed == 1) && (result == 0))
  {
    FT::ObjectGroup_var the_object_group =
      this->replication_manager_->get_object_group_ref_from_id (
        fault_event_desc.object_group_id
        ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);
    if (CORBA::is_nil (the_object_group.in()))
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::analyze_fault_event: "
          "Could not get ObjectGroup reference from ObjectGroupId: <%Q>.\n"),
          fault_event_desc.object_group_id
      ));
      result = -1;
    }

    //@@ Q: How do we get the properties of the ObjectGroup to
    // figure out the ReplicationStyle, current primary,
    // MinimumNumberReplicas, etc.?
    //@@ A: FT::PropertyManager::get_properties().

    // Get the properties associated with this ObjectGroup.
    FT::Properties_var properties;
    if (result == 0)
    {
      properties = this->replication_manager_->get_properties (
        the_object_group.in()
        ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (-1);

      // Get the MembershipStyle property.
      FT::MembershipStyleValue membership_style;
      result = this->get_membership_style (properties.in(), membership_style);
      if (result != 0)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_FaultConsumer::analyze_fault_event: "
            "Could not extract MembershipStyle from properties on "
            "ObjectGroup with id <%Q>.\n"),
          fault_event_desc.object_group_id),
          -1);
      }
      else
      {
        fault_event_desc.membership_style = membership_style;
      }

      // Get the ReplicationStyle property.
      FT::ReplicationStyleValue replication_style;
      result = this->get_replication_style (properties.in(), replication_style);
      if (result != 0)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_FaultConsumer::analyze_fault_event: "
            "Could not extract ReplicationStyle from properties on "
            "ObjectGroup with id <%Q>.\n"),
          fault_event_desc.object_group_id),
          -1);
      }
      else
      {
        fault_event_desc.replication_style = replication_style;
      }

      // Get the MinimumNumberReplicas property.
      FT::MinimumNumberReplicasValue minimum_number_replicas;
      result = this->get_minimum_number_replicas (
        properties.in(), minimum_number_replicas);
      if (result != 0)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_FaultConsumer::analyze_fault_event: "
            "Could not extract MinimumNumberReplicas from properties on "
            "ObjectGroup with id <%Q>.\n"),
          fault_event_desc.object_group_id),
          -1);
      }
      else
      {
        fault_event_desc.minimum_number_replicas = minimum_number_replicas;
      }

      // Get the InitialNumberReplicas property.
      FT::InitialNumberReplicasValue initial_number_replicas;
      result = this->get_initial_number_replicas (
        properties.in(), initial_number_replicas);
      if (result != 0)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
          ACE_TEXT (
            "TAO::FT_FaultConsumer::analyze_fault_event: "
            "Could not extract InitialNumberReplicas from properties on "
            "ObjectGroup with id <%Q>.\n"),
          fault_event_desc.object_group_id),
          -1);
      }
      else
      {
        fault_event_desc.initial_number_replicas = initial_number_replicas;
      }

    }
  }
#endif /* (INTEGRATED_WITH_REPLICATION_MANAGER == 1) */

  return result;
}

// Extract a string type_id from CORBA::Any.
// Caller owns the returned string.
char*
TAO::FT_FaultConsumer::extract_type_id (const CORBA::Any& val)
{
  const char* type_id_value;
  if ((val >>= type_id_value) == 0)
  {
    ACE_ERROR ((LM_ERROR,
      ACE_TEXT (
        "TAO::FT_FaultConsumer::extract_type_id: "
        "Could not extract TypeId value from any.\n")
    ));
    return 0;
  }

  return CORBA::string_dup (type_id_value);
}

// Extract the ObjectGroupId from CORBA::Any.
FT::ObjectGroupId
TAO::FT_FaultConsumer::extract_object_group_id (const CORBA::Any& val)
{
  FT::ObjectGroupId id = (FT::ObjectGroupId)0;
  if ((val >>= id) == 0)
  {
    ACE_ERROR ((LM_ERROR,
      ACE_TEXT (
        "TAO::FT_FaultConsumer::extract_object_group_id: "
        "Could not extract ObjectGroupId value from any.\n")
    ));
  }

  return id;
}

//
//TODO: Use TAO_PG::find() to get property values from properties
// instead of all these specific "get" functions.
//

// Get the MembershipStyle property.
int TAO::FT_FaultConsumer::get_membership_style (
  const FT::Properties & properties,
  FT::MembershipStyleValue & membership_style)
{
  FT::Name prop_name (1);
  prop_name.length (1);
  prop_name[0].id = CORBA::string_dup (FT::FT_MEMBERSHIP_STYLE);
  int result = 0;

  FT::Value value;
  if (TAO_PG::get_property_value (prop_name, properties, value)
    && ((value >>= membership_style) == 1))
  {
#if (TAO_DEBUG_LEVEL_NEEDED == 1)
    if (TAO_debug_level > 6)
#endif /* (TAO_DEBUG_LEVEL_NEEDED == 1) */
    {
      ACE_DEBUG ((LM_DEBUG,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::analyze_fault_event: "
          "MembershipStyle is <%d>:\n"),
        membership_style
      ));
    }
  }
  else
  {
    result = -1;
  }

  return result;
}

int TAO::FT_FaultConsumer::get_replication_style (
  const FT::Properties & properties,
  FT::ReplicationStyleValue & replication_style)
{
  FT::Name prop_name (1);
  prop_name.length (1);
  prop_name[0].id = CORBA::string_dup (FT::FT_REPLICATION_STYLE);
  int result = 0;

  FT::Value value;
  if (TAO_PG::get_property_value (prop_name, properties, value)
    && ((value >>= replication_style) == 1))
  {
#if (TAO_DEBUG_LEVEL_NEEDED == 1)
    if (TAO_debug_level > 6)
#endif /* (TAO_DEBUG_LEVEL_NEEDED == 1) */
    {
      ACE_DEBUG ((LM_DEBUG,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::analyze_fault_event: "
          "ReplicationStyle is <%d>:\n"),
        replication_style
      ));
    }
  }
  else
  {
    result = -1;
  }

  return result;
}

int TAO::FT_FaultConsumer::get_minimum_number_replicas (
  const FT::Properties & properties,
  FT::MinimumNumberReplicasValue & minimum_number_replicas)
{
  FT::Name prop_name (1);
  prop_name.length (1);
  prop_name[0].id = CORBA::string_dup (FT::FT_MINIMUM_NUMBER_REPLICAS);
  int result = 0;

  FT::Value value;
  if (TAO_PG::get_property_value (prop_name, properties, value)
    && ((value >>= minimum_number_replicas) == 1))
  {
#if (TAO_DEBUG_LEVEL_NEEDED == 1)
    if (TAO_debug_level > 6)
#endif /* (TAO_DEBUG_LEVEL_NEEDED == 1) */
    {
      ACE_DEBUG ((LM_DEBUG,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::analyze_fault_event: "
          "MinimumNumberReplicas is <%d>:\n"),
        minimum_number_replicas
      ));
    }
  }
  else
  {
    result = -1;
  }

  return result;
}

int TAO::FT_FaultConsumer::get_initial_number_replicas (
  const FT::Properties & properties,
  FT::InitialNumberReplicasValue & initial_number_replicas)
{
  FT::Name prop_name (1);
  prop_name.length (1);
  prop_name[0].id = CORBA::string_dup (FT::FT_INITIAL_NUMBER_REPLICAS);
  int result = 0;

  FT::Value value;
  if (TAO_PG::get_property_value (prop_name, properties, value)
    && ((value >>= initial_number_replicas) == 1))
  {
#if (TAO_DEBUG_LEVEL_NEEDED == 1)
    if (TAO_debug_level > 6)
#endif /* (TAO_DEBUG_LEVEL_NEEDED == 1) */
    {
      ACE_DEBUG ((LM_DEBUG,
        ACE_TEXT (
          "TAO::FT_FaultConsumer::analyze_fault_event: "
          "InitialNumberReplicas is <%d>:\n"),
        initial_number_replicas
      ));
    }
  }
  else
  {
    result = -1;
  }

  return result;
}