ImR_Activator_i Class Reference

IMR Activator Interface. More...

#include <ImR_Activator_i.h>

Inheritance diagram for ImR_Activator_i:

Inheritance graph
[legend]
Collaboration diagram for ImR_Activator_i:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ImR_Activator_i (void)
void start_server (const char *name, const char *cmdline, const char *dir, const ImplementationRepository::EnvironmentList &env)
void shutdown (void)
int init (Activator_Options &opts)
 Initialize the Server state - parsing arguments and waiting.

int fini (void)
 Cleans up any state created by init*.

int run (void)
 Runs the orb.

void shutdown (bool wait_for_completion)
 Shutdown the orb.


Private Types

typedef ACE_Hash_Map_Manager_Ex<
pid_t, ACE_CString, ACE_Hash_pid_t,
ACE_Equal_To_pid_t, ACE_Null_Mutex
ProcessMap

Private Member Functions

int init_with_orb (CORBA::ORB_ptr orb, const Activator_Options &opts)
void register_with_imr (ImplementationRepository::Activator_ptr activator)
int handle_exit (ACE_Process *process)

Private Attributes

ACE_Process_Manager process_mgr_
PortableServer::POA_var root_poa_
PortableServer::POA_var imr_poa_
ImplementationRepository::Locator_var locator_
CORBA::Long registration_token_
CORBA::ORB_var orb_
unsigned int debug_
bool notify_imr_
ACE_CString name_
ProcessMap process_map_
int env_buf_len_
 The default environment buffer length.


Detailed Description

IMR Activator Interface.

This class provides the interface for the various activities that can be done by the ImR_Activator.

Definition at line 60 of file ImR_Activator_i.h.


Member Typedef Documentation

typedef ACE_Hash_Map_Manager_Ex<pid_t, ACE_CString, ACE_Hash_pid_t, ACE_Equal_To_pid_t, ACE_Null_Mutex> ImR_Activator_i::ProcessMap [private]
 

Definition at line 102 of file ImR_Activator_i.h.


Constructor & Destructor Documentation

ImR_Activator_i::ImR_Activator_i void   ) 
 

Definition at line 22 of file ImR_Activator_i.cpp.

References getHostName().

00023 : registration_token_(0)
00024 , debug_(0)
00025 , notify_imr_ (false)
00026 , name_ (getHostName ())
00027 , env_buf_len_ (Activator_Options::ENVIRONMENT_BUFFER)
00028 {
00029 }


Member Function Documentation

int ImR_Activator_i::fini void   ) 
 

Cleans up any state created by init*.

Definition at line 204 of file ImR_Activator_i.cpp.

References ACE_DEBUG, ACE_Process_Manager::close(), CORBA::is_nil(), LM_DEBUG, process_mgr_, and registration_token_.

Referenced by ImR_Activator_Loader::fini(), run_standalone(), and Activator_NT_Service::svc().

00205 {
00206   try
00207     {
00208       if (debug_ > 1)
00209         ACE_DEBUG ((LM_DEBUG, "ImR Activator: Shutting down...\n"));
00210 
00211       this->process_mgr_.close ();
00212 
00213       this->root_poa_->destroy (1, 1);
00214 
00215       if (! CORBA::is_nil (this->locator_.in ()) && this->registration_token_ != 0)
00216         {
00217           this->locator_->unregister_activator (name_.c_str(),
00218             this->registration_token_);
00219         }
00220     }
00221   catch (const CORBA::COMM_FAILURE&)
00222     {
00223       if (debug_ > 1)
00224         ACE_DEBUG ((LM_DEBUG, "ImR Activator: Unable to unregister from ImR.\n"));
00225     }
00226   catch (const CORBA::TRANSIENT&)
00227     {
00228       if (debug_ > 1)
00229         ACE_DEBUG ((LM_DEBUG, "ImR Activator: Unable to unregister from ImR.\n"));
00230     }
00231   catch (const CORBA::Exception& ex)
00232   {
00233     ex._tao_print_exception ("ImR Activator: fini");
00234     throw;
00235   }
00236 
00237   try
00238     {
00239       this->orb_->destroy ();
00240 
00241       if (debug_ > 0)
00242         ACE_DEBUG ((LM_DEBUG, "ImR Activator: Shut down successfully.\n"));
00243     }
00244   catch (const CORBA::Exception& ex)
00245     {
00246       ex._tao_print_exception ("ImR Activator: fini 2");
00247       throw;
00248     }
00249   return 0;
00250 }

int ImR_Activator_i::handle_exit ACE_Process process  )  [private, virtual]
 

Reimplemented from ACE_Event_Handler.

Definition at line 341 of file ImR_Activator_i.cpp.

References ACE_CString, ACE_DEBUG, ACE_TEXT, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::find(), ACE_Process::getpid(), CORBA::is_nil(), LM_DEBUG, process_map_, ACE_Process::return_value(), and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::unbind().

00342 {
00343   // We use the process_manager so that we're notified when
00344   // any of our launched processes die. We notify the locator
00345   // when this happens.
00346 
00347   if (debug_ > 0)
00348     {
00349       ACE_DEBUG
00350         ((LM_DEBUG,
00351         ACE_TEXT ("Process %d exited with exit code %d\n"),
00352         process->getpid (), process->return_value ()));
00353     }
00354 
00355   ACE_CString name;
00356   if (this->process_map_.find (process->getpid (), name) == 0)
00357     {
00358       this->process_map_.unbind (process->getpid ());
00359 
00360       if (!CORBA::is_nil (this->locator_.in ()))
00361         {
00362           if (debug_ > 1)
00363             {
00364               ACE_DEBUG ((LM_DEBUG,
00365                 ACE_TEXT ("ImR Activator: Notifying ImR that %s has exited.\n"),
00366                 name.c_str()));
00367             }
00368           this->locator_->notify_child_death (name.c_str());
00369         }
00370     }
00371 
00372   return 0;
00373 }

int ImR_Activator_i::init Activator_Options opts  ) 
 

Initialize the Server state - parsing arguments and waiting.

Definition at line 186 of file ImR_Activator_i.cpp.

References ACE_ARGV, ACE_CString, Activator_Options::cmdline(), init_with_orb(), and CORBA::ORB_init().

Referenced by ImR_Activator_Loader::init(), run_standalone(), and Activator_NT_Service::svc().

00187 {
00188   ACE_CString cmdline = opts.cmdline();
00189   // Must use IOR style objrefs, because URLs sometimes get mangled when passed
00190   // to ACE_Process::spawn().
00191   cmdline += "-ORBUseImR 0 -ORBObjRefStyle IOR ";
00192   ACE_ARGV av (cmdline.c_str ());
00193   int argc = av.argc ();
00194 
00195   CORBA::ORB_var orb =
00196     CORBA::ORB_init (argc, av.argv (), "TAO_ImR_Activator");
00197 
00198   int ret = this->init_with_orb(orb.in (), opts);
00199 
00200   return ret;
00201 }

int ImR_Activator_i::init_with_orb CORBA::ORB_ptr  orb,
const Activator_Options opts
[private]
 

Definition at line 99 of file ImR_Activator_i.cpp.

References CORBA::ORB::_duplicate(), ACE_ASSERT, ACE_DEBUG, ACE_ERROR_RETURN, createPersistentPOA(), Activator_Options::debug(), Activator_Options::env_buf_len(), ACE_OS::fclose(), ACE_OS::fopen(), ACE_OS::fprintf(), imr_poa_, ACE_Reactor::instance(), Activator_Options::ior_filename(), LM_DEBUG, LM_ERROR, Activator_Options::name(), Activator_Options::notify_imr(), ACE_Process_Manager::open(), process_mgr_, register_with_imr(), and PortableServer::string_to_ObjectId().

Referenced by init().

00100 {
00101   ACE_ASSERT(! CORBA::is_nil (orb));
00102   orb_ = CORBA::ORB::_duplicate (orb);
00103   debug_ = opts.debug ();
00104   notify_imr_ = opts.notify_imr ();
00105   env_buf_len_ = opts.env_buf_len ();
00106   if (opts.name ().length () > 0)
00107     {
00108       name_ = opts.name();
00109     }
00110 
00111   try
00112     {
00113       CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
00114       ACE_ASSERT (! CORBA::is_nil (obj.in ()));
00115       this->root_poa_ = PortableServer::POA::_narrow (obj.in ());
00116       ACE_ASSERT (! CORBA::is_nil(this->root_poa_.in ()));
00117 
00118       // The activator must use a persistent POA so that it can be started before the
00119       // locator in some scenarios, such as when the locator persists its database, and
00120       // wants to reconnect to running activators to auto_start some servers.
00121       this->imr_poa_ = createPersistentPOA (this->root_poa_.in (),
00122         "ImR_Activator");
00123       ACE_ASSERT (! CORBA::is_nil(this->imr_poa_.in ()));
00124 
00125       // Activate ourself
00126       PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("ImR_Activator");
00127       this->imr_poa_->activate_object_with_id (id.in (), this);
00128       obj = this->imr_poa_->id_to_reference (id.in ());
00129       ImplementationRepository::Activator_var activator =
00130         ImplementationRepository::Activator::_narrow (obj.in ());
00131       ACE_ASSERT(! CORBA::is_nil (activator.in ()));
00132 
00133       CORBA::String_var ior = this->orb_->object_to_string (activator.in ());
00134 
00135       if (this->debug_ > 0)
00136         ACE_DEBUG((LM_DEBUG, "ImR Activator: Starting %s\n", name_.c_str ()));
00137 
00138       // initialize our process manager.
00139       // This requires a reactor that has signal handling.
00140       ACE_Reactor *reactor = ACE_Reactor::instance ();
00141       if (reactor != 0)
00142         {
00143           if (this->process_mgr_.open (ACE_Process_Manager::DEFAULT_SIZE, reactor) == -1)
00144             {
00145               ACE_ERROR_RETURN ((LM_ERROR,
00146                 "The ACE_Process_Manager didnt get initialized\n"), -1);
00147             }
00148         }
00149 
00150       this->register_with_imr (activator.in ()); // no throw
00151 
00152       PortableServer::POAManager_var poaman =
00153         this->root_poa_->the_POAManager ();
00154       poaman->activate ();
00155 
00156       if (this->debug_ > 1)
00157         {
00158           ACE_DEBUG ((LM_DEBUG,
00159             "ImR Activator: The Activator IOR is: <%s>\n", ior.in ()));
00160         }
00161 
00162       // The last thing we do is write out the ior so that a test program can assume
00163       // that the activator is ready to go as soon as the ior is written.
00164       if (opts.ior_filename ().length () > 0)
00165         {
00166           FILE* fp = ACE_OS::fopen (opts.ior_filename ().c_str (), "w");
00167           if (fp == 0)
00168             {
00169               ACE_ERROR_RETURN ((LM_ERROR,
00170                 "ImR Activator: Could not open file: %s\n", opts.ior_filename ().c_str ()), -1);
00171             }
00172           ACE_OS::fprintf (fp, "%s", ior.in ());
00173           ACE_OS::fclose (fp);
00174         }
00175     }
00176   catch (const CORBA::Exception& ex)
00177     {
00178       ex._tao_print_exception (
00179         "ImR_Activator_i::init_with_orb");
00180       throw;
00181     }
00182   return 0;
00183 }

void ImR_Activator_i::register_with_imr ImplementationRepository::Activator_ptr  activator  )  [private]
 

Definition at line 60 of file ImR_Activator_i.cpp.

References ACE_DEBUG, CORBA::is_nil(), LM_DEBUG, ACE_Process_Manager::open(), process_mgr_, and registration_token_.

Referenced by init_with_orb().

00061 {
00062   try
00063     {
00064       if (this->debug_ > 1)
00065         ACE_DEBUG( (LM_DEBUG, "ImR Activator: Contacting ImplRepoService...\n"));
00066 
00067       // First, resolve the ImR, without this we can go no further
00068       CORBA::Object_var obj =
00069         orb_->resolve_initial_references ("ImplRepoService");
00070 
00071       this->process_mgr_.open (ACE_Process_Manager::DEFAULT_SIZE,
00072         this->orb_->orb_core ()->reactor ());
00073 
00074       locator_ = ImplementationRepository::Locator::_narrow (obj.in ());
00075 
00076       if (!CORBA::is_nil (locator_.in ()))
00077         {
00078           this->registration_token_ =
00079             locator_->register_activator (name_.c_str (), activator);
00080 
00081           if (debug_ > 0)
00082             ACE_DEBUG((LM_DEBUG, "ImR Activator: Registered with ImR.\n"));
00083 
00084           return;
00085         }
00086     }
00087   catch (const CORBA::Exception& ex)
00088     {
00089       if (debug_ > 1)
00090         ex._tao_print_exception (
00091           "ImR Activator: Can't register with ImR.");
00092     }
00093 
00094   if (debug_ > 0)
00095     ACE_DEBUG ((LM_DEBUG, "ImR Activator: Not registered with ImR.\n"));
00096 }

int ImR_Activator_i::run void   ) 
 

Runs the orb.

Definition at line 253 of file ImR_Activator_i.cpp.

Referenced by ImR_Activator_Loader::run(), run_standalone(), and Activator_NT_Service::svc().

00254 {
00255   this->orb_->run ();
00256   return 0;
00257 }

void ImR_Activator_i::shutdown bool  wait_for_completion  ) 
 

Shutdown the orb.

Definition at line 266 of file ImR_Activator_i.cpp.

00267 {
00268   this->orb_->shutdown (wait_for_completion);
00269 }

void ImR_Activator_i::shutdown void   ) 
 

Definition at line 260 of file ImR_Activator_i.cpp.

Referenced by ImR_Activator_Shutdown::operator()().

00261 {
00262   this->shutdown (false);
00263 }

void ImR_Activator_i::start_server const char *  name,
const char *  cmdline,
const char *  dir,
const ImplementationRepository::EnvironmentList &  env
 

Definition at line 272 of file ImR_Activator_i.cpp.

References ACE_DEBUG, ACE_ERROR, ACE_INVALID_PID, ACE_Process_Options::command_line(), ACE_Process_Options::handle_inheritence(), CORBA::is_nil(), LM_DEBUG, LM_ERROR, process_map_, process_mgr_, ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::rebind(), ACE_Process_Manager::register_handler(), ACE_Process_Options::setenv(), ACE_Process_Manager::spawn(), and ACE_Process_Options::working_directory().

00276 {
00277   if (debug_ > 1)
00278     ACE_DEBUG((LM_DEBUG, "ImR Activator: Starting server <%s>...\n", name));
00279   if (debug_ > 1)
00280     ACE_DEBUG((LM_DEBUG, "\tcommand line : <%s>\n\tdirectory : <%s>\n", cmdline, dir));
00281 
00282   ACE_Process_Options proc_opts (
00283                         1,
00284                         ACE_Process_Options::DEFAULT_COMMAND_LINE_BUF_LEN,
00285                         this->env_buf_len_);
00286   proc_opts.command_line (cmdline);
00287   proc_opts.working_directory (dir);
00288   // Win32 does not support the CLOSE_ON_EXEC semantics for sockets
00289   // the way unix does, so in order to avoid having the child process
00290   // hold the listen socket open, we force the child to inherit no
00291   // handles. This includes stdin, stdout, logs, etc.
00292   proc_opts.handle_inheritence (0);
00293 
00294   proc_opts.setenv ("TAO_USE_IMR", "1");
00295   if (!CORBA::is_nil (this->locator_.in ()))
00296     {
00297       CORBA::String_var ior = orb_->object_to_string (locator_.in ());
00298       proc_opts.setenv ("ImplRepoServiceIOR", ior.in());
00299     }
00300 
00301   for (CORBA::ULong i = 0; i < env.length (); ++i)
00302     {
00303       proc_opts.setenv (env[i].name.in (), env[i].value.in ());
00304     }
00305 
00306   int pid = this->process_mgr_.spawn (proc_opts);
00307   if (pid == ACE_INVALID_PID)
00308     {
00309       ACE_ERROR ((LM_ERROR,
00310         "ImR Activator: Cannot start server <%s> using <%s>\n", name, cmdline));
00311 
00312       throw ImplementationRepository::CannotActivate(
00313         CORBA::string_dup (
00314           "Process Creation Failed"));
00315       return;
00316     }
00317   else
00318     {
00319       if (debug_ > 1)
00320         {
00321           ACE_DEBUG((LM_DEBUG,
00322             "ImR Activator: register death handler for process %d\n", pid));
00323         }
00324       this->process_mgr_.register_handler (this, pid);
00325 
00326       // We only bind to the process_map_ if we want to notify
00327       // the locator of a process' death.
00328       if (notify_imr_)
00329         {
00330           this->process_map_.rebind (pid, name);
00331         }
00332     }
00333 
00334   if (debug_ > 0)
00335     {
00336       ACE_DEBUG ((LM_DEBUG, "ImR Activator: Successfully started <%s>. \n", name));
00337     }
00338 }


Member Data Documentation

unsigned int ImR_Activator_i::debug_ [private]
 

Definition at line 117 of file ImR_Activator_i.h.

int ImR_Activator_i::env_buf_len_ [private]
 

The default environment buffer length.

Definition at line 126 of file ImR_Activator_i.h.

PortableServer::POA_var ImR_Activator_i::imr_poa_ [private]
 

Definition at line 107 of file ImR_Activator_i.h.

Referenced by init_with_orb().

ImplementationRepository::Locator_var ImR_Activator_i::locator_ [private]
 

Definition at line 109 of file ImR_Activator_i.h.

ACE_CString ImR_Activator_i::name_ [private]
 

Definition at line 121 of file ImR_Activator_i.h.

bool ImR_Activator_i::notify_imr_ [private]
 

Definition at line 119 of file ImR_Activator_i.h.

CORBA::ORB_var ImR_Activator_i::orb_ [private]
 

Definition at line 115 of file ImR_Activator_i.h.

ProcessMap ImR_Activator_i::process_map_ [private]
 

Definition at line 123 of file ImR_Activator_i.h.

Referenced by handle_exit(), and start_server().

ACE_Process_Manager ImR_Activator_i::process_mgr_ [private]
 

Definition at line 104 of file ImR_Activator_i.h.

Referenced by fini(), init_with_orb(), register_with_imr(), and start_server().

CORBA::Long ImR_Activator_i::registration_token_ [private]
 

We're given a token when registering with the locator, which we must use when unregistering.

Definition at line 113 of file ImR_Activator_i.h.

Referenced by fini(), and register_with_imr().

PortableServer::POA_var ImR_Activator_i::root_poa_ [private]
 

Definition at line 106 of file ImR_Activator_i.h.


The documentation for this class was generated from the following files:
Generated on Sun Jan 27 15:55:38 2008 for TAO_Implementation_Repository by doxygen 1.3.6