📄 imr_activator_i.cpp
字号:
this->repository_.remove (server);
// Add server with new startup parameters
this->repository_.add (server,
"",
options.command_line.in (),
options.environment,
options.working_directory.in (),
options.activation);
// Set the old running info
if (location.length () != 0)
this->repository_.update (server, location, server_object_ior);
// Set old starting up value, if there was one.
if (starting_up != -1)
this->repository_.starting_up (server, starting_up);
if (OPTIONS::instance()->debug () >= 2)
{
ACE_DEBUG ((LM_DEBUG, "ImR_Activator_i::reregister_server:\nServer: %s\n"
"Command Line: %s\n"
"Working Directory: %s\n"
"Activation: %s\n\n",
server,
options.command_line.in (),
options.working_directory.in (),
OPTIONS::instance ()->convert_str (options.activation)));
for (CORBA::ULong i = 0; i < options.environment.length (); ++i)
ACE_DEBUG ((LM_DEBUG, "Environment variable %s=%s\n",
options.environment[i].name.in (),
options.environment[i].value.in ()));
}
}
// Remove the server entry from the Repository
void
ImR_Activator_i::remove_server (const char *server
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException,
ImplementationRepository::NotFound))
{
if (OPTIONS::instance ()->readonly ())
{
ACE_ERROR ((LM_ERROR,
"ImR Activator: Activator is readonly. Can't remove server %s.\n",
server));
ACE_THROW (CORBA::NO_PERMISSION ());
}
if (this->repository_.remove (server) == 0)
{
if (OPTIONS::instance()->debug () >= 1)
ACE_DEBUG ((LM_DEBUG, "ImR Activator: Removed Server %s.\n", server));
}
else
{
ACE_ERROR ((LM_ERROR,
"ImR Activator: Can't remove unknown server %s.\n",
server));
ACE_THROW (ImplementationRepository::NotFound ());
}
}
// Register the current location of the server
void
ImR_Activator_i::server_is_running (const char *server,
const char *partial_ior,
ImplementationRepository::ServerObject_ptr server_object
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException, ImplementationRepository::NotFound))
{
CORBA::ORB_var orb = OPTIONS::instance ()->orb ();
if (OPTIONS::instance()->debug () >= 1)
ACE_DEBUG ((LM_DEBUG, "ImR Activator: Server %s is running.\n", server));
if (OPTIONS::instance()->debug () >= 2)
ACE_DEBUG ((LM_DEBUG, "ImR_Activator_i::server_is_running: at %s\n", partial_ior));
CORBA::String_var server_object_ior =
orb->object_to_string (server_object ACE_ENV_ARG_PARAMETER);
ACE_CHECK;
// Update the status of the server in the repository.
if (this->repository_.update (server, partial_ior, server_object_ior.in ()) == 0)
{
if (OPTIONS::instance()->debug () >= 1)
ACE_DEBUG ((LM_DEBUG,
"ImR Activator: Status updated for server %s.\n", server));
}
else
{
ACE_ERROR ((LM_ERROR,
"ImR Activator: Could not update running information for server <%s>\n",
server));
ACE_THROW(ImplementationRepository::NotFound());
}
this->repository_.starting_up (server, 0);
}
// Remove the state information for the current server
void
ImR_Activator_i::server_is_shutting_down (const char *server ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException,
ImplementationRepository::NotFound))
{
if (this->repository_.update (server, "", "") == 0)
{
if (OPTIONS::instance()->debug () >= 1)
ACE_DEBUG ((LM_DEBUG, "ImR Activator: Shut down server %s.\n", server));
}
else
{
ACE_ERROR ((LM_ERROR,
"ImR Activator: Could not update information for unknown server <%s>\n",
server));
ACE_THROW (ImplementationRepository::NotFound ());
}
}
int
ImR_Activator_i::init (ACE_ENV_SINGLE_ARG_DECL)
{
CORBA::ORB_var orb = OPTIONS::instance ()->orb ();
ACE_TRY
{
CORBA::Object_var obj =
orb->resolve_initial_references ("IORTable" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
IORTable::Table_var adapter =
IORTable::Table::_narrow (obj.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (adapter.in ()))
{
ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
return -1;
}
obj = orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (obj.in ()))
{
ACE_ERROR_RETURN ((LM_ERROR,
"Unable to initialize the ROOT POA.\n"),
-1);
}
this->root_poa_ = PortableServer::POA::_narrow (obj.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POAManager_var poa_manager =
this->root_poa_->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
CORBA::PolicyList policies (2);
policies.length (2);
policies[0] =
this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
policies[1] =
this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Create a child POA with userId "ImR_Activator"
this->imr_poa_ =
this->root_poa_->create_POA ("ImR_Activator",
poa_manager.in (),
policies
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// If create_POA throws an exception then the process will end, and free all memory.
for (CORBA::ULong i = 0; i < policies.length (); ++i)
{
CORBA::Policy_ptr policy = policies[i];
policy->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
}
// Get the ObjectId for the string 'ImR_Activator'
PortableServer::ObjectId_var imr_id =
PortableServer::string_to_ObjectId ("ImR_Activator");
// Activate the object
this->imr_poa_->activate_object_with_id (imr_id.in (),
this
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
obj = this->imr_poa_->id_to_reference (imr_id.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ImplementationRepository::Administration_var activator =
ImplementationRepository::Administration::_narrow(obj.in() ACE_ENV_ARG_PARAMETER);
CORBA::String_var ior = orb->object_to_string (activator.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
adapter->bind ("ImR_Activator", ior.in() ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
obj = orb->resolve_initial_references ("ImplRepoService" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (obj.in ()))
{
ACE_ERROR_RETURN ((LM_ERROR,
"Unable to get a reference to a Locator.\n"),
-1);
}
ImplementationRepository::Locator_var locator =
ImplementationRepository::Locator::_narrow (obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG((LM_DEBUG, "Starting activator : %s\n", this->name_.c_str()));
ACE_Reactor *reactor = orb->orb_core ()->reactor ();
if (reactor != 0)
{
if (this->process_mgr_.open (ACE_Process_Manager::DEFAULT_SIZE,
reactor) == -1)
{
ACE_ERROR_RETURN ((LM_ERROR,
"The ACE_Process_Manager didnt get initialized\n"),
-1);
}
}
// Initialize the persistent storage
if (this->repository_.init ())
{
ACE_ERROR_RETURN ((LM_ERROR,
"Repository failed to initialize\n"),
-1);
}
// We need to send the list of our persisted server names to the Locator
// so that it knows we are managing them.
auto_ptr<Server_Repository::HASH_IMR_MAP::ITERATOR>
server_iter(this->repository_.new_iterator());
if (server_iter.get () == 0)
{
ACE_THROW_RETURN (CORBA::NO_MEMORY (), -1);
}
ImplementationRepository::Locator::ServerNameList server_names;
server_names.length(this->repository_.get_repository_size());
Server_Repository::HASH_IMR_MAP::ENTRY* next_entry = 0;
for (CORBA::ULong idx = 0;server_iter->next(next_entry) != 0; server_iter->advance())
{
ACE_CString server_name = next_entry->ext_id_;
server_names[idx++] = server_name.c_str();
}
this->registration_token_ =
locator->register_activator (this->name_.c_str(),
activator.in (),
server_names
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// 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 (OPTIONS::instance ()->debug () >= 2)
{
ACE_DEBUG ((LM_DEBUG,
"ImR_Activator_i::init: The Activator IOR is: <%s>\n",
ior.in ()));
}
ACE_CString filename = OPTIONS::instance()->output_filename();
if (filename.length() > 0)
{
FILE* fp = ACE_OS::fopen(filename.c_str(), "w");
if (fp != 0) {
ACE_OS::fprintf(fp, "%s", ior.in());
ACE_OS::fclose(fp);
} else {
ACE_ERROR((LM_ERROR, "ImR Activator: Could not open file %s\n", filename.c_str()));
}
}
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Server_i::init");
ACE_RE_THROW;
}
ACE_ENDTRY;
ACE_CHECK_RETURN (-1);
return 0;
}
int
ImR_Activator_i::fini (ACE_ENV_SINGLE_ARG_DECL)
{
CORBA::ORB_var orb = OPTIONS::instance ()->orb ();
ACE_TRY
{
CORBA::Object_var table_object =
orb->resolve_initial_references ("IORTable" ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
IORTable::Table_var adapter =
IORTable::Table::_narrow (table_object.in () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (adapter.in ()))
{
ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
}
else
{
adapter->set_locator (IORTable::Locator::_nil ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
}
this->imr_poa_->destroy (1, 1 ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -