⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ft_replicationmanager.cpp

📁 这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用于网络游戏医学图像网关的高qos要求.更详细的内容可阅读相应的材料
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file    FT_ReplicationManager.cpp
 *
 *  FT_ReplicationManager.cpp,v 1.5 2004/01/09 11:00:31 jwillemsen Exp
 *
 *  This file is part of Fault Tolerant CORBA.
 *  This file implements the FT_ReplicationManager class as declared in
 *  FT_Replication_Manager.h.
 *
 *  @author Curt Hibbs <hibbs_c@ociweb.com>
 */
//=============================================================================
#include "FT_ReplicationManager.h"
#include "FT_Property_Validator.h"

#include <ace/Get_Opt.h>
#include <ace/OS_NS_stdio.h>
#include <tao/Messaging/Messaging.h>
#include <tao/IORTable/IORTable.h>
#include <tao/debug.h>
#include <tao/ORB_Constants.h>
#include <orbsvcs/PortableGroup/PG_Object_Group.h>
#include <orbsvcs/PortableGroup/PG_Property_Set.h>
#include <orbsvcs/PortableGroup/PG_Properties_Encoder.h>
#include <orbsvcs/PortableGroup/PG_Property_Utils.h>
#include <orbsvcs/PortableGroup/PG_conf.h>

#include <orbsvcs/FaultTolerance/FT_IOGR_Property.h>
#include <orbsvcs/FT_ReplicationManager/FT_ReplicationManagerFaultAnalyzer.h>

ACE_RCSID (FT_ReplicationManager,
           FT_ReplicationManager,
           "FT_ReplicationManager.cpp,v 1.5 2004/01/09 11:00:31 jwillemsen Exp")


// Use this macro at the beginning of CORBA methods
// to aid in debugging.
#define METHOD_ENTRY(name)    \
  if (TAO_debug_level > 6)    \
  {                           \
    ACE_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)    \
  {                           \
    ACE_DEBUG (( LM_DEBUG,    \
      "Leave %s\n", #name     \
      ));                     \
  }                           \
  return /* value goes here */

#define TODO
//#define TODO int todo; // warn on todos

TAO::FT_ReplicationManager::FT_ReplicationManager ()
  : orb_ (CORBA::ORB::_nil ())
  , poa_ (PortableServer::POA::_nil ())
  , ior_output_file_ (0)
  , ns_name_ (0)
  , naming_context_ (CosNaming::NamingContext::_nil ())
  , replication_manager_ref_ (FT::ReplicationManager::_nil ())
  , fault_notifier_ (FT::FaultNotifier::_nil ())
  , fault_notifier_ior_string_ (0)
  , fault_consumer_ ()
  , factory_registry_ ("ReplicationManager::FactoryRegistry")
  , quit_ (0)
{
  // init must be called before using this object.
}

TAO::FT_ReplicationManager::~FT_ReplicationManager (void)
{
  // cleanup happens in fini
}

//public
int TAO::FT_ReplicationManager::parse_args (int argc, char * argv[])
{
  ACE_Get_Opt get_opts (argc, argv, "n:o:f:");
  int c;

  while ( (c = get_opts ()) != -1)
  {
    switch (c)
    {
      case 'o':
        this->ior_output_file_ = get_opts.opt_arg ();
        break;

      case 'n':
        this->ns_name_ = get_opts.opt_arg ();
        break;

      case 'f':
        this->fault_notifier_ior_string_ = get_opts.opt_arg ();
        break;

      case '?':
        // fall thru
      default:
        ACE_ERROR_RETURN ( (LM_ERROR,
                           ACE_TEXT ("%T %n (%P|%t) - usage:  %s")
                           ACE_TEXT (" -o <iorfile (for testing)>")
                           ACE_TEXT (" -f <fault notifier IOR (for testing)>")
                           ACE_TEXT (" -n <name-to-bind-in-NameService (for testing)>")
                           ACE_TEXT ("\n"),
                           argv [0]),
                          -1);
      break;
    }
  }
  // Indicates sucessful parsing of the command line
  return 0;
}

//public
const char * TAO::FT_ReplicationManager::identity () const
{
  return this->identity_.c_str ();
}

//public
int TAO::FT_ReplicationManager::init (CORBA::ORB_ptr orb ACE_ENV_ARG_DECL)
{
  int result = 0;

  if (TAO_debug_level > 1)
  {
    ACE_DEBUG ( (LM_DEBUG,
      ACE_TEXT (
        "%T %n (%P|%t) - Enter TAO::FT_ReplicationManager::init.\n")
    ));
  }


  this->orb_ = CORBA::ORB::_duplicate (orb);

  // Get the RootPOA.
  CORBA::Object_var poa_obj = this->orb_->resolve_initial_references (
    TAO_OBJID_ROOTPOA ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);
  this->poa_ = PortableServer::POA::_narrow (
    poa_obj.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);


  // initialize the FactoryRegistry
  this->factory_registry_.init (this->orb_.in (), this->poa_.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  PortableGroup::FactoryRegistry_var factory_registry = this->factory_registry_.reference ();

  // @@: do we want to use the same poa to create object groups?
  this->group_factory_.init (
    this->orb_.in (),
    this->poa_.in (),
    factory_registry.in ()
    ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Activate ourself in the POA.
  PortableServer::ObjectId_var oid = this->poa_->activate_object (
    this ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  CORBA::Object_var this_obj = this->poa_->id_to_reference (
    oid.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);
  this->replication_manager_ref_ = FT::ReplicationManager::_narrow (
    this_obj.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // If we were given an initial IOR string for a Fault Notifier on the
  // command line, convert it to an IOR, then register the fault
  // notifier.
  if (this->fault_notifier_ior_string_ != 0)
  {
    CORBA::Object_var notifier_obj = this->orb_->string_to_object (
      this->fault_notifier_ior_string_ ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);
    FT::FaultNotifier_var notifier = FT::FaultNotifier::_narrow (
      notifier_obj.in () ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);
    if (! CORBA::is_nil (notifier.in ()))
    {
      this->register_fault_notifier_i (notifier.in () ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN (-1);
    }
    else
    {
      ACE_ERROR_RETURN ( (LM_ERROR,
        ACE_TEXT (
          "%T %n (%P|%t) - "
          "Could not resolve notifier IOR.\n")),
          -1);
    }
  }

  // Activate the RootPOA.
  PortableServer::POAManager_var poa_mgr =
    this->poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);
  poa_mgr->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  // Register our IOR in the IORTable with the key-string
  // "ReplicationManager".
  CORBA::Object_var ior_table_obj =
    this->orb_->resolve_initial_references (
      TAO_OBJID_IORTABLE ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  IORTable::Table_var ior_table =
    IORTable::Table::_narrow (ior_table_obj.in () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);
  if (CORBA::is_nil (ior_table.in ()))
  {
    ACE_ERROR_RETURN ( (LM_ERROR,
      ACE_TEXT ("%T %n (%P|%t) - Unable to resolve the IORTable.\n")),
      -1);
  }
  else
  {
    CORBA::String_var rm_ior_str = this->orb_->object_to_string (
      this->replication_manager_ref_.in () ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);
    ior_table->bind ("ReplicationManager", rm_ior_str.in ()
      ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);
  }

  // Publish our IOR, either to a file or the Naming Service.
  if (this->ior_output_file_ != 0)
  {
    this->identity_ = "file:";
    this->identity_ += this->ior_output_file_;
    result = this->write_ior ();
  }

  if (result == 0 && this->ns_name_ != 0)
  {
    this->identity_ = "name:";
    this->identity_ += this->ns_name_;

    CORBA::Object_var naming_obj = this->orb_->resolve_initial_references (
        TAO_OBJID_NAMESERVICE ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);

    this->naming_context_ =
      CosNaming::NamingContext::_narrow (
        naming_obj.in () ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);

    if (CORBA::is_nil (this->naming_context_.in ()))
    {
      ACE_ERROR_RETURN ( (LM_ERROR,
        ACE_TEXT ("%T %n (%P|%t) - Unable to find the Naming Service.\n")),
        -1);
    }

    this->this_name_.length (1);
    this->this_name_[0].id = CORBA::string_dup (this->ns_name_);

    this->naming_context_->rebind (
      this->this_name_,
      this->replication_manager_ref_.in ()
      ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);
  }

  if (TAO_debug_level > 1)
  {
    if (result == 0)
    {
      ACE_DEBUG ( (LM_DEBUG,
        ACE_TEXT (
          "%T %n (%P|%t) - Leave TAO::FT_ReplicationManager::init.\n")
      ));
    }
    else
    {
      ACE_DEBUG ( (LM_DEBUG,
        ACE_TEXT (
          "%T %n (%P|%t) - FT_ReplicationManager::init failed.\n")
      ));
    }
  }

  ////////////////////////////////
  // Initialize default properties
  PortableGroup::Value value;
  value <<= TAO_PG_MEMBERSHIP_STYLE;
  this->properties_support_.set_default_property (PortableGroup::PG_MEMBERSHIP_STYLE, value ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  value <<= TAO_PG_INITIAL_NUMBER_MEMBERS;
  this->properties_support_.set_default_property (PortableGroup::PG_INITIAL_NUMBER_MEMBERS, value ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  value <<= TAO_PG_MINIMUM_NUMBER_MEMBERS;
  this->properties_support_.set_default_property (PortableGroup::PG_MINIMUM_NUMBER_MEMBERS, value ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  value <<= FT::SEMI_ACTIVE;
  this->properties_support_.set_default_property (FT::FT_REPLICATION_STYLE, value ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  value <<= FT::CONS_APP_CTRL;
  this->properties_support_.set_default_property (  FT::FT_CONSISTENCY_STYLE, value ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  value <<= FT::PULL;
  this->properties_support_.set_default_property (FT::FT_FAULT_MONITORING_STYLE, value ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

  value <<= FT::MEMB;
  this->properties_support_.set_default_property (FT::FT_FAULT_MONITORING_GRANULARITY, value ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);

#if 0
  FaultMonitoringIntervalAndTimeoutValue times;
  value <<= times;
  this->properties_support_.set_default_property (FT::FT_FAULT_MONITORING_INTERVAL_AND_TIMEOUT, value ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN(-1);
#endif

#if 0
  value << interval;
  this->properties_support_.set_default_property (FT::FT_CHECKPOINT_INTERVAL, value);
#endif


  return result;
}

//public
int TAO::FT_ReplicationManager::idle (int & result ACE_ENV_ARG_DECL_NOT_USED)
{
  ACE_UNUSED_ARG (result);
  return this->quit_;
}


//public
int TAO::FT_ReplicationManager::fini (ACE_ENV_SINGLE_ARG_DECL)
{
  int result = 0;

  result = this->fault_consumer_.fini (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK_RETURN (-1);

  if (this->ior_output_file_ != 0)
  {
    ACE_OS::unlink (this->ior_output_file_);
    this->ior_output_file_ = 0;
  }
  if (this->ns_name_ != 0)
  {
    this->naming_context_->unbind (this->this_name_ ACE_ENV_ARG_PARAMETER);
    ACE_CHECK_RETURN (-1);
    this->ns_name_ = 0;
  }

  return result;
}

//CORBA
void
TAO::FT_ReplicationManager::register_fault_notifier (
  FT::FaultNotifier_ptr fault_notifier
  ACE_ENV_ARG_DECL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -