📄 ft_replicationmanagerfaultanalyzer.cpp
字号:
/* -*- C++ -*- */
//=============================================================================
/**
* @file FT_ReplicationManagerFaultAnalyzer.cpp
*
* FT_ReplicationManagerFaultAnalyzer.cpp,v 1.3 2003/12/30 23:53:58 wilson_d Exp
*
* This file is part of TAO's implementation of Fault Tolerant CORBA.
*
* @author Steve Totten <totten_s@ociweb.com>
*/
//=============================================================================
#include "FT_ReplicationManagerFaultAnalyzer.h"
#include "orbsvcs/CosNotifyCommC.h"
#include "orbsvcs/FT_NotifierC.h"
#include "orbsvcs/FT_ReplicationManager/FT_ReplicationManager.h"
#include "orbsvcs/FT_ReplicationManager/FT_FaultEventDescriptor.h"
#include "orbsvcs/PortableGroup/PG_Property_Utils.h"
#include "orbsvcs/PortableGroup/PG_Operators.h"
#include "orbsvcs/FaultTolerance/FT_IOGR_Property.h"
#include <tao/debug.h>
#include <iostream>
ACE_RCSID (FT_ReplicationManagerFaultAnalyzer,
FT_ReplicationManagerFaultAnalyzer,
"FT_ReplicationManagerFaultAnalyzer.cpp,v 1.3 2003/12/30 23:53:58 wilson_d Exp")
/// Constructor.
TAO::FT_ReplicationManagerFaultAnalyzer::FT_ReplicationManagerFaultAnalyzer (
const TAO::FT_ReplicationManager * replication_manager)
: replication_manager_ (
ACE_const_cast (TAO::FT_ReplicationManager *, replication_manager))
{
}
/// Destructor.
TAO::FT_ReplicationManagerFaultAnalyzer::~FT_ReplicationManagerFaultAnalyzer ()
{
}
// 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_ReplicationManagerFaultAnalyzer::validate_event_type (
const CosNotification::StructuredEvent & event)
{
// Delegate to base class.
//@@ Visual C++ 6.0 won't compile this if I include the namespace name
// on the base class.
// return TAO::FT_DefaultFaultAnalyzer::validate_event_type (event);
return FT_DefaultFaultAnalyzer::validate_event_type (event);
}
/// Analyze a fault event.
int TAO::FT_ReplicationManagerFaultAnalyzer::analyze_fault_event (
const CosNotification::StructuredEvent & event)
{
int result = 0;
const CosNotification::FilterableEventBody & filterable =
event.filterable_data;
CORBA::ULong item_count = filterable.length ();
if (TAO_debug_level > 6)
{
for (CORBA::ULong n_prop = 0; n_prop < item_count; ++n_prop)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT(
"TAO::FT_ReplicationManagerFaultAnalyzer::analyze_fault_event: "
"Property Name: <%s>\n"),
filterable[n_prop].name.in()
));
}
}
// Populate a TAO::FT_FaultEventDescriptor structure from the
// properties in the event.
TAO::FT_FaultEventDescriptor fault_event_desc;
// Extract the location.
if (result == 0)
{
result = this->get_location (
filterable[1].value, fault_event_desc.location.out());
}
// 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) && (item_count == 2))
{
// All objects at location failed.
fault_event_desc.all_at_location_failed = 1;
}
if ((result == 0) && (item_count == 3))
{
// All objects of type at location failed.
fault_event_desc.all_of_type_at_location_failed = 1;
result = this->get_type_id (
filterable[2].value, fault_event_desc.type_id.out());
}
if ((result == 0) && (item_count == 4))
{
// An object (replica) at a location failed.
fault_event_desc.object_at_location_failed = 1;
result = this->get_type_id (
filterable[2].value, fault_event_desc.type_id.out());
if (result == 0)
{
result = this->get_object_group_id (
filterable[3].value, fault_event_desc.object_group_id);
}
}
// A specific object at a location failed.
if ((result == 0) && (fault_event_desc.object_at_location_failed == 1))
{
result = this->single_replica_failure (fault_event_desc);
}
// All objects at location failed.
if ((result == 0) && (fault_event_desc.all_at_location_failed == 1))
{
result = this->location_failure (fault_event_desc);
}
// All objects of type at location failed.
if ((result == 0) && (fault_event_desc.all_of_type_at_location_failed == 1))
{
result = this->type_failure (fault_event_desc);
}
// Debugging support.
if (TAO_debug_level > 6)
{
fault_event_desc.dump ();
}
return result;
}
// Extract a string type_id from CORBA::Any.
// Caller owns the string returned via <type_id>.
int TAO::FT_ReplicationManagerFaultAnalyzer::get_type_id (
const CORBA::Any& val, PortableGroup::TypeId_out type_id)
{
const char* type_id_value;
if ((val >>= type_id_value) == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_type_id: "
"Could not extract TypeId value from any.\n")),
-1);
}
// Make a deep copy of the TypeId string.
type_id = CORBA::string_dup (type_id_value);
return 0;
}
// Extract the ObjectGroupId from CORBA::Any.
int TAO::FT_ReplicationManagerFaultAnalyzer::get_object_group_id (
const CORBA::Any& val, PortableGroup::ObjectGroupId& id)
{
PortableGroup::ObjectGroupId temp_id = (PortableGroup::ObjectGroupId)0;
if ((val >>= temp_id) == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_object_group_id: "
"Could not extract ObjectGroupId value from any.\n")),
-1);
}
id = temp_id;
return 0;
}
int TAO::FT_ReplicationManagerFaultAnalyzer::get_location (
const CORBA::Any& val, PortableGroup::Location_out location)
{
const PortableGroup::Location* temp_loc;
if ((val >>= temp_loc) == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_location: "
"Could not extract Location value from fault event.\n")),
-1);
}
// Make a deep copy of the Location.
ACE_NEW_RETURN (location, PortableGroup::Location (*temp_loc), -1);
return 0;
}
//
//TODO: Use TAO::PG_Property_Set to get property values from properties
// instead of all these specific "get" functions.
//
// Get the MembershipStyle property.
int TAO::FT_ReplicationManagerFaultAnalyzer::get_membership_style (
const PortableGroup::Properties & properties,
PortableGroup::MembershipStyleValue & membership_style)
{
PortableGroup::Name prop_name (1);
prop_name.length (1);
prop_name[0].id = CORBA::string_dup (FT::FT_MEMBERSHIP_STYLE);
int result = 0;
PortableGroup::Value value;
if (TAO_PG::get_property_value (prop_name, properties, value)
&& ((value >>= membership_style) == 1))
{
if (TAO_debug_level > 6)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_membership_style: "
"MembershipStyle is <%d>:\n"),
membership_style
));
}
}
else
{
result = -1;
}
return result;
}
int TAO::FT_ReplicationManagerFaultAnalyzer::get_replication_style (
const PortableGroup::Properties & properties,
FT::ReplicationStyleValue & replication_style)
{
PortableGroup::Name prop_name (1);
prop_name.length (1);
prop_name[0].id = CORBA::string_dup (FT::FT_REPLICATION_STYLE);
int result = 0;
PortableGroup::Value value;
if (TAO_PG::get_property_value (prop_name, properties, value)
&& ((value >>= replication_style) == 1))
{
if (TAO_debug_level > 6)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_replication_style: "
"ReplicationStyle is <%d>:\n"),
replication_style
));
}
}
else
{
result = -1;
}
return result;
}
int TAO::FT_ReplicationManagerFaultAnalyzer::get_minimum_number_members (
const PortableGroup::Properties & properties,
PortableGroup::MinimumNumberMembersValue & minimum_number_members)
{
PortableGroup::Name prop_name (1);
prop_name.length (1);
prop_name[0].id = CORBA::string_dup (FT::FT_MINIMUM_NUMBER_MEMBERS);
int result = 0;
PortableGroup::Value value;
if (TAO_PG::get_property_value (prop_name, properties, value)
&& ((value >>= minimum_number_members) == 1))
{
if (TAO_debug_level > 6)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_minimum_number_members: "
"MinimumNumberMembers is <%d>:\n"),
minimum_number_members
));
}
}
else
{
result = -1;
}
return result;
}
int TAO::FT_ReplicationManagerFaultAnalyzer::get_initial_number_members (
const PortableGroup::Properties & properties,
PortableGroup::InitialNumberMembersValue & initial_number_members)
{
PortableGroup::Name prop_name (1);
prop_name.length (1);
prop_name[0].id = CORBA::string_dup (FT::FT_INITIAL_NUMBER_MEMBERS);
int result = 0;
PortableGroup::Value value;
if (TAO_PG::get_property_value (prop_name, properties, value)
&& ((value >>= initial_number_members) == 1))
{
if (TAO_debug_level > 6)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_initial_number_members: "
"InitialNumberMembers is <%d>:\n"),
initial_number_members
));
}
}
else
{
result = -1;
}
return result;
}
int TAO::FT_ReplicationManagerFaultAnalyzer::get_factories (
const PortableGroup::Properties & properties,
PortableGroup::FactoryInfos_out factories)
{
PortableGroup::Name prop_name (1);
prop_name.length (1);
prop_name[0].id = CORBA::string_dup (FT::FT_FACTORIES);
int result = 0;
PortableGroup::FactoryInfos_var temp_factories;
PortableGroup::Value value;
if (TAO_PG::get_property_value (prop_name, properties, value) == 1)
{
if ((value >>= temp_factories) == 0)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_factories: "
"Could not extract Factories from properties.\n")
));
result = -1;
}
else
{
// Make a deep copy of the Factories.
ACE_NEW_RETURN (factories, PortableGroup::FactoryInfos (temp_factories.in()), -1);
result = 0;
}
}
else
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT (
"TAO::FT_ReplicationManagerFaultAnalyzer::get_factories: "
"Could not find Factories property.\n")
));
result = -1;
}
return result;
}
int TAO::FT_ReplicationManagerFaultAnalyzer::is_primary_member (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -