Example #1
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
        return 1;

      MessageFactory::register_new_factory(* orb.in());

      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

      PortableServer::POAManager_var poaman = poa->the_POAManager();

      PortableServer::Servant_var<Messenger_i> svt = new Messenger_i;

      PortableServer::ObjectId_var id = poa->activate_object(svt.in());
      obj = poa->id_to_reference(id.in());
      CORBA::String_var ior = orb->object_to_string(obj.in());
      write_ior(ior.in());

      std::cout << "Starting server." << std::endl;

      poaman->activate();

      orb->run();

      poa->destroy(true, true);
      orb->destroy();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Example #2
0
int TAO::FT_FaultNotifier_i::init (CORBA::ORB_ptr orb )
{
    int result = 0;
    this->orb_ = CORBA::ORB::_duplicate (orb);

    // Use the ROOT POA for now
    CORBA::Object_var poa_object =
        this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA);

    if (CORBA::is_nil (poa_object.in ()))
        ORBSVCS_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
                              -1);

    // Get the POA object.
    this->poa_ =
        PortableServer::POA::_narrow (poa_object.in ());


    if (CORBA::is_nil(this->poa_.in ()))
    {
        ORBSVCS_ERROR_RETURN ((LM_ERROR,
                               ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")),
                              -1);
    }

    PortableServer::POAManager_var poa_manager =
        this->poa_->the_POAManager ();

    poa_manager->activate ();

    // Register with the POA.

    this->object_id_ = this->poa_->activate_object (this);

    // find my IOR

    CORBA::Object_var this_obj =
        this->poa_->id_to_reference (object_id_.in ());

    this->ior_ = this->orb_->object_to_string (this_obj.in ());


    ////////////////////////////////////////////////
    // Register with coresident Notification Channel
    CosNotifyChannelAdmin::EventChannelFactory_var notify_factory =
        TAO_Notify_EventChannelFactory_i::create (poa_.in ());
    CosNotification::QoSProperties initial_qos;
    CosNotification::AdminProperties initial_admin;
    this->notify_channel_ =
        notify_factory->create_channel (initial_qos,
                                        initial_admin,
                                        channel_id_);

    this->filter_factory_ = this->notify_channel_->default_filter_factory ();

    ///////////////////////////
    // Producer registration

    this->supplier_admin_ = this->notify_channel_->default_supplier_admin ();

    ::CosNotifyChannelAdmin::ProxyID proxyId = 0;

    //////////////////////
    // structured producer
    ::CosNotifyChannelAdmin::ProxyConsumer_var consumer
        = this->supplier_admin_->obtain_notification_push_consumer (
              ::CosNotifyChannelAdmin::STRUCTURED_EVENT,
              proxyId);

    structured_proxy_push_consumer_
        = ::CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(consumer.in ());
    if (CORBA::is_nil (this->structured_proxy_push_consumer_.in ()))
    {
        ORBSVCS_ERROR_RETURN ((LM_ERROR,
                               "%T %n (%P|%t) Should not occur: Unable to narrow Structured Proxy Push Consumer\n"),
                              1);
    }

    // todo: implement a push supplier if we want to receive disconnect notice
    CosNotifyComm::StructuredPushSupplier_var stubPushSupplier =
        CosNotifyComm::StructuredPushSupplier::_nil();

    this->structured_proxy_push_consumer_->connect_structured_push_supplier (stubPushSupplier.in());

    ////////////////////
    // Sequence producer
    consumer
        = this->supplier_admin_->obtain_notification_push_consumer (
              ::CosNotifyChannelAdmin::SEQUENCE_EVENT,
              proxyId);

    this->sequence_proxy_push_consumer_
        = ::CosNotifyChannelAdmin::SequenceProxyPushConsumer::_narrow(consumer.in ());
    if (CORBA::is_nil (this->sequence_proxy_push_consumer_.in ()))
    {
        ORBSVCS_ERROR_RETURN ((LM_ERROR,
                               "%T %n (%P|%t) Should not occur: Unable to narrow Sequence Proxy Push Consumer\n"),
                              1);
    }

    // todo: implement this if we want to receive disconnect notice
    CosNotifyComm::SequencePushSupplier_var stubSeqPushSupplier =
        CosNotifyComm::SequencePushSupplier::_nil();

    this->sequence_proxy_push_consumer_->connect_sequence_push_supplier (stubSeqPushSupplier.in());
    ///////////////////////////
    // Consumer registration

    // find the channel administrator for consumers
    this->consumer_admin_ = this->notify_channel_->default_consumer_admin ();
    if (CORBA::is_nil (this->consumer_admin_.in ()))
    {
        ORBSVCS_ERROR ((LM_ERROR,
                        "%T %n (%P|%t) NIL consumer admin\n"
                       ));
        result = -1;
    }
    // everything else happens when subscriber shows up

    ///////////////////////////////
    // Register with ReplicationManager
    if (this->rm_register_)
    {
        try
        {
            CORBA::Object_var rm_obj = orb->resolve_initial_references("ReplicationManager");
            this->replication_manager_ = ::FT::ReplicationManager::_narrow(rm_obj.in());
            if (!CORBA::is_nil (replication_manager_.in ()))
            {
                // @@: should we check to see if there's already one registered?
                FT::FaultNotifier_var notifier = FT::FaultNotifier::_narrow (this_obj.in ());
                if (! CORBA::is_nil (notifier.in ()))
                {
                    this->replication_manager_->register_fault_notifier(notifier.in ());
                    ORBSVCS_DEBUG ((LM_DEBUG,
                                    "FaultNotifier registered with ReplicationManager.\n"
                                   ));
                    this->registered_ = 1;
                }
                else
                {
                    ORBSVCS_ERROR ((LM_ERROR,
                                    "Error: Registration failed.  This is not a FaultNotifier (should not occur.)\n"
                                   ));
                }
            }
            else
            {
                ORBSVCS_ERROR ((LM_ERROR,"FaultNotifier: Can't resolve ReplicationManager, It will not be registered.\n" ));
            }
        }
        catch (const CORBA::Exception& ex)
        {
            ex._tao_print_exception (
                "FaultNotifier: Exception resolving ReplicationManager.  Notifier will not be registered.\n");
        }
    }
    else
    {
        ORBSVCS_DEBUG ((LM_DEBUG,
                        "FaultNotifier: ReplicationManager registration disabled.\n"
                       ));
    }
    ///////////////////////////////
    // Set up and ready for action
    // publish our IOR

    if(result == 0)
    {
        if (this->ior_output_file_ != 0)
        {
            this->identity_ = "file:";
            this->identity_ += ACE_TEXT_ALWAYS_CHAR(this->ior_output_file_);
            result = write_ior();
        }
    }

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

            CORBA::Object_var naming_obj =
                this->orb_->resolve_initial_references ("NameService");

            if (CORBA::is_nil(naming_obj.in ())) {
                ORBSVCS_ERROR_RETURN ((LM_ERROR,
                                       "%T %n (%P|%t) Unable to find the Naming Service\n"),
                                      1);
            }

            this->naming_context_ =
                CosNaming::NamingContext::_narrow (naming_obj.in ());
            if (CORBA::is_nil(this->naming_context_.in ()))
            {
                ORBSVCS_ERROR_RETURN ((LM_ERROR,
                                       "%T %n (%P|%t) Should not occur: Can't narrow initial reference to naming context.\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_obj.in()  //CORBA::Object::_duplicate(this_obj)
                                          );
        }
    }

    return result;
}
Example #3
0
int FT_ReplicaFactory_i::init (CORBA::ORB_ptr orb)
{
  int result = 0;

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

  // Use the ROOT POA for now
  CORBA::Object_var poa_object =
    this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA);

  if (CORBA::is_nil (poa_object.in ()))
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
                      -1);
  }

  // Get the POA object.
  this->poa_ =
    PortableServer::POA::_narrow (poa_object.in ());

  if (CORBA::is_nil(this->poa_.in ()))
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")),
                      -1);
  }

  PortableServer::POAManager_var poa_manager =
    this->poa_->the_POAManager ();

  poa_manager->activate ();

  // Register with the POA.

  this->object_id_ = this->poa_->activate_object (this);

  CORBA::Object_var this_obj =
    this->poa_->id_to_reference (object_id_.in ());

  this->ior_ = this->orb_->object_to_string (this_obj.in ());

  if (this->factory_registry_ior_ != 0)
  {
    if (ACE_OS::strcmp (this->factory_registry_ior_, ACE_TEXT("none")) != 0)
    {
      CORBA::Object_var reg_obj = this->orb_->string_to_object(factory_registry_ior_);
      this->factory_registry_ = ::PortableGroup::FactoryRegistry::_narrow(reg_obj.in ());
      if (CORBA::is_nil(this->factory_registry_.in ()))
      {
        ACE_ERROR (( LM_ERROR,
           "Can't resolve Factory Registry IOR %s\n",
           this->factory_registry_ior_
           ));
        result = -1;
      }
    }
  }
  else // no -f option.  Try RIR(RM)
  {
    ///////////////////////////////
    // Find the ReplicationManager
    try
    {
      CORBA::Object_var rm_obj = orb->resolve_initial_references("ReplicationManager");
      this->replication_manager_ = ::FT::ReplicationManager::_narrow(rm_obj.in());
      if (!CORBA::is_nil (replication_manager_.in ()))
      {
        this->have_replication_manager_ = 1;
        // empty criteria
        ::PortableGroup::Criteria criteria;
        this->factory_registry_ = this->replication_manager_->get_factory_registry(criteria);
        if (CORBA::is_nil (this->factory_registry_.in ()))
        {
          ACE_ERROR ((LM_ERROR,"ReplicaFactory: ReplicationManager failed to return FactoryRegistry.  Factory will not be registered.\n" ));
        }
      }
      else
      {
        this->factory_registry_ =  ::PortableGroup::FactoryRegistry::_narrow(rm_obj.in());
        if (!CORBA::is_nil(this->factory_registry_.in ()))
        {
          ACE_DEBUG ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" ));
        }
        else
        {
          ACE_ERROR ((LM_ERROR,"ReplicaFactory: Can't resolve ReplicationManager.\n" ));
        }
      }
    }
    catch (const CORBA::Exception& ex)
    {
      if (this->test_output_file_ == 0) // ignore if this is a test run
      {
        ex._tao_print_exception (
          "ReplicaFactory: Exception resolving ReplicationManager. Factory will not be registered.\n");
      }
    }

  }

  if ( ! CORBA::is_nil (this->factory_registry_.in ()))
  {
    size_t roleCount = roles_.size();
    for (size_t nRole = 0; nRole < roleCount; ++nRole)
    {
      const char * roleName = this->roles_[nRole].c_str();

      PortableGroup::FactoryInfo info;
      info.the_factory = ::PortableGroup::GenericFactory::_narrow(this_obj.in ());
      info.the_location.length(1);
      info.the_location[0].id = CORBA::string_dup(this->location_.c_str ());
      info.the_criteria.length(1);
      info.the_criteria[0].nam.length(1);
      info.the_criteria[0].nam[0].id = CORBA::string_dup(PortableGroup::role_criterion);
      info.the_criteria[0].val <<= CORBA::string_dup(roleName);

      ACE_ERROR (( LM_INFO,
         "Factory: %s@%C registering with factory registry\n",
         roleName,
         location_.c_str ()
         ));

      char const * replica_repository_id =
        FT_TEST::_tc_TestReplica->id ();

      this->factory_registry_->register_factory(
        roleName,
        replica_repository_id,
        info);
    }
    this->registered_ = 1;
  }

  int identified = 0; // bool

  if (this->roles_.size() > 0)
  {
    this->identity_ = ACE_TEXT("Factory");
    if (this->location_.length () != 0)
    {
      this->identity_ += ACE_TEXT("@");
      this->identity_ += ACE_TEXT_CHAR_TO_TCHAR(this->location_.c_str ());
    }
    identified = 1;
  }

  if (this->ior_output_file_ != 0)
  {
    if (!identified)
    {
      this->identity_ = ACE_TEXT("file:");
      this->identity_ += this->ior_output_file_;
      // note: don't set identified--ns identity overrides file identitiy
    }
    result = write_ior (this->ior_output_file_, this->ior_. in ());
  }
  else
  {
    if (this->registered_)
    {
      // if we didn't register with a FactoryRegistry
      // and no IOR file specified,
      // then always try to register with name service
      this->ns_name_ = "FT_ReplicaFactory";
    }
  }

  if (this->ns_name_.length () != 0)
  {
    if (!identified)
    {
      this->identity_ = ACE_TEXT("name:");
      this->identity_ += ACE_TEXT_CHAR_TO_TCHAR(this->ns_name_.c_str ());
    }

    CORBA::Object_var naming_obj =
      this->orb_->resolve_initial_references ("NameService");

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

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

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

    this->naming_context_->rebind (this->this_name_, this_obj.in());
  }

  // if we're testing.  Create a replica at startup time
  if (this->test_output_file_ != 0)
  {
    // shouldn't be necessary, but create_replica assumes this
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->internals_, 1);
    FT_TestReplica_i * replica = create_replica ("test");

    PortableServer::POA_var poa = replica->_default_POA ();
    ::CORBA::Object_var replica_obj = poa->servant_to_reference(replica);
    ::CORBA::String_var replicaIOR = this->orb_->object_to_string(replica_obj.in ());
    write_ior (this->test_output_file_, replicaIOR.in ());
  }

  return result;
}