📄 imr_activator_i.cpp
字号:
ACE_CHECK;
}
else if (OPTIONS::instance ()->debug () >= 2)
ACE_DEBUG ((LM_DEBUG, "ImR_Activator_i::start_server_i: Process ID is %d\n", spawned_pid));
}
// Now that the server has been started up, we need to go back into the event
// loop so we can get the reponse or handle other requests
TAO_ORB_Core *orb_core = orb->orb_core ();
int starting_up;
ACE_Time_Value timeout = OPTIONS::instance ()->startup_timeout ();
// We will wait till the timeout period for the server to get
// started up. The starting_up value will be made zero when the
// server is up and running. And, thats the condition that we are
// checking.
while ((starting_up = this->repository_.starting_up (server)) == 1)
{
if (OPTIONS::instance()->debug () >= 2)
ACE_DEBUG ((LM_DEBUG, "ImR_Activator_i::activate_server: Going into handle_events\n"));
// Will wait for the specified timeout.
int result = orb_core->reactor ()->handle_events (&timeout);
if (result == 0 && timeout == ACE_Time_Value::zero)
{
// The timer is out and we are still in the while loop which
// means that the server is not activated. Set the
// starting_up_ value to '0' and
this->repository_.starting_up (server, 0);
// print the same.
ACE_ERROR ((LM_ERROR,
"ImR Activator: Cannot activate server <%s> using <%s>, "
"terminating it.\n",
server,
startup.c_str ()));
// Kill the server
this->process_mgr_.terminate (spawned_pid);
ACE_THROW(ImplementationRepository::CannotActivate
(CORBA::string_dup ("Timeout")));
ACE_CHECK;
}
}
// If the control comes here, it means that the server got activated.
if (OPTIONS::instance()->debug () >= 2)
ACE_DEBUG ((LM_DEBUG, "ImR_Activator_i::activate_server: Got out of handle_events loop\n"));
// Check to see if it disappeared on us
if (starting_up == -1)
{
ACE_ERROR ((LM_ERROR,
"ImR Activator: Cannot find startup info for server <%s>\n",
server));
ACE_THROW (ImplementationRepository::NotFound ());
ACE_CHECK;
}
// Now check to see if it is responding yet.
int ready_error = this->ready_check (server);
if (ready_error < 0)
{
// We got an error in ready_check, so shutdown the server and
// throw an exception
this->process_mgr_.terminate (spawned_pid);
if (ready_error == -1)
{
ACE_THROW (ImplementationRepository::CannotActivate
(CORBA::string_dup ("Timeout while pinging for readiness")));
}
else
{
ACE_THROW (ImplementationRepository::CannotActivate
(CORBA::string_dup ("Unknown error")));
}
}
}
// ready_check will continuously ping a server and either return when it
// responds to the ping or return -1 if it times out.
int
ImR_Activator_i::ready_check (const char *server)
ACE_THROW_SPEC ((CORBA::SystemException,
ImplementationRepository::NotFound))
{
CORBA::ORB_var orb = OPTIONS::instance ()->orb ();
ACE_CString ping_object_ior, location;
ImplementationRepository::ServerObject_var ping_object;
ACE_DECLARE_NEW_CORBA_ENV;
// <end> is the end of the window where we can get a response before
// timing out
ACE_Time_Value end = ACE_OS::gettimeofday ()
+ OPTIONS::instance ()->startup_timeout ();
// Get the ior for the "ping" object for the server
if (this->repository_.get_running_info (server,
location,
ping_object_ior) != 0)
{
// If get_running_info fails, something weird must have happened.
// Maybe it was removed after we started it up, but before we got here.
ACE_ERROR ((LM_ERROR,
"ImR Activator: Cannot find ServerObject IOR for server <%s>\n",
server));
ACE_THROW_RETURN (
ImplementationRepository::NotFound (),
-2
);
}
// Narrow the ping object
ACE_TRY_EX (ping1)
{
// Get the Object
CORBA::Object_var object =
orb->string_to_object (ping_object_ior.c_str () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK_EX (ping1);
// Narrow it down to the correct interface
ping_object =
ImplementationRepository::ServerObject::_narrow (object.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK_EX (ping1);
if (CORBA::is_nil (ping_object.in ()))
{
ACE_ERROR ((LM_ERROR,
"ImR Activator: Invalid ServerObject IOR: <%s>\n",
ping_object_ior.c_str ()));
ACE_THROW_RETURN (
ImplementationRepository::NotFound (),
-2
);
}
}
ACE_CATCHANY
{
ACE_ERROR ((LM_ERROR,
"ImR Activator: Cannot activate server <%s>, "
"terminating it (Server Ping Object failed).\n",
server));
return -2;
}
ACE_ENDTRY;
ACE_CHECK_RETURN (-2);
// Now ping it until we get a response.
while (ACE_OS::gettimeofday () < end)
{
ACE_TRY_EX (ping2);
{
if (OPTIONS::instance()->debug () >= 2)
ACE_DEBUG ((LM_DEBUG, "ImR_Activator_i::ready_check: ping server.\n"));
ping_object->ping (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK_EX (ping2);
if (OPTIONS::instance()->debug () >= 2)
ACE_DEBUG ((LM_DEBUG, "ImR_Activator_i::ready_check: Pinged Server OK\n"));
// If we got here, we successfully pinged, therefore we
// can exit the function.
return 0;
}
ACE_CATCHANY // todo : I doubt we really want to retry on all exceptions. Maybe just transient?
{
// Ignore the exception
if (OPTIONS::instance()->debug () >= 2)
ACE_DEBUG ((LM_DEBUG, "ImR_Activator_i::ready_check: Server not ready (Exception)\n"));
}
ACE_ENDTRY;
ACE_CHECK_RETURN (-2);
// Sleep between sending pings.
ACE_OS::sleep (OPTIONS::instance ()->ping_interval ());
}
// If we fall out here, that means we didn't get a response before timing
// out, so return an error.
return -1;
}
// Adds an entry to the Repository about this <server>
void
ImR_Activator_i::register_server (
const char *server,
const ImplementationRepository::StartupOptions &options
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException,
ImplementationRepository::AlreadyRegistered,
ImplementationRepository::NotFound
))
{
if (OPTIONS::instance ()->readonly ())
{
ACE_THROW (CORBA::NO_PERMISSION ());
}
if (OPTIONS::instance ()->debug () >= 1)
ACE_DEBUG((LM_DEBUG, "Imr Activator: Register server %s.\n", server));
if (OPTIONS::instance ()->debug () >= 2)
{
ACE_DEBUG ((LM_DEBUG,
"ImR_Activator_i::register_server:\nServer: %s\n"
"Command Line: %s\n"
"Working Directory: %s\n"
"Activation Mode: %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 ()));
}
// Add the server
int status = this->repository_.add (server,
"",
options.command_line.in (),
options.environment,
options.working_directory.in (),
options.activation);
if (status == 1)
{
ACE_ERROR ((LM_ERROR,
"ImR Activator: Server %s Already Registered!\n",
server));
ACE_THROW (ImplementationRepository::AlreadyRegistered ());
}
}
// Updates the entry in the Repository about this <server> or adds it
// if necessary.
void
ImR_Activator_i::reregister_server (const char *server,
const ImplementationRepository::StartupOptions &options
ACE_ENV_ARG_DECL)
ACE_THROW_SPEC ((CORBA::SystemException,
ImplementationRepository::AlreadyRegistered,
ImplementationRepository::NotFound
))
{
if (OPTIONS::instance ()->debug () >= 1)
ACE_DEBUG((LM_DEBUG, "ImR Activator: Reregister server %s.\n", server));
if (OPTIONS::instance ()->readonly ())
{
ACE_THROW (CORBA::NO_PERMISSION ());
}
// Get current starting up value
int starting_up = this->repository_.starting_up (server);
// Get ready to save the running info
ACE_CString location;
ACE_CString server_object_ior;
// Only save the running info if it's still running before we remove it.
ACE_TRY
{
// Get the current running information
ACE_CString ping_location;
ACE_CString ping_object_ior;
this->repository_.get_running_info (server,
ping_location,
ping_object_ior);
// Narrow the server
CORBA::ORB_var orb = OPTIONS::instance ()->orb ();
CORBA::Object_var object =
orb->string_to_object (ping_object_ior.c_str () ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ImplementationRepository::ServerObject_var ping_object =
ImplementationRepository::ServerObject::_narrow (object.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (!CORBA::is_nil (ping_object.in ()))
{
// Ok, we've found our ior, now we remove the server from the
// repository in order to avoid restarting it if it's not
// running
this->repository_.remove (server);
// Now ping the object
ping_object->ping (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// If the ping succeeded, then we will save the
// running information for this server
location = ping_location;
server_object_ior = ping_object_ior;
}
}
ACE_CATCHANY
{
// Ignore all exceptions
}
ACE_ENDTRY;
// Remove old info
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -