Пример #1
0
//-----------------------------------------------------------------------------
ORBHelper::ORBHelper() :
    threadManager_mp(0),
    orbRunYet_m(false)
{
    //create a new ACE thread manager
    threadManager_mp = ACE_Thread_Manager::instance();
    
    //CORBA naming service corbaloc
    ACE_CString nameService;
    
    //get NameService Reference
    nameService += acscommon::NAMING_SERVICE_NAME;
    nameService +="=corbaloc::";
    nameService += ACSPorts::getIP();
    nameService += ":"; 
    nameService += ACSPorts::getNamingServicePort().c_str();
    nameService += "/"; 
    nameService += acscommon::NAMING_SERVICE_NAME;
    
    // initialize ORB
    int argc = 5;
    char* argv[] = { "", 
		     "-ORBInitRef",
		     (char *)nameService.c_str(),
		     "-ORBDottedDecimalAddresses",
		     "1"};
    
    //initialize the ORB
    orb_mp = CORBA::ORB_init(argc, argv, "");
    //ensure it's a real reference
    ACE_ASSERT(!CORBA::is_nil(orb_mp));
	    
    //get the Root POA
    CORBA::Object_var poaObject = orb_mp->resolve_initial_references("RootPOA");
    //ensure it's a real reference
    ACE_ASSERT(!CORBA::is_nil(poaObject.in()));
    //narrow the Root POA
    PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(poaObject.in());
    //ensure it's a real reference
    ACE_ASSERT(!CORBA::is_nil(rootPOA.in()));
    
    //get the POA manager
    PortableServer::POAManager_var poaManager = rootPOA->the_POAManager();
    //ensure it's a real reference
    ACE_ASSERT(!CORBA::is_nil(poaManager.in()));
    
    //finally activate the POA manager to start processing incoming and
    //outgoing calls
    poaManager->activate();

    //spawn a separate thread to start the ORB in
    ACE_ASSERT(threadManager_mp!=0);
    threadManager_mp->spawn(ACE_THR_FUNC(ORBHelper::runOrbThread), static_cast<void *>(this));

    //block until the ORB thread has really started!
    while(orbRunYet_m==false)
	{
	ACE_OS::sleep(1);
	}
    ACE_OS::sleep(1);
}
Пример #2
0
void CORBAThread::run()
{
	uint32 realCurrTime = 0;
    uint32 realPrevTime = getMSTime();
	uint32 prevSleepTime = 0;                               // used for balanced full tick time length near WORLD_SLEEP_CONST

	CosNaming::NamingContext_var rootContext;
	try
	{
		sLog.outBasic("Initializing CORBA...");
		CORBA::ORB_ptr orb = CORBA::ORB_init(argnb,argtab,"omniORB4");

		sLog.outBasic("Initializing CORBA POA...");
		CORBA::Object_var obj = orb->resolve_initial_references("NameService");
		rootContext = CosNaming::NamingContext::_narrow(obj);
		PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
		if( CORBA::is_nil(rootContext) ) {
			sLog.outError("RootContext configuration failed !");
		}

		sLog.outBasic("Prepare FirstCallBack object...");
		FirstCallBack_var v = FirstCallBack::_narrow(obj);

		FirstCallBack_i* FCB = new FirstCallBack_i();

		// Activate the object.  This tells the POA that this object is
		// ready to accept requests.
		PortableServer::ObjectId_var FCBid = poa->activate_object(FCB);

		// Obtain a reference to the object.
		FirstCallBack_var FCBref = FCB->_this();

		// Decrement the reference count of the object implementation, so
		// that it will be properly cleaned up when the POA has determined
		// that it is no longer needed.
		FCB->_remove_ref();
		
		/** TODO : activate objects there

		*/

		sLog.outBasic("Activate CORBA POA Manager...");
		PortableServer::POAManager_var pman = poa->the_POAManager();
		pman->activate();

		if(CORBA::is_nil(v))
			sLog.outError("Cannot Initialize FirstCallBack object");
		else
		{
			CORBA::String_var src = (const char*) "Toto";
			CORBA::String_var dest = v->nerzhulCB(src);
			sLog.outError("String recv %s",dest);
		}

		sLog.outBasic("CORBA Thread launched successfuly !");
		while(!MustStop())
		{
			// Updates
			realCurrTime = getMSTime();
			uint32 diff = getMSTimeDiff(realPrevTime,realCurrTime);

			// Main update there if need
			realPrevTime = realCurrTime;
			if (diff <=  CLUSTER_SLEEP_CONST+prevSleepTime)
			{
				prevSleepTime = CLUSTER_SLEEP_CONST+prevSleepTime-diff;
				ACE_Based::Thread::Sleep(prevSleepTime);
			}
			else
				prevSleepTime = 0;
		}

		sLog.outBasic("Destroy CORBA ORB...");
		orb->destroy();
	}
	catch(CORBA::SystemException& ex)
	{
		sLog.outError("CORBA System Exception : %s",ex._name());
	}
	catch(CORBA::Exception& ex)
	{
		sLog.outError("CORBA Exception : %s",ex._name());
	}
	catch(omniORB::fatalException& ex)
	{
		sLog.outError("omniORB fatalException : file => %s / line => %d / error : %s",ex.file(),ex.line(),ex.errmsg());
	}

	sLog.outBasic("CORBA Thread finished successfuly !");
}
Пример #3
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      int server_num = 0;
      int die_on_ping = 1;
      int ping_count = 0;

      for (int i = 1; i < argc; i++)
        {
          ACE_TCHAR *c = argv[i];
          if (ACE_OS::strcasecmp (ACE_TEXT ("-n"), c) == 0)
            {
              server_num = ACE_OS::atoi (argv[++i]);
            }
          else if (ACE_OS::strcasecmp (ACE_TEXT ("-?"),c) == 0)
            {
              ACE_DEBUG ((LM_DEBUG,
                          ACE_TEXT ("usage: %C ")
                          ACE_TEXT ("-n Number of the server\n"),
                          argv[0]));
              return 1;
            }
        }

      Server_ORBInitializer * temp_initializer;

      ACE_NEW_RETURN (temp_initializer,
                      Server_ORBInitializer (&ping_count),
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var initializer =
        temp_initializer;

      PortableInterceptor::register_orb_initializer (initializer.in ());

      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

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

      PortableServer::POAManager_var mgr = root_poa->the_POAManager();

      ACE_CString poa_name_base = ACE_CString("TestObject_") + toStr (server_num);
      PortableServer::POA_var test_poa;
      test_poa = createPOA(root_poa.in (), true, poa_name_base.c_str ());
      temp_initializer->set_poa (test_poa.in());

      mgr->activate();

      PortableServer::Servant_var<Test_i> test_servant =
        new Test_i(server_num);

      PortableServer::ObjectId_var object_id =
        PortableServer::string_to_ObjectId("test_object");

    //
    // Activate the servant with the test POA,
    // obtain its object reference, and get a
    // stringified IOR.
    //
    test_poa->activate_object_with_id(object_id.in(), test_servant.in());

    //
    // Create binding between "TestService" and
    // the test object reference in the IOR Table.
    // Use a TAO extension to get the non imrified poa
    // to avoid forwarding requests back to the ImR.

    TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
    obj = tpoa->id_to_reference_i(object_id.in(), false);
    CORBA::String_var test_ior = orb->object_to_string(obj.in());
    obj = orb->resolve_initial_references("IORTable");
    IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
    table->bind(poa_name_base.c_str (), test_ior.in());

    ACE_DEBUG ((LM_DEBUG, "Started Server %s \n",
                poa_name_base.c_str()));

    {
      ACE_CString status_file = poa_name_base + ACE_CString(".status");
      ofstream out(status_file.c_str ());
      out << "started" << endl;
    }

    while (ping_count < die_on_ping)
      {
        orb->perform_work ();
      }

    root_poa->destroy(1,1);
    orb->destroy();

  }
  catch(const CORBA::Exception& ex) {
    ex._tao_print_exception ("Server main()");
    return 1;
  }

  return 0;
}
Пример #4
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int ec = 0;
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    int max_run = 0;
    int server_num = 0;
    int init_delay_secs = 0;
    const ACE_TCHAR *ior_file_name = ACE_TEXT ("");
    ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("d:m:n:o:?"));
    int c;

    while ((c = get_opts ()) != -1)
      switch (c)
        {
        case 'd':
          init_delay_secs = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'm':
          max_run = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'n':
          server_num = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'o':
          ior_file_name = get_opts.opt_arg ();
          break;
        case '?':
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("usage: %s ")
                      ACE_TEXT ("-d <seconds to delay before initializing POA> ")
                      ACE_TEXT ("-n Number of the server\n"),
                      argv[0]));
          return 1;
          break;
        }

    ACE_OS::sleep (init_delay_secs);

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

    PortableServer::POAManager_var mgr = root_poa->the_POAManager();

    ACE_CString poa_name = ACE_CString("TestObject_") + toStr (server_num);

    PortableServer::POA_var test_poa = createPOA(root_poa.in(), poa_name.c_str ());

    Test_i *impl = new Test_i(orb.in());
    PortableServer::Servant_var<Test_i> test_servant = impl;

    PortableServer::ObjectId_var object_id =
      PortableServer::string_to_ObjectId("test_object");

    //
    // Activate the servant with the test POA,
    // obtain its object reference, and get a
    // stringified IOR.
    //
    test_poa->activate_object_with_id(object_id.in(), test_servant.in());

    //
    // Create binding between "TestService" and
    // the test object reference in the IOR Table.
    // Use a TAO extension to get the non imrified poa
    // to avoid forwarding requests back to the ImR.

    TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
    obj = tpoa->id_to_reference_i(object_id.in(), false);
    CORBA::String_var test_ior = orb->object_to_string(obj.in());
    obj = orb->resolve_initial_references("IORTable");
    IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
    table->bind(poa_name.c_str (), test_ior.in());

    if (ACE_OS::strlen (ior_file_name) > 0)
      {
        obj = test_poa->id_to_reference (object_id.in ());
        test_ior = orb->object_to_string (obj.in ());
        FILE *f = ACE_OS::fopen (ior_file_name, ACE_TEXT ("w"));
        ACE_OS::fprintf (f, "%s", test_ior.in ());
        ACE_OS::fclose (f);
      }

    //
    // This server is now ready to run.
    // This version does not create an IOR
    // file as demonstrated in the
    // Developer's Guide.  It assumes that
    // users create IORs for the client using
    // the tao_imr utility.
    //
    //
    // Stop discarding requests.
    //
    mgr->activate();

    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Started Server <%C> pid = %d\n"),
                poa_name.c_str(), ACE_OS::getpid ()));

    ACE_CString pid_file = "server.pid";
    {
      ofstream out(pid_file.c_str (), ios_base::app);
      out << ACE_OS::getpid () << endl;
      out.close ();
    }
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Server <%C> pid = %d closed pidfile\n"),
                poa_name.c_str(), ACE_OS::getpid ()));

    if (max_run > 0)
      {
        ACE_Time_Value tv (max_run,0);
        orb->run (tv);
      }
    else
      {
        orb->run ();
      }
    ec = impl->exit_code ();
    root_poa->destroy(1,1);
    orb->destroy();

    //    ACE_OS::unlink (pid_file.c_str ());

  }
  catch(const CORBA::Exception& ex) {
    ex._tao_print_exception (ACE_TEXT ("Server main()"));
    return 1;
  }

  return ec;
}
Пример #5
0
int
ACE_TMAIN (int argc,
      ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB first.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var obj
        = orb->resolve_initial_references ("RootPOA");

      // Get the POA_var object from Object_var.
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (obj.in ());

      PortableServer::POAManager_var mgr
        = root_poa->the_POAManager ();

      mgr->activate ();

      // Initialize the AVStreams components.
      TAO_AV_CORE::instance ()->init (orb.in (),
                                      root_poa.in ());

      int result =
        parse_args (argc,
                    argv);

      if (result == -1)
        return -1;

      // Make sure we have a valid <output_file>
      output_file = ACE_OS::fopen (output_file_name,
                                   "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_DEBUG,
                           "Cannot open output file %s\n",
                           output_file_name),
                          -1);

      else
        ACE_DEBUG ((LM_DEBUG,
                    "File Opened Successfully\n"));

      Receiver receiver;
      result =
        receiver.init (argc,
                       argv);

      if (result != 0)
        return result;

      orb->run ();

      // Hack for now....
      ACE_OS::sleep (1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("receiver::init");
      return -1;
    }

  ACE_OS::fclose (output_file);

  return 0;
}
Пример #6
0
Messenger_i::Messenger_i (CORBA::ORB_ptr orb)
  : orb_ (CORBA::ORB::_duplicate (orb))
{

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

  CosNaming::NamingContext_var naming_context =
    CosNaming::NamingContext::_narrow (naming_obj.in());

  CosNaming::Name name;
  name.length (1);
  name[0].id = CORBA::string_dup ("NotifyEventChannelFactory");

  CORBA::Object_var obj = naming_context->resolve (name);

  CosNotifyChannelAdmin::EventChannelFactory_var notify_factory =
    CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ());

  CosNotifyChannelAdmin::ChannelID id;
  CosNotification::QoSProperties initial_qos;
  CosNotification::AdminProperties initial_admin;

  CosNotifyChannelAdmin::EventChannel_var ec =
    notify_factory->create_channel (initial_qos,
                                    initial_admin,
                                    id);

  name[0].id = CORBA::string_dup ("MyEventChannel");

  naming_context->rebind (name, ec.in());

  CosNotifyChannelAdmin::AdminID adminid;
  CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
    CosNotifyChannelAdmin::OR_OP;

  CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
    ec->new_for_suppliers (ifgop, adminid);

  CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id;

  CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer =
    supplier_admin->obtain_notification_push_consumer(
                                 CosNotifyChannelAdmin::STRUCTURED_EVENT,
                                 supplieradmin_proxy_id);

  StructuredEventSupplier_i *servant =
    new StructuredEventSupplier_i(orb_.in());

  CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA");
  PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ());
  PortableServer::POAManager_var mgr = poa->the_POAManager ();

  mgr->activate ();
  PortableServer::ObjectId_var objectId = poa->activate_object (servant);

  CORBA::Object_var supplier_obj = poa->id_to_reference (objectId.in ());

  CosNotifyComm::StructuredPushSupplier_var supplier =
    CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj.in ());

  consumer_proxy_ =
    CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer.in());

  consumer_proxy_->
    connect_structured_push_supplier (supplier.in());
}
Пример #7
0
CORBA::Object_ptr
DAnCE_NodeManager_Module::init (CORBA::ORB_ptr orb,
                                int argc,
                                ACE_TCHAR *argv[])
{
  try
    {
      if (CORBA::is_nil(orb))
        {
          DANCE_ERROR (DANCE_LOG_EMERGENCY,
                       (LM_ERROR, DLINFO
                        ACE_TEXT("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT("Attempted to create Node Manager with a nil orb.\n")));
          return CORBA::Object::_nil();
        }

      if (CORBA::is_nil(this->orb_.in()))
        {
          DANCE_TRACE_LOG (DANCE_LOG_DETAILED_TRACE,
                           (LM_TRACE, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ")
                            ACE_TEXT("NM's orb is nil.\n")));
          this->orb_ = CORBA::ORB::_duplicate (orb);
        }
      else if (ACE_OS::strcmp(orb->id(), this->orb_->id()) != 0)
        {
          DANCE_DEBUG (DANCE_LOG_DETAILED_TRACE,
                       (LM_TRACE, DLINFO
                        ACE_TEXT("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT("Resetting NM's orb.\n")));
          this->orb_ = CORBA::ORB::_duplicate (orb);
          this->domain_nc_ = CosNaming::NamingContext::_nil();
        }

      if (!this->parse_args (argc, argv))
        {
          DANCE_ERROR (DANCE_LOG_EMERGENCY,
                       (LM_ERROR, DLINFO
                        ACE_TEXT("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT("Unable to parse the commandline arguments.\n")));
          return CORBA::Object::_nil ();
        }

      this->register_value_factories ();
      this->create_poas ();

      if (this->options_.domain_nc_)
        {
          try
            {
              DANCE_TRACE_LOG (DANCE_LOG_TRACE,
                               (LM_TRACE, DLINFO ACE_TEXT("DAnCE_NodeManager_Module::init - ")
                                ACE_TEXT("Resolving DomainNC.\n")));
              CORBA::Object_var domain_obj = this->orb_->string_to_object (this->options_.domain_nc_);
              if (!CORBA::is_nil (domain_obj.in ()))
                {
                  this->domain_nc_ = CosNaming::NamingContext::_narrow (domain_obj.in());
                  if (CORBA::is_nil (this->domain_nc_.in ()))
                    {
                      DANCE_ERROR (DANCE_LOG_EMERGENCY,
                                   (LM_ERROR, DLINFO
                                    ACE_TEXT("DAnCE_NodeManager_Module::init - ")
                                    ACE_TEXT("Narrow to NamingContext return nil for DomainNC.\n")));
                      return CORBA::Object::_nil ();
                    }
                }
            }
          catch (const CORBA::Exception&)
            {
              DANCE_ERROR (DANCE_LOG_WARNING, (LM_WARNING, DLINFO
                                               ACE_TEXT("DAnCE_NodeManager_Module::init - ")
                                               ACE_TEXT("DomainNC context not found!\n")));
            }
        }

      DANCE_TRACE_LOG (DANCE_LOG_TRACE,
                       (LM_TRACE, DLINFO
                        ACE_TEXT("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT("Resolving plan NS naming context.\n")));

      CosNaming::NamingContext_var rebind_nc;
      if (this->options_.rebind_plan_ns_)
        {
          if (!this->options_.create_plan_ns_)
            {
              DANCE_ERROR (DANCE_LOG_EMERGENCY,
                           (LM_ERROR, DLINFO
                            ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                            ACE_TEXT ("Rebind_plan_ns option is enabled but Create_plan_ns is not.\n")));
              return CORBA::Object::_nil();
            }
          CORBA::Object_var tmp_obj;
          if (0 != this->options_.rebind_plan_ns_ior_)
            {
              tmp_obj = orb->string_to_object (this->options_.rebind_plan_ns_ior_);
              rebind_nc = CosNaming::NamingContext::_narrow (tmp_obj);
            }
          else
            {
              if (CORBA::is_nil (this->domain_nc_.in ()))
                {
                  DANCE_ERROR (DANCE_LOG_EMERGENCY,
                               (LM_ERROR, DLINFO
                                ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                                ACE_TEXT ("The rebind plan is enabled but neither NC ")
                                ACE_TEXT ("nor DomainNC are not supplied. No rebinding will be done.\n")
                                ACE_TEXT ("Use the \"-rebind-plan-ns NC ior\" ")
                                ACE_TEXT ("or \"-ORBInitRef DomainNC\" option.\n")));
                  return CORBA::Object::_nil ();
                }
              rebind_nc = CosNaming::NamingContext::_duplicate (this->domain_nc_.in ());
            }
        }

      // Initialize IOR table
      CORBA::Object_var table_object = orb->resolve_initial_references ("IORTable");

      IORTable::Table_var adapter = IORTable::Table::_narrow (table_object.in ());

      if (CORBA::is_nil (adapter.in ()))
        {
          DANCE_ERROR (DANCE_LOG_EMERGENCY,
                       (LM_ERROR, DLINFO
                        ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT ("Unable to RIR the IORTable.\n")));
          return CORBA::Object::_nil ();
        }

      // Creating in process nameservice
      CosNaming::NamingContext_var plan_nc;
      if (this->options_.create_plan_ns_)
        {
          DANCE_DEBUG (DANCE_LOG_TRACE,
                       (LM_TRACE, DLINFO
                        ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT ("Resolving plan-specific naming context.\n")));
          CORBA::Object_var naming_obj;
          if (0 != this->options_.create_plan_ns_ior_)
            {
              naming_obj = orb->string_to_object (this->options_.create_plan_ns_ior_);
              plan_nc = CosNaming::NamingContext::_narrow (naming_obj.in());
              if (CORBA::is_nil (plan_nc.in()))
                {
                  DANCE_ERROR (DANCE_LOG_EMERGENCY,
                               (LM_ERROR, DLINFO
                                ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                                ACE_TEXT ("Failed trying to narrow naming context ")
                                ACE_TEXT ("for dance creating plan NC.\n")
                                ACE_TEXT ("Use the \"--create-plan-ns NC ior\" ")
                                ACE_TEXT ("or \"--process-ns\" option.\n")));
                  return CORBA::Object::_nil ();
                }
            }
          else if (this->options_.process_ns_)
            {
              naming_obj = orb->resolve_initial_references ("NameService");
              if (0 != this->options_.process_ns_file_)
                {
                  CORBA::String_var ior = orb->object_to_string (naming_obj.in ());
                  DAnCE::Node_Manager::write_IOR (this->options_.process_ns_file_, ior.in ());
                }
              plan_nc = CosNaming::NamingContext::_narrow (naming_obj.in ());
              if (CORBA::is_nil (plan_nc.in ()))
                {
                  DANCE_ERROR (DANCE_LOG_EMERGENCY,
                               (LM_ERROR, DLINFO
                                ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                                ACE_TEXT ("Fails trying to narrow naming context ")
                                ACE_TEXT ("for dance creating plan NC.\n")
                                ACE_TEXT ("Use the \"--create-plan-ns NC ior\" ")
                                ACE_TEXT ("or \"--process-ns\" option.\n")));
                  return CORBA::Object::_nil ();
                }
            }
          else if (CORBA::is_nil (this->domain_nc_.in ()))
            {
              DANCE_ERROR (DANCE_LOG_EMERGENCY,
                           (LM_ERROR, DLINFO
                            ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                            ACE_TEXT ("The create plan is enabled but neither NC ior ")
                            ACE_TEXT ("nor --process-ns or DomainNC option are not supplied.\n")
                            ACE_TEXT ("Use the \"--create-plan-ns NC ior\", \"--process-ns\" ")
                            ACE_TEXT ("or \"-ORBInitRef DomainNC\" option.\n")));
              return CORBA::Object::_nil ();
            }
          else
            {
              plan_nc = CosNaming::NamingContext::_duplicate (this->domain_nc_.in ());
            }
        }

      // Parsing Node name and node manager ior file name
      ACE_TString node_name = this->options_.node_managers_[0].c_str ();
      ACE_TString node_file;
      size_t npos = node_name.find ('=');
      if (ACE_CString::npos != npos)
        {
          node_file = node_name.substring (npos + 1, node_name.length() - npos + 1);
          node_name = node_name.substring (0, npos);
        }

      // load service modules for artifact installation service
      load_artifact_installation_modules (argc, argv);

      // Creating in process artifact installation service
      DAnCE::ArtifactInstallation_Impl* installer = 0;
      ACE_NEW_RETURN (installer,
                      DAnCE::ArtifactInstallation_Impl (),
                      CORBA::Object::_nil ());
      PortableServer::Servant_var<DAnCE::ArtifactInstallation_Impl> safe_installer (installer);

      ACE_CString installer_oid_str = ACE_TEXT_ALWAYS_CHAR ((node_name + ACE_TEXT (".ArtifactInstaller")).c_str ());

      // Registering servant in poa
      PortableServer::ObjectId_var installer_oid =
        PortableServer::string_to_ObjectId (installer_oid_str.c_str());
      this->nm_poa_->activate_object_with_id (installer_oid, safe_installer._retn ());

      CORBA::Object_var installer_object = this->nm_poa_->id_to_reference (installer_oid.in ());
      this->installer_ = DAnCE::ArtifactInstallation::_narrow (installer_object.in ());

      // Getting node manager ior
      CORBA::String_var installer_ior = orb->object_to_string (installer_object.in ());

      // Binding ior to IOR Table
      adapter->bind (installer_oid_str.c_str (), installer_ior.in ());

      // Make sure that we have only one Node Manager
      if (this->options_.node_managers_.size () != 1)
        {
          DANCE_ERROR (DANCE_LOG_EMERGENCY,
                       (LM_ERROR, DLINFO
                        ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT ("For now only one node manager creation is supported.\n")));
          return CORBA::Object::_nil ();
        }

      DANCE_DEBUG (DANCE_LOG_MINOR_EVENT,
                   (LM_DEBUG, DLINFO
                    ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                    ACE_TEXT ("DAnCE_NodeManager::run_main - creating NodeManager for node %C\n"),
                    this->options_.node_managers_[0].c_str()));

      //Creating node manager servant
      DAnCE::NodeManager_Impl * nm = 0;
      if (this->nm_map_.find (node_name, nm) == -1)
        {
          DANCE_DEBUG (DANCE_LOG_EVENT_TRACE,
                       (LM_TRACE, DLINFO
                        ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT ("Allocating new NodeManager servant instance for NodeManager\n")));
          int size = 64;
          DAnCE::Utility::PROPERTY_MAP properties (size);
          this->create_nm_properties (properties);

          ACE_NEW_RETURN (nm,
                          DAnCE::NodeManager_Impl (orb,
                                                   this->root_poa_.in (),
                                                   this->installer_.in (),
                                                   ACE_TEXT_ALWAYS_CHAR (node_name.c_str()),
                                                   this->options_.node_config_,
                                                   properties),
                          CORBA::Object::_nil ());
          DANCE_TRACE_LOG (DANCE_LOG_TRACE,
                           (LM_TRACE, DLINFO
                            ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                            ACE_TEXT ("New NodeManager servant instance for NodeManager allocated.\n")));
          this->nm_map_.bind (node_name, nm);
        }

      ACE_CString node_manager_oid = ACE_TEXT_ALWAYS_CHAR ((node_name + ACE_TEXT (".NodeManager")).c_str ());

      // Registering servant in poa
      PortableServer::ObjectId_var oid =
        PortableServer::string_to_ObjectId (node_manager_oid.c_str());
      this->nm_poa_->activate_object_with_id (oid, nm);

      // Getting node manager ior
      CORBA::Object_var nm_obj = this->nm_poa_->id_to_reference (oid.in ());
      CORBA::String_var ior = orb->object_to_string (nm_obj.in ());

      // Binding ior to IOR Table
      adapter->bind (node_manager_oid.c_str (), ior.in ());

      // Binding node manager to DomainNC
      if (!CORBA::is_nil (this->domain_nc_.in ()))
        {
          DANCE_DEBUG (DANCE_LOG_MAJOR_DEBUG_INFO,
                       (LM_TRACE, DLINFO
                        ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT ("Registering NM in NC as \"%C.NodeManager\".\n"), node_name.c_str ()));
          CosNaming::Name name (1);
          name.length (1);
          name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (node_name.c_str ()));
          name[0].kind = CORBA::string_dup ("NodeManager");
          this->domain_nc_->rebind (name, nm_obj.in ());
        }

      // Writing ior to file
      if (0 != node_file.length ())
        {
          DANCE_DEBUG (DANCE_LOG_EVENT_TRACE,
                       (LM_TRACE,  DLINFO
                        ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                        ACE_TEXT ("Writing node IOR %C to file %C.\n"), node_file.c_str (), ior.in ()));
          if (!DAnCE::Node_Manager::write_IOR (node_file.c_str (), ior.in ()))
            DANCE_ERROR (DANCE_LOG_NONFATAL_ERROR,
                         (LM_ERROR, DLINFO
                          ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                          ACE_TEXT ("Error: Unable to write IOR to file %C\n"),
                          node_file.c_str ()));
        }

      // Activate POA manager
      PortableServer::POAManager_var mgr = this->root_poa_->the_POAManager ();
      mgr->activate ();

      // Finishing Deployment part
      DANCE_DEBUG (DANCE_LOG_MAJOR_EVENT,
                   (LM_NOTICE, DLINFO
                    ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                    ACE_TEXT ("DAnCE_NodeManager is running...\n")));

      DANCE_DEBUG (DANCE_LOG_MAJOR_DEBUG_INFO,
                   (LM_DEBUG, DLINFO
                    ACE_TEXT ("DAnCE_NodeManager_Module::init - ")
                    ACE_TEXT ("NodeManager IOR: %C\n"), ior.in ()));

      return nm_obj._retn ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("DAnCE_NodeManager::main\t\n");
      return CORBA::Object::_nil ();
    }
}
Пример #8
0
CORBA::Object_ptr
DAnCE_RepositoryManager_Module::init (CORBA::ORB_ptr orb,
                                               int argc,
                                               ACE_TCHAR *argv[])
{
  DANCE_TRACE ("DAnCE_RepositoryManager_Module::init");

  try
    {
      if (CORBA::is_nil(orb))
        {
          DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR,
                       (LM_ERROR, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                       ACE_TEXT("Attempted to create Repository Manager with a nil orb.\n")));
          return CORBA::Object::_nil();
        }
      else
        {
          this->orb_ = CORBA::ORB::_duplicate (orb);
        }

      if (ACE_OS::strcmp(orb->id(), this->orb_->id()) != 0)
        {
          DANCE_TRACE_LOG (DANCE_LOG_TRACE,
                           (LM_TRACE, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                            ACE_TEXT("Resetting NM's orb.\n")));
          this->orb_ = CORBA::ORB::_duplicate (orb);
          this->domain_nc_ = CosNaming::NamingContext::_nil();
        }

      if (!this->parse_args (argc, argv))
        {
          return CORBA::Object::_nil ();
        }

      if (this->options_.spawn_http_)
        this->spawn_http ();

      this->create_poas ();

      if (this->options_.domain_nc_)
        {
          try
            {
              DANCE_TRACE_LOG (DANCE_LOG_TRACE,
                               (LM_TRACE, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                                ACE_TEXT("Resolving DomainNC.\n")));
              CORBA::Object_var domain_obj = this->orb_->string_to_object (this->options_.domain_nc_);
              if (!CORBA::is_nil (domain_obj.in ()))
                {
                  this->domain_nc_ = CosNaming::NamingContext::_narrow (domain_obj.in());
                  if (CORBA::is_nil (this->domain_nc_.in ()))
                    {
                      DANCE_ERROR (DANCE_LOG_ERROR,
                                   (LM_ERROR,DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                                    ACE_TEXT("Narrow to NamingContext return nil for DomainNC.\n")));
                      return CORBA::Object::_nil ();
                    }
                }
            }
          catch (const CORBA::Exception&)
            {
              DANCE_DEBUG (DANCE_LOG_ERROR,
                           (LM_WARNING, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                            ACE_TEXT("DomainNC context not found!\n")));
            }
        }


      DANCE_TRACE_LOG (DANCE_LOG_TRACE,
                       (LM_TRACE, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                        ACE_TEXT("Initializing the IOR Table\n")));
      // Initialize IOR table
      CORBA::Object_var table_object = orb->resolve_initial_references ("IORTable");

      IORTable::Table_var adapter = IORTable::Table::_narrow (table_object.in ());

      if (CORBA::is_nil (adapter.in ()))
        {
          DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR,
                       (LM_ERROR, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                        ACE_TEXT("Unable to RIR the IORTable.\n")));
          return CORBA::Object::_nil ();
        }


      //Creating repository manager servant
      DAnCE::RepositoryManagerDaemon_i * rm = new DAnCE::RepositoryManagerDaemon_i (orb,
                                                                                    this->options_.server_address_,
                                                                                    this->options_.package_dir_);
      PortableServer::ServantBase_var safe_svt (rm);

      ACE_CString repository_manager_oid;

      if (this->options_.name_ == 0)
        repository_manager_oid = "RepositoryManager";
      else
        {
          repository_manager_oid = this->options_.name_;
          repository_manager_oid += ".RepositoryManager";
        }

      // Registering servant in poa
      PortableServer::ObjectId_var oid =
        PortableServer::string_to_ObjectId (repository_manager_oid.c_str());
      this->rm_poa_->activate_object_with_id (oid, rm);

      // Getting repository manager ior
      CORBA::Object_var nm_obj = this->rm_poa_->id_to_reference (oid.in ());
      CORBA::String_var ior = orb->object_to_string (nm_obj.in ());

      // Binding ior to IOR Table
      adapter->bind (repository_manager_oid.c_str (), ior.in ());

      // Binding repository manager to DomainNC
      if (!CORBA::is_nil (this->domain_nc_.in ()))
        {
          ACE_CString ns_name;
          if (this->options_.name_ == 0)
            ns_name = "RepositoryManager";
          else ns_name = this->options_.name_;

          DANCE_DEBUG (DANCE_LOG_MINOR_EVENT,
                       (LM_TRACE, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                        ACE_TEXT("Registering NM in NC as \"%C\".\n"), ns_name.c_str ()));
          CosNaming::Name name (1);
          name.length (1);
          name[0].id = CORBA::string_dup (ns_name.c_str ());
          name[0].kind = CORBA::string_dup ("RepositoryManager");
          this->domain_nc_->rebind (name, nm_obj.in ());
        }

      // Writing ior to file
      if (0 != this->options_.ior_file_)
        {
          DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE,  DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                        ACE_TEXT("Writing RM IOR %C to file %C.\n"), this->options_.ior_file_, ior.in ()));
          if (!DAnCE::Repository_Manager::write_IOR (this->options_.ior_file_, ior.in ()))
            DANCE_ERROR (DANCE_LOG_ERROR, (LM_ERROR, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                          ACE_TEXT("Error: Unable to write IOR to file %C\n"),
                          this->options_.ior_file_));
        }

      // Activate POA manager
      PortableServer::POAManager_var mgr = this->root_poa_->the_POAManager ();
      mgr->activate ();

      // Finishing Deployment part
      DANCE_DEBUG (DANCE_LOG_MAJOR_EVENT,
                   (LM_NOTICE, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                    ACE_TEXT("DAnCE_RepositoryManager is running...\n")));

      DANCE_DEBUG (DANCE_LOG_MAJOR_DEBUG_INFO,
                   (LM_DEBUG, DLINFO ACE_TEXT("DAnCE_RepositoryManager_Module::init - ")
                    ACE_TEXT("RepositoryManager IOR: %C\n"), ior.in ()));

      return nm_obj._retn ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("DAnCE_RepositoryManager::main\t\n");
      return CORBA::Object::_nil ();
    }
}
Пример #9
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  DANCE_DISABLE_TRACE ();

  int retval = 0;

  try
    {
      DAnCE::Logger_Service * dlf =
        ACE_Dynamic_Service<DAnCE::Logger_Service>::instance ("DAnCE_Logger");

      if (dlf)
        {
          dlf->init (argc, argv);
        }

      DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO
                    ACE_TEXT("SHS_Deamon - initializing ORB\n")));

      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO
            ACE_TEXT("SHS_Deamon - initializing module instance\n")));


      TAO::Utils::ORB_Destroyer safe_orb (orb);

      CORBA::Object_var tmp = orb->resolve_initial_references ("NameService");
      CosNaming::NamingContext_var domain_nc =
        CosNaming::NamingContext::_narrow (tmp);

      if (CORBA::is_nil (domain_nc.in ()))
        {
          ACE_ERROR ((LM_EMERGENCY,
            "SHS_Daemon - Unable to register with the"\
            " CORBA Naming Service\n"));
          return -1;
        }

      CORBA::Object_var poa_obj
        = orb->resolve_initial_references ("RootPOA");

      PortableServer::POA_var poa
        = PortableServer::POA::_narrow (poa_obj.in ());

      PortableServer::POAManager_var mgr = poa->the_POAManager ();
      PortableServer::POA_var persistent_poa;
      TAO::Utils::PolicyList_Destroyer policies (2);
      policies.length (2);
      try
        {
          DANCE_DEBUG (DANCE_LOG_TRACE, (LM_TRACE,
            DLINFO ACE_TEXT("SHS_Deamon - ")
            ACE_TEXT("before creating the \"SHS\" POA.\n")));

          policies[0] = poa->create_id_assignment_policy (
            PortableServer::USER_ID);
          policies[1] = poa->create_lifespan_policy (
            PortableServer::PERSISTENT);
          persistent_poa = poa->create_POA ("SHS",
                                            mgr.in(),
                                            policies);
        }
      catch (const PortableServer::POA::AdapterAlreadyExists &)
        {
          persistent_poa = poa->find_POA ("Managers", 0);
        }

      DAnCE::SHS_Daemon_i *shs_daemon (0);

      ACE_NEW_RETURN (shs_daemon,
                      DAnCE::SHS_Daemon_i (orb.in ()),
                      0);

      PortableServer::ServantBase_var safe_servant (shs_daemon);
      PortableServer::ObjectId_var oid =
        PortableServer::string_to_ObjectId ("SHS_Daemon");
      persistent_poa->activate_object_with_id (oid, shs_daemon);

      CORBA::Object_var shs_obj = persistent_poa->id_to_reference (oid.in ());
      CORBA::String_var shs_ior = orb->object_to_string (shs_obj.in ());

      DAnCE::Utility::write_IOR (ACE_TEXT ("SHS_Daemon.ior"),
                                 shs_ior.in ());


      CosNaming::Name name (1);
      name.length (1);
      name[0].id = "DAnCE.SystemHealthDaemon";

      domain_nc->rebind (name, shs_obj.in ());

      mgr->activate ();
      orb->run ();

      DANCE_DEBUG (DANCE_LOG_EVENT_TRACE, (LM_TRACE, DLINFO
                       ACE_TEXT("SHS_Daemon - destroying ORB\n")));

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("SHS_Daemon");
      retval = -1;
    }
  catch (...)
    {
      DANCE_ERROR (DANCE_LOG_TERMINAL_ERROR,
        (LM_ERROR, "SHS_Daemon - Error: Unknown exception.\n"));
      retval = -1;
    }

  return retval;
}
Пример #10
0
int
ImR_Activator_i::init_with_orb (CORBA::ORB_ptr orb, const Activator_Options& opts)
{
  ACE_ASSERT(! CORBA::is_nil (orb));
  orb_ = CORBA::ORB::_duplicate (orb);
  debug_ = opts.debug ();
  notify_imr_ = opts.notify_imr ();
  induce_delay_ = opts.induce_delay ();
  env_buf_len_ = opts.env_buf_len ();
  max_env_vars_ = opts.max_env_vars ();
  detach_child_ = opts.detach_child ();

  if (opts.name ().length () > 0)
    {
      name_ = opts.name();
    }

  try
    {
      CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
      ACE_ASSERT (! CORBA::is_nil (obj.in ()));
      this->root_poa_ = PortableServer::POA::_narrow (obj.in ());
      ACE_ASSERT (! CORBA::is_nil(this->root_poa_.in ()));

      // The activator must use a persistent POA so that it can be started before the
      // locator in some scenarios, such as when the locator persists its database, and
      // wants to reconnect to running activators to auto_start some servers.
      this->imr_poa_ = createPersistentPOA (this->root_poa_.in (),
                                            "ImR_Activator");
      ACE_ASSERT (! CORBA::is_nil(this->imr_poa_.in ()));

      obj = orb->resolve_initial_references ("POACurrent");
      ACE_ASSERT (! CORBA::is_nil (obj.in ()));
      this->current_ = PortableServer::Current::_narrow (obj.in ());

      // Activate ourself
      PortableServer::ObjectId_var id =
        PortableServer::string_to_ObjectId ("ImR_Activator");
      this->imr_poa_->activate_object_with_id (id.in (), this);
      obj = this->imr_poa_->id_to_reference (id.in ());
      ImplementationRepository::ActivatorExt_var activator =
        ImplementationRepository::ActivatorExt::_narrow (obj.in ());
      ACE_ASSERT(! CORBA::is_nil (activator.in ()));

      CORBA::String_var ior = this->orb_->object_to_string (activator.in ());

      if (this->debug_ > 0)
        ORBSVCS_DEBUG((LM_DEBUG, "ImR Activator: Starting %C\n", name_.c_str ()));

      // initialize our process manager.
      // This requires a reactor that has signal handling.
      ACE_Reactor *reactor = ACE_Reactor::instance ();
      if (reactor != 0)
        {
          if (this->process_mgr_.open (ACE_Process_Manager::DEFAULT_SIZE, reactor) == -1)
            {
              ORBSVCS_ERROR_RETURN ((LM_ERROR,
                                     "The ACE_Process_Manager didnt get initialized\n"), -1);
            }
        }

      this->register_with_imr (activator.in ()); // no throw

      PortableServer::POAManager_var poaman =
        this->root_poa_->the_POAManager ();
      poaman->activate ();

      if (this->debug_ > 1)
        {
          ORBSVCS_DEBUG ((LM_DEBUG,
                          "ImR Activator: The Activator IOR is: <%C>\n", ior.in ()));
        }

      // The last thing we do is write out the ior so that a test program can assume
      // that the activator is ready to go as soon as the ior is written.
      if (opts.ior_filename ().length () > 0)
        {
          FILE* fp = ACE_OS::fopen (opts.ior_filename ().c_str (), "w");
          if (fp == 0)
            {
              ORBSVCS_ERROR_RETURN ((LM_ERROR,
                                     "ImR Activator: Could not open file: %s\n", opts.ior_filename ().c_str ()), -1);
            }
          ACE_OS::fprintf (fp, "%s", ior.in ());
          ACE_OS::fclose (fp);
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
                               "ImR_Activator_i::init_with_orb");
      throw;
    }
  return 0;
}