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; 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(); const char* poa_name = "MessengerService"; PortableServer::POA_var poa = createPersistentPOA(root_poa.in(), poa_name); PortableServer::Servant_var<Messenger_i> servant1 = new Messenger_i; PortableServer::Servant_var<Messenger_i> servant2 = new Messenger_i; PortableServer::ObjectId_var id1 = PortableServer::string_to_ObjectId("Object1"); poa->activate_object_with_id(id1.in(), servant1.in()); PortableServer::ObjectId_var id2 = PortableServer::string_to_ObjectId("Object2"); poa->activate_object_with_id(id2.in(), servant2.in()); obj = poa->id_to_reference(id1.in()); CORBA::String_var ior1 = orb->object_to_string(obj.in()); obj = poa->id_to_reference(id2.in()); CORBA::String_var ior2 = orb->object_to_string(obj.in()); TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(poa.in()); obj = tpoa->id_to_reference_i(id1.in(), false); CORBA::String_var direct_ior1 = orb->object_to_string(obj.in()); obj = orb->resolve_initial_references("IORTable"); IORTable::Table_var ior_table = IORTable::Table::_narrow(obj.in()); ior_table->bind("MessengerService/Object1", direct_ior1.in()); ior_table->bind("MessengerService/Object2", ior2.in()); writeIORFile(ior1.in(), ior_output_file1); writeIORFile(ior2.in(), ior_output_file2); mgr->activate(); std::cout << "Messenger server ready." << std::endl; orb->run(); std::cout << "Messenger server shutting down." << std::endl; root_poa->destroy(1,1); orb->destroy(); return 0; } catch(const CORBA::Exception& ex) { std::cerr << "Server main() Caught Exception" << ex << std::endl; } return 1; }
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 (); 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 ())); // 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 %s\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: <%s>\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; }
int ImR_Locator_i::init_with_orb (CORBA::ORB_ptr orb) { this->orb_ = CORBA::ORB::_duplicate (orb); ImR_Locator_i::debug_ = this->opts_->debug (); CORBA::Object_var obj = this->orb_->resolve_initial_references ("RootPOA"); this->root_poa_ = PortableServer::POA::_narrow (obj.in ()); ACE_ASSERT (! CORBA::is_nil (this->root_poa_.in ())); this->dsi_forwarder_.init (orb); this->adapter_.init (& this->dsi_forwarder_); this->pinger_.init (orb, this->opts_->ping_interval ()); this->opts_->pinger (&this->pinger_); // Register the Adapter_Activator reference to be the RootPOA's // Adapter Activator. root_poa_->the_activator (&this->adapter_); // Use a persistent POA so that any IOR this->imr_poa_ = createPersistentPOA (this->root_poa_.in (), "ImplRepo_Service"); ACE_ASSERT (! CORBA::is_nil (this->imr_poa_.in ())); PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("ImplRepo_Service"); this->imr_poa_->activate_object_with_id (id.in (), this); obj = this->imr_poa_->id_to_reference (id.in ()); ImplementationRepository::Locator_var locator = ImplementationRepository::Locator::_narrow (obj.in ()); ACE_ASSERT(! CORBA::is_nil (locator.in ())); const CORBA::String_var ior = this->orb_->object_to_string (obj.in ()); // create the selected Locator_Repository with backing store switch (this->opts_->repository_mode ()) { case Options::REPO_REGISTRY: { repository_.reset(new Registry_Backing_Store(*this->opts_, orb)); break; } case Options::REPO_HEAP_FILE: { repository_.reset(new Heap_Backing_Store(*this->opts_, orb)); break; } case Options::REPO_XML_FILE: { repository_.reset(new XML_Backing_Store(*this->opts_, orb)); break; } case Options::REPO_SHARED_FILES: { repository_.reset(new Shared_Backing_Store(*this->opts_, orb, this)); break; } case Options::REPO_NONE: { repository_.reset(new No_Backing_Store(*this->opts_, orb)); break; } default: { bool invalid_rmode_specified = false; ACE_ASSERT (invalid_rmode_specified); ACE_UNUSED_ARG (invalid_rmode_specified); ORBSVCS_ERROR_RETURN (( LM_ERROR, ACE_TEXT ("Repository failed to initialize\n")), -1); } } // Register the ImR for use with INS obj = orb->resolve_initial_references ("AsyncIORTable"); IORTable::Table_var ior_table = IORTable::Table::_narrow (obj.in ()); ACE_ASSERT (! CORBA::is_nil (ior_table.in ())); ior_table->set_locator (this->ins_locator_.in ()); // initialize the repository. This will load any values that // may have been persisted before. int result = this->repository_->init(this->root_poa_.in (), this->imr_poa_.in (), ior); if (result != 0) { return result; } Locator_Repository::SIMap::ENTRY* entry = 0; Locator_Repository::SIMap::ITERATOR it (this->repository_->servers ()); for (;it.next (entry) != 0; it.advance ()) { UpdateableServerInfo info (this->repository_, entry->int_id_); bool is_alive = this->server_is_alive (info); Server_Info *active = info.edit()->active_info (); if (this->debug_ > 0) { ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("server %C is_alive = %d\n"), active->ping_id(), is_alive)); } if (!is_alive) { info.edit()->reset_runtime (); active->reset_runtime (); continue; } active->death_notify = false; if (active->pid > 0) { Activator_Info_Ptr ainfo = this->get_activator (active->activator); if (!(ainfo.null () || CORBA::is_nil (ainfo->activator.in ()))) { ImplementationRepository::ActivatorExt_var actx = ImplementationRepository::ActivatorExt::_narrow (ainfo->activator.in ()); try { active->death_notify = !CORBA::is_nil (actx.in ()) && actx->still_alive (active->pid); } catch (const CORBA::Exception &) { } if (this->debug_ > 0) { ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("activator says death_notify = %d\n"), active->death_notify)); } } } } //only after verifying do we report the IOR and become open for business return this->repository_->report_ior(this->imr_poa_.in ()); }