ImR_Locator_i Class Reference

#include <ImR_Locator_i.h>

Collaboration diagram for ImR_Locator_i:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ImR_Locator_i ()
 ~ImR_Locator_i (void)
int init (Options &opts)
 Initialize the service, creating its own orb, poa, etc.
int init_with_orb (CORBA::ORB_ptr orb, Options &opts)
 Same as above, but use the given orb.
int fini (void)
 Cleans up any state created by init*.
int run (void)
 Run using the orb reference created during init().
void shutdown (bool wait_for_completion)
 Shutdown the orb.
int debug () const
virtual CORBA::Long register_activator (const char *name, ImplementationRepository::Activator_ptr admin)
virtual void unregister_activator (const char *name, CORBA::Long token)
virtual void notify_child_death (const char *name)
virtual void activate_server (const char *name)
virtual void add_or_update_server (const char *name, const ImplementationRepository::StartupOptions &options)
virtual void remove_server (const char *name)
virtual void shutdown_server (const char *name)
virtual void find (const char *name, ImplementationRepository::ServerInformation_out info)
virtual void list (CORBA::ULong how_many, ImplementationRepository::ServerInformationList_out server_list, ImplementationRepository::ServerInformationIterator_out server_iterator)
virtual void shutdown (CORBA::Boolean activators, CORBA::Boolean servers)
virtual void server_is_running (const char *name, const char *partial_ior, ImplementationRepository::ServerObject_ptr server_object)
virtual void server_is_shutting_down (const char *name)
char * activate_server_by_object (const char *object_name)
char * activate_server_by_name (const char *name, bool manual_start)

Private Member Functions

char * activate_server_i (Server_Info &info, bool manual_start)
char * activate_perclient_server_i (Server_Info info, bool manual_start)
ImplementationRepository::StartupInfo * start_server (Server_Info &info, bool manual_start, int &waiting_clients)
bool is_alive (Server_Info &info)
int is_alive_i (Server_Info &info)
int setup_multicast (ACE_Reactor *reactor, const char *ior)
void teardown_multicast ()
void unregister_activator_i (const char *activator)
Activator_Info_Ptr get_activator (const ACE_CString &name)
void connect_activator (Activator_Info &info)
void auto_start_servers (void)
CORBA::Object_ptr set_timeout_policy (CORBA::Object_ptr obj, const ACE_Time_Value &to)
void connect_server (Server_Info &info)
PortableServer::POA_ptr findPOA (const char *name)

Private Attributes

ImR_Forwarder forwarder_
ImR_Adapter adapter_
IORTable::Locator_var ins_locator_
 The locator interface for the IORTable.
CORBA::ORB_var orb_
PortableServer::POA_var root_poa_
PortableServer::POA_var imr_poa_
int debug_
TAO_IOR_Multicast ior_multicast_
Locator_Repository repository_
AsyncStartupWaiter_i waiter_svt_
ImplementationRepository::AsyncStartupWaiter_var waiter_
bool read_only_
ACE_Time_Value startup_timeout_
ACE_Time_Value ping_interval_

Detailed Description

Definition at line 36 of file ImR_Locator_i.h.


Constructor & Destructor Documentation

ImR_Locator_i::ImR_Locator_i (  ) 

Definition at line 56 of file ImR_Locator_i.cpp.

References ACE_NEW, and ins_locator_.

00057   : forwarder_ (*this)
00058   , ins_locator_ (0)
00059   , debug_ (0)
00060   , read_only_ (false)
00061 {
00062   // Visual C++ 6.0 is not smart enough to do a direct assignment
00063   // while allocating the INS_Locator.  So, we have to do it in
00064   // two steps.
00065   INS_Locator* locator;
00066   ACE_NEW (locator,
00067           INS_Locator (*this));
00068   ins_locator_ = locator;
00069 }

ImR_Locator_i::~ImR_Locator_i ( void   ) 

Definition at line 71 of file ImR_Locator_i.cpp.

00072 {
00073   // For some reason g++ 4.0 needs this out-of-line destructor instead
00074   // of the default one generated by the compiler.  Without this
00075   // destructor, we get a number of "undefined reference" link errors
00076   // related to the virtual tables of the INS_Locator, ImR_Adapter and
00077   // ImR_Forwarder members in this class.
00078 }


Member Function Documentation

char * ImR_Locator_i::activate_perclient_server_i ( Server_Info  info,
bool  manual_start 
) [private]

Definition at line 546 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_String_Base< CHAR >::c_str(), debug_, Locator_Repository::get_server(), Server_Info::ior, is_alive(), LM_DEBUG, Server_Info::name, Server_Info::partial_ior, repository_, Server_Info::start_count, Server_Info::start_limit, start_server(), and CORBA::string_dup().

Referenced by activate_server_i().

00547 {
00548   Server_Info_Ptr shared_info = this->repository_.get_server (info.name);
00549   do
00550     {
00551       ImplementationRepository::StartupInfo* psi =
00552         start_server (info, manual_start, shared_info->waiting_clients);
00553 
00554       if (psi != 0)
00555         {
00556           ImplementationRepository::StartupInfo_var si = psi;
00557           ACE_ASSERT (info.name == si->name.in ());
00558           info.partial_ior = si->partial_ior.in ();
00559           info.ior = si->ior.in ();
00560 
00561           if (is_alive (info))
00562             {
00563               if (debug_ > 1)
00564                 {
00565                   ACE_DEBUG ((LM_DEBUG, "ImR: Successfully activated <%s> at \n\t%s\n",
00566                               info.name.c_str (), info.partial_ior.c_str ()));
00567                 }
00568               return CORBA::string_dup (info.partial_ior.c_str ());
00569             }
00570           info.reset ();
00571         }
00572     } while (info.start_count < info.start_limit);
00573 
00574   if (this->debug_ > 0)
00575     {
00576       ACE_DEBUG ((LM_DEBUG,
00577                   "ImR: Cannot Activate <%s>.\n", info.name.c_str ()));
00578     }
00579   throw ImplementationRepository::CannotActivate(
00580     CORBA::string_dup (
00581       "Cannot start server."));
00582 }

void ImR_Locator_i::activate_server ( const char *  name  )  [virtual]

Definition at line 455 of file ImR_Locator_i.cpp.

References ACE_DEBUG, activate_server_by_name(), debug_, and LM_DEBUG.

00456 {
00457   if (debug_ > 1)
00458     ACE_DEBUG ((LM_DEBUG, "ImR: Manually activating server <%s>\n", server));
00459 
00460   // This is the version called by tao_imr to activate the server, manually
00461   // starting it if necessary.
00462   CORBA::String_var cleanup =
00463     activate_server_by_name (server, true);
00464 }

char * ImR_Locator_i::activate_server_by_name ( const char *  name,
bool  manual_start 
)

Definition at line 467 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_ERROR, activate_server_i(), Locator_Repository::get_server(), LM_ERROR, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), and repository_.

Referenced by activate_server(), activate_server_by_object(), and ImR_Forwarder::preinvoke().

00468 {
00469   // Activate the server, starting it if necessary. Don't start MANUAL
00470   // servers unless manual_start=true
00471   ACE_ASSERT (name != 0);
00472 
00473   Server_Info_Ptr info = this->repository_.get_server (name);
00474   if (info.null ())
00475     {
00476       ACE_ERROR ((LM_ERROR, "ImR: Cannot find info for server <%s>\n", name));
00477       throw ImplementationRepository::NotFound ();
00478     }
00479 
00480   return activate_server_i (*info, manual_start);
00481 }

char * ImR_Locator_i::activate_server_by_object ( const char *  object_name  ) 

Definition at line 484 of file ImR_Locator_i.cpp.

References ACE_ASSERT, activate_server_by_name(), ACE_String_Base< CHAR >::c_str(), ACE_String_Base< CHAR >::find(), ACE_String_Base_Const::npos, and ACE_String_Base< CHAR >::substr().

Referenced by INS_Locator::locate().

00485 {
00486   ACE_ASSERT (object_name != 0);
00487 
00488   // We assume that the first part of the object name is the server name.
00489   // So a name of foo/bar means that the server name is foo.
00490   ACE_CString server_name (object_name);
00491   ACE_CString::size_type pos = server_name.find ('/');
00492   if (pos != ACE_CString::npos)
00493     server_name = server_name.substr (pos + 1);
00494 
00495   return activate_server_by_name (server_name.c_str (), false);
00496 }

char * ImR_Locator_i::activate_server_i ( Server_Info info,
bool  manual_start 
) [private]

Definition at line 499 of file ImR_Locator_i.cpp.

References ACE_DEBUG, activate_perclient_server_i(), Server_Info::activation_mode, debug_, is_alive(), LM_DEBUG, start_server(), CORBA::string_dup(), AsyncStartupWaiter_i::unblock_all(), and waiter_svt_.

Referenced by activate_server_by_name().

00500 {
00501   if (info.activation_mode == ImplementationRepository::PER_CLIENT)
00502     {
00503       return activate_perclient_server_i (info, manual_start);
00504     }
00505 
00506   while (true)
00507     {
00508       if (is_alive (info))
00509         {
00510           if (debug_ > 1)
00511             {
00512               ACE_DEBUG ((LM_DEBUG, "ImR: Successfully activated <%s> at \n\t%s\n",
00513                           info.name.c_str (), info.partial_ior.c_str ()));
00514             }
00515           info.start_count = 0;
00516 
00517           waiter_svt_.unblock_all (info.name.c_str ());
00518 
00519           return CORBA::string_dup (info.partial_ior.c_str ());
00520         }
00521 
00522       info.reset ();
00523 
00524       if (! info.starting && info.start_count >= info.start_limit)
00525         {
00526           if (this->debug_ > 0)
00527             {
00528               ACE_DEBUG ((LM_DEBUG,
00529                           "ImR: Cannot Activate <%s>.\n", info.name.c_str ()));
00530             }
00531 
00532           waiter_svt_.unblock_all (info.name.c_str ());
00533 
00534           throw ImplementationRepository::CannotActivate(
00535             CORBA::string_dup (
00536               "Cannot start server."));
00537         }
00538 
00539       // Note: We already updated info with StartupInfo in server_is_running ()
00540       ImplementationRepository::StartupInfo_var si =
00541         start_server (info, manual_start, info.waiting_clients);
00542     }
00543 }

void ImR_Locator_i::add_or_update_server ( const char *  name,
const ImplementationRepository::StartupOptions &  options 
) [virtual]

Definition at line 760 of file ImR_Locator_i.cpp.

References CORBA::SystemException::_tao_minor_code(), ACE_ASSERT, ACE_DEBUG, ImR_Utils::activationModeToString(), Locator_Repository::add_server(), ACE_String_Base< CHAR >::c_str(), CORBA::COMPLETED_NO, debug_, Locator_Repository::get_server(), LM_DEBUG, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), repository_, TAO_IMPLREPO_MINOR_CODE, and Locator_Repository::update_server().

00762 {
00763   ACE_ASSERT (server != 0);
00764 
00765   if (this->read_only_)
00766     {
00767       ACE_DEBUG ((LM_DEBUG, "ImR: Cannot add/update server <%s> due to locked database.\n", server));
00768       throw CORBA::NO_PERMISSION (
00769         CORBA::SystemException::_tao_minor_code (
00770           TAO_IMPLREPO_MINOR_CODE,
00771           0),
00772         CORBA::COMPLETED_NO);
00773     }
00774 
00775   if (debug_ > 0)
00776     ACE_DEBUG ((LM_DEBUG, "ImR: Add/Update server <%s>.\n", server));
00777 
00778   int limit = options.start_limit;
00779   if (limit < 0)
00780     {
00781       limit = -limit;
00782     }
00783   else if (limit == 0)
00784     {
00785       limit = 1;
00786     }
00787 
00788   Server_Info_Ptr info = this->repository_.get_server (server);
00789   if (info.null ())
00790     {
00791       if (this->debug_ > 1)
00792         ACE_DEBUG ((LM_DEBUG, "ImR: Adding server <%s>.\n", server));
00793 
00794       this->repository_.add_server (server,
00795                                     options.activator.in (),
00796                                     options.command_line.in (),
00797                                     options.environment,
00798                                     options.working_directory.in (),
00799                                     options.activation,
00800                                     limit);
00801     }
00802   else
00803     {
00804       if (this->debug_ > 1)
00805         ACE_DEBUG ((LM_DEBUG, "ImR: Updating server <%s>.\n", server));
00806 
00807       info->activator = options.activator.in ();
00808       info->cmdline = options.command_line.in ();
00809       info->env_vars = options.environment;
00810       info->dir = options.working_directory.in ();
00811       info->activation_mode = options.activation;
00812       info->start_limit = limit;
00813       info->start_count = 0;
00814       int err = this->repository_.update_server (*info);
00815       ACE_ASSERT (err == 0);
00816       ACE_UNUSED_ARG (err);
00817     }
00818 
00819   if (this->debug_ > 1)
00820     {
00821       // Note : The info var may be null, so we use options.
00822       ACE_DEBUG ((LM_DEBUG, "ImR: Server: %s\n"
00823                   "\tActivator: %s\n"
00824                   "\tCommand Line: %s\n"
00825                   "\tWorking Directory: %s\n"
00826                   "\tActivation: %s\n"
00827                   "\tStart Limit: %d\n"
00828                   "\n",
00829                   server,
00830                   options.activator.in (),
00831                   options.command_line.in (),
00832                   options.working_directory.in (),
00833                   ImR_Utils::activationModeToString (options.activation).c_str (),
00834                   limit
00835                   ));
00836 
00837       for (CORBA::ULong i = 0; i < options.environment.length (); ++i)
00838         ACE_DEBUG ((LM_DEBUG, "Environment variable %s=%s\n",
00839                     options.environment[i].name.in (),
00840                     options.environment[i].value.in ()));
00841     }
00842 }

void ImR_Locator_i::auto_start_servers ( void   )  [private]

Definition at line 1200 of file ImR_Locator_i.cpp.

References CORBA::Exception::_tao_print_exception(), ACE_ASSERT, ACE_DEBUG, and LM_DEBUG.

Referenced by run().

01201 {
01202   if (this->repository_.servers ().current_size () == 0)
01203     return;
01204 
01205   Locator_Repository::SIMap::ENTRY* server_entry;
01206   Locator_Repository::SIMap::ITERATOR server_iter (this->repository_.servers ());
01207 
01208   // For each of the entries in the Locator_Repository, get the startup
01209   // information and activate the servers, if they are not already
01210   // running.
01211   for (;server_iter.next (server_entry) != 0; server_iter.advance ())
01212     {
01213       Server_Info_Ptr info = server_entry->int_id_;
01214       ACE_ASSERT (! info.null ());
01215 
01216       try
01217         {
01218           if (info->activation_mode == ImplementationRepository::AUTO_START
01219               && info->cmdline.length () > 0)
01220             {
01221               CORBA::String_var cleanup =
01222                 this->activate_server_i (*info, true);
01223             }
01224         }
01225       catch (const CORBA::Exception& ex)
01226         {
01227           if (this->debug_ > 1)
01228             {
01229               ACE_DEBUG ((LM_DEBUG,
01230                           "ImR: AUTO_START Could not activate <%s>\n",
01231                           server_entry->ext_id_.c_str ()));
01232               ex._tao_print_exception ("AUTO_START");
01233             }
01234           // Ignore exceptions
01235         }
01236     }
01237 }

void ImR_Locator_i::connect_activator ( Activator_Info info  )  [private]

Definition at line 1160 of file ImR_Locator_i.cpp.

References ACE_DEBUG, Activator_Info::activator, ACE_String_Base< CHAR >::c_str(), debug_, TAO_Pseudo_Var_T< T >::in(), Activator_Info::ior, CORBA::is_nil(), ACE_String_Base< CHAR >::length(), LM_DEBUG, Activator_Info::name, orb_, Activator_Info::reset(), set_timeout_policy(), startup_timeout_, and ACE_Time_Value::zero.

Referenced by shutdown().

01161 {
01162   if (! CORBA::is_nil (info.activator.in ()) || info.ior.length () == 0)
01163     return;
01164 
01165   try
01166     {
01167       CORBA::Object_var obj =
01168         this->orb_->string_to_object (info.ior.c_str ());
01169 
01170       if (CORBA::is_nil (obj.in ()))
01171         {
01172           info.reset ();
01173           return;
01174         }
01175 
01176       if (startup_timeout_ > ACE_Time_Value::zero)
01177         {
01178           obj = set_timeout_policy (obj.in (), startup_timeout_);
01179         }
01180 
01181       info.activator =
01182         ImplementationRepository::Activator::_unchecked_narrow (obj.in ());
01183 
01184       if (CORBA::is_nil (info.activator.in ()))
01185         {
01186           info.reset ();
01187           return;
01188         }
01189 
01190       if (debug_ > 1)
01191         ACE_DEBUG ((LM_DEBUG, "ImR: Connected to activator <%s>\n", info.name.c_str ()));
01192     }
01193   catch (const CORBA::Exception&)
01194     {
01195       info.reset ();
01196     }
01197 }

void ImR_Locator_i::connect_server ( Server_Info info  )  [private]

Definition at line 1240 of file ImR_Locator_i.cpp.

References ACE_DEBUG, ACE_String_Base< CHAR >::c_str(), debug_, DEFAULT_SERVER_TIMEOUT, TAO_Pseudo_Var_T< T >::in(), Server_Info::ior, CORBA::is_nil(), ACE_String_Base< CHAR >::length(), LM_DEBUG, Server_Info::name, orb_, Server_Info::reset(), Server_Info::server, and set_timeout_policy().

Referenced by is_alive_i(), and shutdown_server().

01241 {
01242   if (! CORBA::is_nil (info.server.in ()))
01243     {
01244       return; // already connected
01245     }
01246 
01247   if (info.ior.length () == 0)
01248     {
01249       info.reset ();
01250       return; // can't connect
01251     }
01252 
01253   try
01254     {
01255       CORBA::Object_var obj = orb_->string_to_object (info.ior.c_str ());
01256 
01257       if (CORBA::is_nil (obj.in ()))
01258         {
01259           info.reset ();
01260           return;
01261         }
01262 
01263       obj = set_timeout_policy (obj.in (), DEFAULT_SERVER_TIMEOUT);
01264 
01265       info.server =
01266         ImplementationRepository::ServerObject::_unchecked_narrow (obj.in ());
01267 
01268       if (CORBA::is_nil (info.server.in ()))
01269         {
01270           info.reset ();
01271           return;
01272         }
01273 
01274       if (debug_ > 1)
01275         ACE_DEBUG ((LM_DEBUG, "ImR: Connected to server <%s>\n", info.name.c_str ()));
01276     }
01277   catch (const CORBA::Exception&)
01278     {
01279       info.reset ();
01280     }
01281 }

int ImR_Locator_i::debug (  )  const

Definition at line 1470 of file ImR_Locator_i.cpp.

References debug_.

Referenced by INS_Locator::locate(), ImR_Forwarder::preinvoke(), and run().

01471 {
01472   return debug_;
01473 }

void ImR_Locator_i::find ( const char *  name,
ImplementationRepository::ServerInformation_out  info 
) [virtual]

Definition at line 1058 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_NEW_THROW_EX, debug_, Locator_Repository::get_server(), LM_DEBUG, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), and repository_.

01060 {
01061   ACE_ASSERT (server != 0);
01062   ACE_NEW_THROW_EX (imr_info, ImplementationRepository::ServerInformation, CORBA::NO_MEMORY ());
01063 
01064   Server_Info_Ptr info = this->repository_.get_server (server);
01065   if (! info.null ())
01066     {
01067       imr_info = info->createImRServerInfo ();
01068 
01069       if (this->debug_ > 1)
01070         ACE_DEBUG ((LM_DEBUG, "ImR: Found server %s.\n", server));
01071     }
01072   else
01073     {
01074       if (debug_ > 1)
01075         ACE_DEBUG ((LM_DEBUG, "ImR: Cannot find server <%s>\n", server));
01076     }
01077 }

PortableServer::POA_ptr ImR_Locator_i::findPOA ( const char *  name  )  [private]

Definition at line 891 of file ImR_Locator_i.cpp.

References root_poa_.

Referenced by remove_server().

00892 {
00893   try
00894     {
00895       bool activate_it = false;
00896       return root_poa_->find_POA (name, activate_it);
00897     }
00898   catch (const CORBA::Exception&)
00899     {// Ignore
00900     }
00901   return PortableServer::POA::_nil ();
00902 }

int ImR_Locator_i::fini ( void   ) 

Cleans up any state created by init*.

Definition at line 276 of file ImR_Locator_i.cpp.

References CORBA::Exception::_tao_print_exception(), ACE_DEBUG, debug_, LM_DEBUG, orb_, root_poa_, and teardown_multicast().

Referenced by ImR_Locator_Loader::fini(), and run_standalone().

00277 {
00278   try
00279     {
00280       if (debug_ > 1)
00281         ACE_DEBUG ((LM_DEBUG, "ImR: Shutting down...\n"));
00282 
00283       teardown_multicast ();
00284 
00285       this->root_poa_->destroy (1, 1);
00286 
00287       this->orb_->destroy ();
00288 
00289       if (debug_ > 0)
00290         ACE_DEBUG ((LM_DEBUG, "ImR: Shut down successfully.\n"));
00291     }
00292   catch (const CORBA::Exception& ex)
00293     {
00294       ex._tao_print_exception ("ImR_Locator_i::fini");
00295       throw;
00296     }
00297   return 0;
00298 }

Activator_Info_Ptr ImR_Locator_i::get_activator ( const ACE_CString name  )  [private]

Definition at line 1149 of file ImR_Locator_i.cpp.

References Locator_Repository::get_activator(), ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), and repository_.

Referenced by start_server(), and unregister_activator().

01150 {
01151   Activator_Info_Ptr info = this->repository_.get_activator (aname);
01152   if (! info.null ())
01153     {
01154       this->connect_activator (*info);
01155     }
01156   return info;
01157 }

int ImR_Locator_i::init ( Options opts  ) 

Initialize the service, creating its own orb, poa, etc.

Definition at line 173 of file ImR_Locator_i.cpp.

References ACE_String_Base< CHAR >::c_str(), Options::cmdline(), TAO_Pseudo_Var_T< T >::in(), init_with_orb(), and CORBA::ORB_init().

Referenced by ImR_Locator_Loader::init(), and run_standalone().

00174 {
00175   ACE_CString cmdline = opts.cmdline ();
00176   cmdline += " -orbcollocation no -orbuseimr 0";
00177   ACE_ARGV av (cmdline.c_str ());
00178   int argc = av.argc ();
00179   char** argv = av.argv ();
00180 
00181   CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "TAO_ImR_Locator");
00182   int err = this->init_with_orb (orb.in (), opts);
00183   return err;
00184 }

int ImR_Locator_i::init_with_orb ( CORBA::ORB_ptr  orb,
Options opts 
)

Same as above, but use the given orb.

Definition at line 81 of file ImR_Locator_i.cpp.

References CORBA::ORB::_duplicate(), ACE_ASSERT, ACE_ERROR_RETURN, adapter_, ACE_String_Base< CHAR >::c_str(), createPersistentPOA(), AsyncStartupWaiter_i::debug(), Options::debug(), debug_, ACE_OS::fclose(), ACE_OS::fopen(), forwarder_, ACE_OS::fprintf(), imr_poa_, TAO_Pseudo_Var_T< T >::in(), Locator_Repository::init(), ImR_Adapter::init(), ImR_Forwarder::init(), Options::ior_filename(), CORBA::is_nil(), ACE_String_Base< CHAR >::length(), LM_ERROR, Options::multicast(), orb_, CORBA::ORB::orb_core(), Options::ping_interval(), ping_interval_, TAO_ORB_Core::reactor(), read_only_, Options::readonly(), repository_, CORBA::ORB::resolve_initial_references(), root_poa_, set_timeout_policy(), Options::startup_timeout(), startup_timeout_, PortableServer::string_to_ObjectId(), waiter_, waiter_svt_, and ACE_Time_Value::zero.

Referenced by init().

00082 {
00083   orb_ = CORBA::ORB::_duplicate (orb);
00084   debug_ = opts.debug ();
00085   read_only_ = opts.readonly ();
00086   startup_timeout_ = opts.startup_timeout ();
00087   ping_interval_ = opts.ping_interval ();
00088 
00089   CORBA::Object_var obj =
00090     this->orb_->resolve_initial_references ("RootPOA");
00091   this->root_poa_ = PortableServer::POA::_narrow (obj.in ());
00092   ACE_ASSERT (! CORBA::is_nil (this->root_poa_.in ()));
00093 
00094   this->forwarder_.init (orb);
00095   this->adapter_.init (& this->forwarder_);
00096 
00097   // Register the Adapter_Activator reference to be the RootPOA's
00098   // Adapter Activator.
00099   root_poa_->the_activator (&this->adapter_);
00100 
00101   // Use a persistent POA so that any IOR
00102   this->imr_poa_ = createPersistentPOA (this->root_poa_.in (),
00103                                         "ImplRepo_Service");
00104   ACE_ASSERT (! CORBA::is_nil (this->imr_poa_.in ()));
00105 
00106   waiter_svt_.debug (debug_ > 1);
00107   PortableServer::ObjectId_var id = PortableServer::string_to_ObjectId ("ImR_AsyncStartupWaiter");
00108   this->imr_poa_->activate_object_with_id (id.in (), &waiter_svt_);
00109   obj = this->imr_poa_->id_to_reference (id.in ());
00110   if (startup_timeout_ > ACE_Time_Value::zero)
00111     {
00112       obj = set_timeout_policy (obj.in (), startup_timeout_);
00113     }
00114   waiter_ = ImplementationRepository::AsyncStartupWaiter::_narrow (obj.in ());
00115 
00116   id = PortableServer::string_to_ObjectId ("ImplRepo_Service");
00117   this->imr_poa_->activate_object_with_id (id.in (), this);
00118 
00119   obj = this->imr_poa_->id_to_reference (id.in ());
00120   CORBA::String_var ior = this->orb_->object_to_string (obj.in ());
00121 
00122   // Register the ImR for use with INS
00123   obj = orb->resolve_initial_references ("IORTable");
00124   IORTable::Table_var ior_table = IORTable::Table::_narrow (obj.in ());
00125   ACE_ASSERT (! CORBA::is_nil (ior_table.in ()));
00126   ior_table->bind ("ImplRepoService", ior.in ());
00127   ior_table->bind ("ImR", ior.in ());
00128   ior_table->set_locator (this->ins_locator_.in ());
00129 
00130   // Set up multicast support (if enabled)
00131   if (opts.multicast ())
00132     {
00133       ACE_Reactor* reactor = orb->orb_core ()->reactor ();
00134       if (this->setup_multicast (reactor, ior.in ()) != 0)
00135         return -1;
00136     }
00137 
00138   // Initialize the persistent storage. This will load any values that
00139   // may have been persisted before.
00140   // The init can return 1 if there is no persistent file yet. In
00141   // that case, we need not do anything for now.
00142   int init_result =
00143     this->repository_.init (opts);
00144   if (init_result == -1)
00145     {
00146       ACE_ERROR_RETURN ((LM_ERROR, "Repository failed to initialize\n"), -1);
00147     }
00148 
00149   // Activate the two poa managers
00150   PortableServer::POAManager_var poaman =
00151     this->root_poa_->the_POAManager ();
00152   poaman->activate ();
00153   poaman = this->imr_poa_->the_POAManager ();
00154   poaman->activate ();
00155 
00156   // We write the ior file last so that the tests can know we are ready.
00157   if (opts.ior_filename ().length () > 0)
00158     {
00159       FILE* fp = ACE_OS::fopen (opts.ior_filename ().c_str (), "w");
00160       if (fp == 0)
00161         {
00162           ACE_ERROR_RETURN ((LM_ERROR,
00163                              "ImR: Could not open file: %s\n", opts.ior_filename ().c_str ()), -1);
00164         }
00165       ACE_OS::fprintf (fp, "%s", ior.in ());
00166       ACE_OS::fclose (fp);
00167     }
00168 
00169   return 0;
00170 }

bool ImR_Locator_i::is_alive ( Server_Info info  )  [private]

Definition at line 1284 of file ImR_Locator_i.cpp.

References ACE_DEBUG, ACE_String_Base< CHAR >::c_str(), debug_, ACE_OS::gettimeofday(), Server_Info::last_ping, LM_DEBUG, Server_Info::name, orb_, and PING_RETRY_SCHEDULE.

Referenced by activate_perclient_server_i(), and activate_server_i().

01285 {
01286   const size_t table_size = sizeof (PING_RETRY_SCHEDULE) /
01287                             sizeof (*PING_RETRY_SCHEDULE);
01288 
01289   for (size_t i = 0; i < table_size; ++i)
01290     {
01291       int status = this->is_alive_i (info);
01292       if (status == 0)
01293         return false;
01294       if (status == 1)
01295         return true;
01296 
01297       // This is evil, but there's not much else we can do for now. We
01298       // should never reach this code once the ImR Servers are fixed
01299       // so that they don't lie about server_is_running. Currently,
01300       // they send this notification during poa creation.  We have to
01301       // run the orb, because the very thing that may be slowing the
01302       // aliveness of the servers is the fact that they're trying to
01303       // register more objects with us.  In practical testing, we
01304       // never retried the ping more than once, because the second
01305       // ping always timed out, even if the servers poa manager had
01306       // not been activated. The only way we saw multiple retries was
01307       // if we ran the orb on the server before the poa manager was
01308       // activated.  For this reason, the first retry is immediate,
01309       // and the orb->run () call is not required. The call will
01310       // likely timeout, and is_alive will return true.
01311       if (PING_RETRY_SCHEDULE[i] > 0)
01312         {
01313           ACE_Time_Value tv (0, PING_RETRY_SCHEDULE[i] * 1000);
01314           this->orb_->run (tv);
01315         }
01316     }
01317   if (debug_ > 0)
01318     {
01319       ACE_DEBUG ((LM_DEBUG,
01320                   "ImR: <%s> Ping retry count exceeded. alive=maybe.\n", info.name.c_str ()));
01321     }
01322   // We return true here, because the server *might* be alive, it's just not starting in a timely
01323   // manner. We can't return false, because then we'll just try to start another instance, and the
01324   // same thing will likely happen.
01325   info.last_ping = ACE_OS::gettimeofday ();
01326   return true;
01327 }

int ImR_Locator_i::is_alive_i ( Server_Info info  )  [private]

Definition at line 1330 of file ImR_Locator_i.cpp.

References CORBA::Exception::_tao_print_exception(), ACE_DEBUG, Server_Info::activator, ACE_String_Base< CHAR >::c_str(), Server_Info::cmdline, connect_server(), debug_, ACE_OS::gettimeofday(), Locator_Repository::has_activator(), Server_Info::ior, CORBA::is_nil(), Server_Info::last_ping, ACE_String_Base< CHAR >::length(), LM_DEBUG, Server_Info::name, Server_Info::partial_ior, ping_interval_, repository_, Server_Info::server, TAO_INVOCATION_SEND_REQUEST_MINOR_CODE, TAO_POA_DISCARDING, TAO_POA_HOLDING, and ACE_Time_Value::zero.

01331 {
01332   // This is used by the ACE_TRY below when exceptions are turned off.
01333 
01334   if (info.ior.length () == 0 || info.partial_ior.length () == 0)
01335     {
01336       if (debug_ > 1)
01337         {
01338           ACE_DEBUG ((LM_DEBUG,
01339                       "ImR: <%s> not running. alive=false.\n", info.name.c_str ()));
01340         }
01341       info.last_ping = ACE_Time_Value::zero;
01342       return 0;
01343     }
01344 
01345   if (ping_interval_ == ACE_Time_Value::zero)
01346     {
01347       if (debug_ > 1)
01348         {
01349           ACE_DEBUG ((LM_DEBUG,
01350                       "ImR: <%s> Ping verification disabled. alive=true.\n", info.name.c_str ()));
01351         }
01352       return 1;
01353     }
01354 
01355   if ((ACE_OS::gettimeofday () - info.last_ping) < ping_interval_)
01356     {
01357       if (debug_ > 1)
01358         {
01359           ACE_DEBUG ((LM_DEBUG,
01360                       "ImR: <%s> within ping interval. alive=true.\n", info.name.c_str ()));
01361         }
01362       return 1;
01363     }
01364 
01365   // If we don't have enough information to start the server if it isn't already
01366   // then we might as well assume it is running. That way the client can get the
01367   // status directly from the server.
01368   if (info.cmdline.length () == 0 || ! repository_.has_activator (info.activator))
01369     {
01370       if (debug_ > 1)
01371         {
01372           ACE_DEBUG ((LM_DEBUG,
01373                       "ImR: Ping verification skipped. <%s> not startable.\n", info.name.c_str ()));
01374         }
01375       return 1;
01376     }
01377 
01378   connect_server (info);
01379 
01380   if (CORBA::is_nil (info.server.in ()))
01381     {
01382       if (debug_ > 1)
01383         {
01384           ACE_DEBUG ((LM_DEBUG,
01385                       "ImR: <%s> Could not connect. alive=false.\n", info.name.c_str ()));
01386         }
01387       return 0;
01388     }
01389 
01390   try
01391     {
01392       // Make a copy, in case the info is updated during the ping.
01393       ImplementationRepository::ServerObject_var server = info.server;
01394 
01395       // This will timeout if it takes too long
01396       server->ping ();
01397 
01398       if (debug_ > 1)
01399         {
01400           ACE_DEBUG ((LM_DEBUG,
01401                       "ImR: <%s> Ping successful. alive=true\n", info.name.c_str ()));
01402         }
01403       info.last_ping = ACE_OS::gettimeofday ();
01404     }
01405   catch (const CORBA::TRANSIENT& ex)
01406     {
01407       const CORBA::ULong BITS_5_THRU_12_MASK = 0x00000f80;
01408       switch (ex.minor () & BITS_5_THRU_12_MASK)
01409         {
01410         case TAO_INVOCATION_SEND_REQUEST_MINOR_CODE:
01411           {
01412             if (debug_ > 1)
01413               {
01414                 ACE_DEBUG ((LM_DEBUG,
01415                             "ImR: <%s> Local TRANSIENT. alive=false.\n", info.name.c_str ()));
01416               }
01417           }
01418         info.last_ping = ACE_Time_Value::zero;
01419         return 0;
01420         case TAO_POA_DISCARDING:
01421         case TAO_POA_HOLDING:
01422           {
01423             if (debug_ > 1)
01424               {
01425                 ACE_DEBUG ((LM_DEBUG,
01426                             "ImR: <%s> Remote TRANSIENT. alive=maybe.\n", info.name.c_str ()));
01427               }
01428           }
01429         return -1; // We keep trying to ping, because returning 1 now, would just lead
01430         // to clients getting the same exception. If we can't ping after several
01431         // attempts, then we'll give up and return 1, letting the client worry about it.
01432         default:
01433           {
01434             if (debug_ > 1)
01435               {
01436                 ACE_DEBUG ((LM_DEBUG,
01437                             "ImR: <%s> TRANSIENT exception. alive=false.\n", info.name.c_str ()));
01438               }
01439             info.last_ping = ACE_Time_Value::zero;
01440           }
01441         return 0;
01442         }
01443     }
01444   catch (const CORBA::TIMEOUT&)
01445     {
01446       if (debug_ > 1)
01447         {
01448           ACE_DEBUG ((LM_DEBUG,
01449                       "ImR: <%s> Ping timed out. alive=true.\n", info.name.c_str ()));
01450         }
01451       return 1; // This is "alive" as far as we're concerned. Presumably the client
01452       // will have a less stringent timeout policy, or will want to know
01453       // about the timeout. In any case, we're only guaranteeing that the
01454       // server is alive, not that it's responsive.
01455     }
01456   catch (const CORBA::Exception& ex)
01457     {
01458       if (debug_ > 1)
01459         {
01460           ACE_DEBUG ((LM_DEBUG, "ImR: <%s> Unexpected Ping exception. alive=false\n", info.name.c_str ()));
01461           ex._tao_print_exception ("\n");
01462         }
01463       info.last_ping = ACE_Time_Value::zero;
01464       return false;
01465     }
01466   return 1;
01467 }

void ImR_Locator_i::list ( CORBA::ULong  how_many,
ImplementationRepository::ServerInformationList_out  server_list,
ImplementationRepository::ServerInformationIterator_out  server_iterator 
) [virtual]

Definition at line 1080 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_NEW_THROW_EX, imr_poa_, TAO_Pseudo_Var_T< T >::in(), LM_DEBUG, repository_, and Locator_Repository::servers().

01083 {
01084   if (this->debug_ > 1)
01085     ACE_DEBUG ((LM_DEBUG, "ImR: List servers.\n"));
01086 
01087   // Initialize the out variables, so if we return early, they will
01088   // not be dangling.
01089   server_iterator = ImplementationRepository::ServerInformationIterator::_nil ();
01090   ACE_NEW_THROW_EX (server_list,
01091                     ImplementationRepository::ServerInformationList (0), CORBA::NO_MEMORY ());
01092 
01093   Locator_Repository::SIMap::ENTRY* entry = 0;
01094   Locator_Repository::SIMap::ITERATOR it (this->repository_.servers ());
01095 
01096   // Number of servers that will go into the server_list.
01097   CORBA::ULong n = this->repository_.servers ().current_size ();
01098   if (how_many > 0 && n > how_many)
01099     {
01100       n = how_many;
01101     }
01102 
01103   server_list->length (n);
01104 
01105   if (this->debug_ > 1)
01106     ACE_DEBUG ((LM_DEBUG, "ImR_Locator_i::list: Filling ServerList with %d servers\n", n));
01107 
01108   for (CORBA::ULong i = 0; i < n; i++)
01109     {
01110       it.next (entry);
01111       it.advance ();
01112       ACE_ASSERT (entry != 0);
01113 
01114       Server_Info_Ptr info = entry->int_id_;
01115 
01116       ImplementationRepository::ServerInformation_var imr_info = info->createImRServerInfo ();
01117       server_list[i] = *imr_info;
01118     }
01119 
01120   if (this->repository_.servers ().current_size () > n)
01121     {
01122       if (this->debug_ > 1)
01123         ACE_DEBUG ((LM_DEBUG, "ImR_Locator_i::list: Creating ServerInformation Iterator\n"));
01124 
01125       ImR_Iterator* imr_iter = 0;
01126 
01127       ACE_NEW_THROW_EX (imr_iter,
01128                         ImR_Iterator (n, this->repository_, this->imr_poa_.in ()),
01129                         CORBA::NO_MEMORY ());
01130 
01131       PortableServer::ServantBase_var tmp (imr_iter);
01132 
01133       try
01134         {
01135           PortableServer::ObjectId_var id =
01136             this->imr_poa_->activate_object (imr_iter);
01137           CORBA::Object_var obj = this->imr_poa_->id_to_reference (id.in ());
01138           server_iterator = ImplementationRepository::
01139             ServerInformationIterator::_unchecked_narrow (obj.in ());
01140         }
01141       catch (const CORBA::Exception&)
01142         {
01143           throw;
01144         }
01145     }
01146 }

void ImR_Locator_i::notify_child_death ( const char *  name  )  [virtual]

Definition at line 429 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, Locator_Repository::get_server(), LM_DEBUG, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), and repository_.

00430 {
00431   ACE_ASSERT (name != 0);
00432 
00433   if (this->debug_ > 1)
00434     ACE_DEBUG ((LM_DEBUG, "ImR: Server has died <%s>.\n", name));
00435 
00436   Server_Info_Ptr info = this->repository_.get_server (name);
00437   if (! info.null ())
00438     {
00439       info->ior = "";
00440       info->partial_ior = "";
00441 
00442       int err = this->repository_.update_server (*info);
00443       ACE_ASSERT (err == 0);
00444       ACE_UNUSED_ARG (err);
00445     }
00446   else
00447     {
00448       if (this->debug_ > 1)
00449         ACE_DEBUG ((LM_DEBUG,
00450                     "ImR: Failed to find server in repository.\n"));
00451     }
00452 }

CORBA::Long ImR_Locator_i::register_activator ( const char *  name,
ImplementationRepository::Activator_ptr  admin 
) [virtual]

Definition at line 368 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, Locator_Repository::add_activator(), ACE_OS::gettimeofday(), CORBA::is_nil(), LM_DEBUG, ACE_Time_Value::msec(), orb_, repository_, and unregister_activator_i().

00370 {
00371   ACE_ASSERT (aname != 0);
00372   ACE_ASSERT (! CORBA::is_nil (activator));
00373 
00374   // Before we can register the activator, we need to ensure that any existing
00375   // registration is purged.
00376   this->unregister_activator_i (aname);
00377 
00378   CORBA::String_var ior =
00379     this->orb_->object_to_string (activator);
00380 
00381   CORBA::Long token = ACE_OS::gettimeofday ().msec ();
00382 
00383   int err = this->repository_.add_activator (aname, token, ior.in (), activator);
00384   ACE_ASSERT (err == 0);
00385   ACE_UNUSED_ARG (err);
00386 
00387   if (this->debug_ > 0)
00388     ACE_DEBUG ((LM_DEBUG, "ImR: Activator registered for %s.\n", aname));
00389 
00390   return token;
00391 }

void ImR_Locator_i::remove_server ( const char *  name  )  [virtual]

Definition at line 845 of file ImR_Locator_i.cpp.

References CORBA::SystemException::_tao_minor_code(), ACE_ASSERT, ACE_DEBUG, ACE_ERROR, CORBA::COMPLETED_NO, findPOA(), Locator_Repository::get_server(), TAO_Objref_Var_T< T >::in(), CORBA::is_nil(), LM_DEBUG, LM_ERROR, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), repository_, TAO_IMPLREPO_MINOR_CODE, and wait().

00846 {
00847   ACE_ASSERT (name != 0);
00848   if (this->read_only_)
00849     {
00850       ACE_ERROR ((LM_ERROR,
00851                   "ImR: Can't remove server <%s> due to locked database.\n", name));
00852       throw CORBA::NO_PERMISSION (
00853         CORBA::SystemException::_tao_minor_code (
00854           TAO_IMPLREPO_MINOR_CODE,
00855           0),
00856         CORBA::COMPLETED_NO);
00857     }
00858 
00859   // Note : This will be safe, because any Server_Info_Ptr objects will still
00860   // be valid, and the actual Server_Info will be destroyed when the last
00861   // one goes out of scope.
00862 
00863   Server_Info_Ptr info = this->repository_.get_server (name);
00864   if (! info.null ())
00865     {
00866       if (this->repository_.remove_server (name) == 0)
00867         {
00868           if (this->debug_ > 1)
00869             ACE_DEBUG ((LM_DEBUG, "ImR: Removing Server <%s>...\n", name));
00870 
00871           PortableServer::POA_var poa = findPOA (name);
00872           if (! CORBA::is_nil (poa.in ()))
00873             {
00874               bool etherealize = true;
00875               bool wait = false;
00876               poa->destroy (etherealize, wait);
00877             }
00878           if (this->debug_ > 0)
00879             ACE_DEBUG ((LM_DEBUG, "ImR: Removed Server <%s>.\n", name));
00880         }
00881     }
00882   else
00883     {
00884       ACE_ERROR ((LM_ERROR,
00885                   "ImR: Can't remove unknown server <%s>.\n", name));
00886       throw ImplementationRepository::NotFound ();
00887     }
00888 }

int ImR_Locator_i::run ( void   ) 

Run using the orb reference created during init().

Definition at line 187 of file ImR_Locator_i.cpp.

References ACE_DEBUG, auto_start_servers(), debug(), debug_, ior_multicast_, LM_DEBUG, ACE_Time_Value::msec(), orb_, ping_interval_, read_only_, Locator_Repository::repo_mode(), repository_, ACE_Time_Value::sec(), and startup_timeout_.

Referenced by ImR_Locator_Loader::run(), and run_standalone().

00188 {
00189   if (debug_ > 0)
00190     {
00191       // This debug message was split into two calls to
00192       // work around yet another bug in Visual Studio 2005.
00193       // When this was a single debug message, the value for
00194       // debug () came out garbled and the read-only string
00195       // caused an ACCESS VIOLATION -- Chad Elliott 10/4/2006
00196       ACE_DEBUG ((LM_DEBUG,
00197                   "Implementation Repository: Running\n"
00198                   "\tPing Interval : %dms\n"
00199                   "\tStartup Timeout : %ds\n"
00200                   "\tPersistence : %s\n"
00201                   "\tMulticast : %s\n",
00202                   ping_interval_.msec (),
00203                   startup_timeout_.sec (),
00204                   repository_.repo_mode (),
00205                   ior_multicast_.reactor () != 0 ? "Enabled" : "Disabled"));
00206       ACE_DEBUG ((LM_DEBUG,
00207                   "\tDebug : %d\n"
00208                   "\tLocked : %s\n\n",
00209                   debug (),
00210                   read_only_ ? "True" : "False"));
00211     }
00212   this->auto_start_servers ();
00213 
00214   this->orb_->run ();
00215   return 0;
00216 }

void ImR_Locator_i::server_is_running ( const char *  name,
const char *  partial_ior,
ImplementationRepository::ServerObject_ptr  server_object 
) [virtual]

Definition at line 968 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_TEXT(), Locator_Repository::add_server(), DEFAULT_START_LIMIT, Locator_Repository::get_server(), CORBA::is_nil(), LM_DEBUG, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), orb_, repository_, AsyncStartupWaiter_i::unblock_one(), Locator_Repository::update_server(), and waiter_svt_.

00971 {
00972   ACE_ASSERT (name != 0);
00973   ACE_ASSERT (partial_ior != 0);
00974   ACE_ASSERT (! CORBA::is_nil (server));
00975 
00976   if (this->debug_ > 0)
00977     ACE_DEBUG ((LM_DEBUG, "ImR: Server %s is running at %s.\n", name, partial_ior));
00978 
00979   CORBA::String_var ior = orb_->object_to_string (server);
00980 
00981   if (this->debug_ > 1)
00982     ACE_DEBUG ((LM_DEBUG, "ImR: Server %s callback at %s.\n", name, ior.in ()));
00983 
00984   Server_Info_Ptr info = this->repository_.get_server (name);
00985   if (info.null ())
00986     {
00987       if (this->debug_ > 0)
00988         ACE_DEBUG ((LM_DEBUG, "ImR: Auto adding NORMAL server <%s>.\n", name));
00989 
00990       ImplementationRepository::EnvironmentList env (0);
00991       this->repository_.add_server (name,
00992                                     "", // no activator
00993                                     "", // no cmdline
00994                                     ImplementationRepository::EnvironmentList (),
00995                                     "", // no working dir
00996                                     ImplementationRepository::NORMAL,
00997                                     DEFAULT_START_LIMIT,
00998                                     partial_ior,
00999                                     ior.in (),
01000                                     ImplementationRepository::ServerObject::_nil () // Will connect at first access
01001                                     );
01002     }
01003   else
01004     {
01005       if (info->activation_mode != ImplementationRepository::PER_CLIENT) {
01006         info->ior = ior.in ();
01007         info->partial_ior = partial_ior;
01008         info->server = ImplementationRepository::ServerObject::_nil (); // Will connect at first access
01009 
01010         int err = this->repository_.update_server (*info);
01011         ACE_ASSERT (err == 0);
01012         ACE_UNUSED_ARG (err);
01013 
01014         waiter_svt_.unblock_one (name, partial_ior, ior.in (), false);
01015       } else {
01016         // Note : There's no need to unblock all the waiting request until
01017         // we know the final status of the server.
01018         if (info->waiting_clients > 0)
01019         {
01020           waiter_svt_.unblock_one (name, partial_ior, ior.in (), true);
01021         }
01022         else if (this->debug_ > 1)
01023         {
01024           ACE_DEBUG ((LM_DEBUG,
01025                       ACE_TEXT ("ImR - Ignoring server_is_running due to no ")
01026                       ACE_TEXT ("waiting PER_CLIENT clients.\n")));
01027         }
01028       }
01029     }
01030 }

void ImR_Locator_i::server_is_shutting_down ( const char *  name  )  [virtual]

Definition at line 1033 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, Locator_Repository::get_server(), LM_DEBUG, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), repository_, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::reset(), and Locator_Repository::update_server().

01034 {
01035   ACE_ASSERT (server != 0);
01036   Server_Info_Ptr info = this->repository_.get_server (server);
01037   if (info.null ())
01038     {
01039       if (this->debug_ > 1)
01040         {
01041           ACE_DEBUG ((LM_DEBUG,
01042                       "ImR_Locator_i::server_is_shutting_down: Unknown server:%s\n", server));
01043         }
01044       return;
01045     }
01046 
01047   if (this->debug_ > 0)
01048     ACE_DEBUG ((LM_DEBUG, "ImR: Server <%s> is shutting down.\n", server));
01049 
01050   info->reset ();
01051 
01052   int err = this->repository_.update_server (*info);
01053   ACE_ASSERT (err == 0);
01054   ACE_UNUSED_ARG (err);
01055 }

CORBA::Object_ptr ImR_Locator_i::set_timeout_policy ( CORBA::Object_ptr  obj,
const ACE_Time_Value to 
) [private]

Definition at line 722 of file ImR_Locator_i.cpp.

References CORBA::Object::_duplicate(), TAO_Pseudo_Var_T< T >::_retn(), CORBA::Exception::_tao_print_exception(), ACE_DEBUG, TAO_Pseudo_Var_T< T >::in(), CORBA::is_nil(), LM_DEBUG, and orb_.

Referenced by connect_activator(), connect_server(), init_with_orb(), and shutdown_server().

00723 {
00724   CORBA::Object_var ret (CORBA::Object::_duplicate (obj));
00725 
00726   try
00727     {
00728       TimeBase::TimeT timeout;
00729       ORBSVCS_Time::Time_Value_to_TimeT (timeout, to);
00730       CORBA::Any tmp;
00731       tmp <<= timeout;
00732 
00733       CORBA::PolicyList policies (1);
00734       policies.length (1);
00735       policies[0] = orb_->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE, tmp);
00736 
00737       ret = obj->_set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
00738 
00739       policies[0]->destroy ();
00740 
00741       if (CORBA::is_nil (ret.in ()))
00742         {
00743           if (this->debug_ > 0)
00744             {
00745               ACE_DEBUG ((LM_DEBUG, "ImR: Unable to set timeout policy.\n"));
00746             }
00747           ret = CORBA::Object::_duplicate (obj);
00748         }
00749     }
00750   catch (const CORBA::Exception& ex)
00751     {
00752       ex._tao_print_exception (
00753         "ImR_Locator_i::set_timeout_policy ()");
00754     }
00755 
00756   return ret._retn ();
00757 }

int ImR_Locator_i::setup_multicast ( ACE_Reactor reactor,
const char *  ior 
) [private]

Definition at line 311 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_DEFAULT_MULTICAST_ADDR, ACE_OS::atoi(), debug_, ACE_OS::getenv(), LM_DEBUG, TAO_ORB_Parameters::mcast_discovery_endpoint(), TAO::MCAST_IMPLREPOSERVICE, TAO_ORB_Core::orb_params(), ACE_Event_Handler::READ_MASK, ACE_Reactor::register_handler(), TAO_ORB_Parameters::service_port(), TAO_DEFAULT_IMPLREPO_SERVER_REQUEST_PORT, TAO_ORB_Core_instance(), and TAO_SERVICEID_IMPLREPOSERVICE.

00312 {
00313   ACE_ASSERT (reactor != 0);
00314   ACE_ASSERT (ior != 0);
00315 #if defined (ACE_HAS_IP_MULTICAST)
00316 
00317   TAO_ORB_Core* core = TAO_ORB_Core_instance ();
00318   // See if the -ORBMulticastDiscoveryEndpoint option was specified.
00319   ACE_CString mde (core->orb_params ()->mcast_discovery_endpoint ());
00320 
00321   if (mde.length () != 0)
00322     {
00323       if (this->ior_multicast_.init (ior,
00324                                      mde.c_str (), TAO_SERVICEID_IMPLREPOSERVICE) == -1)
00325         {
00326           return -1;
00327         }
00328     }
00329   else
00330     {
00331       // Port can be specified as param, env var, or default
00332       CORBA::UShort port =
00333         core->orb_params ()->service_port (TAO::MCAST_IMPLREPOSERVICE);
00334       if (port == 0)
00335         {
00336           // Check environment var. for multicast port.
00337           const char* port_number = ACE_OS::getenv ("ImplRepoServicePort");
00338 
00339           if (port_number != 0)
00340             port = static_cast<CORBA::UShort> (ACE_OS::atoi (port_number));
00341         }
00342       if (port == 0)
00343         port = TAO_DEFAULT_IMPLREPO_SERVER_REQUEST_PORT;
00344 
00345       if (this->ior_multicast_.init (ior, port,
00346                                      ACE_DEFAULT_MULTICAST_ADDR, TAO_SERVICEID_IMPLREPOSERVICE) == -1)
00347         {
00348           return -1;
00349         }
00350     }
00351 
00352   // Register event handler for the ior multicast.
00353   if (reactor->register_handler (&this->ior_multicast_,
00354                                  ACE_Event_Handler::READ_MASK) == -1)
00355     {
00356       if (debug_ >= 1)
00357         ACE_DEBUG ((LM_DEBUG, "ImR: cannot register Event handler\n"));
00358       return -1;
00359     }
00360 #else /* ACE_HAS_IP_MULTICAST*/
00361   ACE_UNUSED_ARG (reactor);
00362   ACE_UNUSED_ARG (ior);
00363 #endif /* ACE_HAS_IP_MULTICAST*/
00364   return 0;
00365 }

void ImR_Locator_i::shutdown ( CORBA::Boolean  activators,
CORBA::Boolean  servers 
) [virtual]

Definition at line 219 of file ImR_Locator_i.cpp.

References CORBA::Exception::_tao_print_exception(), ACE_ASSERT, ACE_DEBUG, ACE_ERROR, connect_activator(), debug_, CORBA::is_nil(), LM_DEBUG, LM_ERROR, and shutdown().

00220 {
00221   if (servers != 0 && this->repository_.servers ().current_size () > 0)
00222     {
00223       // Note : shutdown is oneway, so we can't throw
00224       ACE_ERROR ((LM_ERROR, "ImR: Shutdown of all servers not implemented.\n"));
00225     }
00226   if (activators != 0 && this->repository_.activators ().current_size () > 0)
00227     {
00228       ACE_Vector<ImplementationRepository::Activator_var> acts;
00229       Locator_Repository::AIMap::ENTRY* entry = 0;
00230       Locator_Repository::AIMap::ITERATOR it (this->repository_.activators ());
00231       for (;it.next (entry) != 0; it.advance ())
00232         {
00233           Activator_Info_Ptr info = entry->int_id_;
00234           ACE_ASSERT (! info.null ());
00235           connect_activator (*info);
00236           if (! CORBA::is_nil (info->activator.in ()))
00237             acts.push_back (info->activator);
00238         }
00239 
00240       int shutdown_errs = 0;
00241 
00242       for (size_t i = 0; i < acts.size (); ++i)
00243         {
00244           try
00245             {
00246               acts[i]->shutdown ();
00247               acts[i] = ImplementationRepository::Activator::_nil ();
00248             }
00249           catch (const CORBA::Exception& ex)
00250             {
00251               ++shutdown_errs;
00252               if (debug_ > 1)
00253                 {
00254                   ex._tao_print_exception (
00255                     "ImR: shutdown activator");
00256                 }
00257             }
00258         }
00259       if (debug_ > 0 && shutdown_errs > 0)
00260         {
00261           ACE_DEBUG ((LM_DEBUG, "ImR: Some activators could not be shut down.\n"));
00262         }
00263     }
00264   // Technically, we should wait for all the activators to unregister, but
00265   // ,for now at least, it doesn't seem worth it.
00266   this->shutdown (false);
00267 }

void ImR_Locator_i::shutdown ( bool  wait_for_completion  ) 

Shutdown the orb.

Definition at line 270 of file ImR_Locator_i.cpp.

References orb_.

Referenced by ImR_Locator_Shutdown::operator()(), and shutdown().

00271 {
00272   this->orb_->shutdown (wait_for_completion);
00273 }

void ImR_Locator_i::shutdown_server ( const char *  name  )  [virtual]

Definition at line 905 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, ACE_ERROR, connect_server(), DEFAULT_SHUTDOWN_TIMEOUT, Locator_Repository::get_server(), TAO_Pseudo_Var_T< T >::in(), CORBA::is_nil(), LM_DEBUG, LM_ERROR, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), repository_, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::reset(), set_timeout_policy(), and Locator_Repository::update_server().

00906 {
00907   ACE_ASSERT (server != 0);
00908 
00909   if (this->debug_ > 0)
00910     ACE_DEBUG ((LM_DEBUG, "ImR: Shutting down server <%s>.\n", server));
00911 
00912   Server_Info_Ptr info = this->repository_.get_server (server);
00913   if (info.null ())
00914     {
00915       ACE_ERROR ((LM_ERROR,
00916                   "ImR: shutdown_server () Cannot find info for server <%s>\n", server));
00917       throw ImplementationRepository::NotFound ();
00918     }
00919 
00920   connect_server (*info);
00921 
00922   if (CORBA::is_nil (info->server.in ()))
00923     {
00924       ACE_ERROR ((LM_ERROR,
00925                   "ImR: shutdown_server () Cannot connect to server <%s>\n", server));
00926       throw ImplementationRepository::NotFound ();
00927     }
00928 
00929   try
00930     {
00931       CORBA::Object_var obj = set_timeout_policy (info->server.in (), DEFAULT_SHUTDOWN_TIMEOUT);
00932       ImplementationRepository::ServerObject_var server =
00933         ImplementationRepository::ServerObject::_unchecked_narrow (obj.in ());
00934       server->shutdown ();
00935     }
00936   catch (const CORBA::TIMEOUT&)
00937     {
00938       info->reset ();
00939       int err = this->repository_.update_server (*info);
00940       ACE_ASSERT (err == 0);
00941       ACE_UNUSED_ARG (err);
00942       // Note : This is a good thing. It means we didn't waste our time waiting for
00943       // the server to finish shutting down.
00944       if (this->debug_ > 1)
00945         {
00946           ACE_DEBUG ((LM_DEBUG, "ImR: Timeout while waiting for <%s> shutdown.\n", server));
00947         }
00948       throw;
00949     }
00950   catch (const CORBA::Exception&)
00951     {
00952       if (this->debug_ > 1)
00953         {
00954           ACE_DEBUG ((LM_DEBUG, "ImR: Exception ignored while shutting down <%s>\n", server));
00955         }
00956     }
00957 
00958   // Note : In most cases this has already been done in the server_is_shutting_down ()
00959   // operation, but it doesn't hurt to update it again.
00960   info->reset ();
00961 
00962   int err = this->repository_.update_server (*info);
00963   ACE_ASSERT (err == 0);
00964   ACE_UNUSED_ARG (err);
00965 }

ImplementationRepository::StartupInfo * ImR_Locator_i::start_server ( Server_Info info,
bool  manual_start,
int &  waiting_clients 
) [private]

Definition at line 585 of file ImR_Locator_i.cpp.

References CORBA::Exception::_tao_print_exception(), ACE_ASSERT, ACE_DEBUG, Server_Info::activation_mode, Server_Info::activator, ACE_String_Base< CHAR >::c_str(), Server_Info::cmdline, debug_, Server_Info::dir, Server_Info::env_vars, get_activator(), CORBA::is_nil(), ACE_String_Base< CHAR >::length(), LM_DEBUG, Server_Info::name, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), Server_Info::partial_ior, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::reset(), Server_Info::reset(), Server_Info::start_count, Server_Info::start_limit, Server_Info::starting, CORBA::string_dup(), and waiter_.

Referenced by activate_perclient_server_i(), and activate_server_i().

00587 {
00588   if (info.activation_mode == ImplementationRepository::MANUAL && ! manual_start)
00589     {
00590       if (debug_ > 0)
00591         ACE_DEBUG ((LM_DEBUG, "ImR: Cannot start server <%s>. ActivationMode=MANUAL\n", info.name.c_str ()));
00592       throw ImplementationRepository::CannotActivate(
00593         CORBA::string_dup (
00594           "Cannot implicitly activate MANUAL server."));
00595     }
00596   if (info.cmdline.length () == 0)
00597     {
00598       if (debug_ > 0)
00599         ACE_DEBUG ((LM_DEBUG, "ImR: Cannot start server <%s>."
00600                     " No command line.\n", info.name.c_str ()));
00601       throw ImplementationRepository::CannotActivate(
00602         CORBA::string_dup (
00603           "No command line registered for server."));
00604     }
00605 
00606   Activator_Info_Ptr ainfo = get_activator (info.activator);
00607 
00608   if (ainfo.null () || CORBA::is_nil (ainfo->activator.in ()))
00609     {
00610       if (debug_ > 0)
00611         ACE_DEBUG ((LM_DEBUG, "ImR: Cannot start server <%s>. "
00612                     "Activator <%s> not found.\n", info.name.c_str (), info.activator.c_str ()));
00613       throw ImplementationRepository::CannotActivate(
00614         CORBA::string_dup (
00615           "No activator registered for server."));
00616     }
00617 
00618   try
00619     {
00620       ++waiting_clients;
00621 
00622       if (waiting_clients <= 1 ||
00623           info.activation_mode == ImplementationRepository::PER_CLIENT)
00624         {
00625           info.starting = true;
00626           ++info.start_count;
00627           ACE_ASSERT (info.start_count <= info.start_limit);
00628           if (this->debug_ > 0)
00629             {
00630               ACE_DEBUG ((LM_DEBUG, "ImR: Starting server <%s>. Attempt %d/%d.\n",
00631                           info.name.c_str (), info.start_count, info.start_limit));
00632             }
00633           ainfo->activator->start_server (
00634                                           info.name.c_str (),
00635                                           info.cmdline.c_str (),
00636                                           info.dir.c_str (),
00637                                           info.env_vars);
00638         }
00639 
00640       if (info.partial_ior.length () == 0)
00641         {
00642           if (this->debug_ > 0)
00643             {
00644               ACE_DEBUG ((LM_DEBUG, "ImR: Waiting for <%s> to start...\n", info.name.c_str ()));
00645             }
00646 
00647           ImplementationRepository::StartupInfo_var si =
00648             waiter_->wait_for_startup (info.name.c_str ());
00649 
00650           --waiting_clients;
00651           info.starting = false;
00652 
00653           return si._retn ();
00654         }
00655       else // The server_is_running () came in before the wait_for_startup ()
00656         {
00657           if (this->debug_ > 0)
00658             {
00659               ACE_DEBUG ((LM_DEBUG, "ImR: <%s> Skipping wait. Already started.\n", info.name.c_str ()));
00660             }
00661           --waiting_clients;
00662           info.starting = false;
00663         }
00664     }
00665   catch (const CORBA::TIMEOUT&)
00666     {
00667       --waiting_clients;
00668       info.starting = false;
00669       // We may have connected successfully, because the timeout could occur before
00670       // the AsyncStartupWaiter manages to return. In fact, when the ImR is very busy
00671       // this is the most likely code path.
00672       if (info.partial_ior.length () == 0)
00673         {
00674           if (debug_ > 0)
00675             ACE_DEBUG ((LM_DEBUG, "ImR : Timeout waiting for <%s> to start.\n", info.name.c_str ()));
00676           info.reset ();
00677         }
00678     }
00679   catch (const ImplementationRepository::CannotActivate&)
00680     {
00681       --waiting_clients;
00682       info.starting = false;
00683       info.reset ();
00684       if (debug_ > 0)
00685         ACE_DEBUG ((LM_DEBUG, "ImR: Activator cannot start <%s>.\n", info.name.c_str ()));
00686     }
00687   catch (const CORBA::Exception& ex)
00688     {
00689       --waiting_clients;
00690       info.starting = false;
00691       if (debug_ > 0)
00692         ACE_DEBUG ((LM_DEBUG, "ImR: Unexpected exception while starting <%s>.\n", info.name.c_str ()));
00693       if (debug_ > 1)
00694         ex._tao_print_exception ("");
00695       info.reset ();
00696 
00697       // Before we reset the activator info, let's see if it's still
00698       // there then let's keep it around for a while.
00699       bool dead_activator = false;
00700       try
00701         {
00702           dead_activator = ainfo->activator->_non_existent ();
00703         }
00704       catch (const CORBA::Exception&)
00705         {
00706           dead_activator = true;
00707         }
00708 
00709       if (dead_activator)
00710         {
00711           // Activator is damaged - reset our info.
00712           // Client's trying to restart a server on this host will
00713           // subsequently be told "no activator found for host ..." or
00714           // some such.
00715           ainfo->reset ();
00716         }
00717     }
00718   return 0; // This is not a corba call, so a zero should be ok
00719 }

void ImR_Locator_i::teardown_multicast (  )  [private]

Definition at line 301 of file ImR_Locator_i.cpp.

References ior_multicast_, ACE_Event_Handler::READ_MASK, and ACE_Reactor::remove_handler().

Referenced by fini().

00302 {
00303   ACE_Reactor* r = ior_multicast_.reactor ();
00304   if (r != 0) {
00305     r->remove_handler (&ior_multicast_, ACE_Event_Handler::READ_MASK);
00306     ior_multicast_.reactor (0);
00307   }
00308 }

void ImR_Locator_i::unregister_activator ( const char *  name,
CORBA::Long  token 
) [virtual]

Definition at line 394 of file ImR_Locator_i.cpp.

References ACE_ASSERT, ACE_DEBUG, get_activator(), LM_DEBUG, ACE_Strong_Bound_Ptr< X, ACE_LOCK >::null(), and unregister_activator_i().

00396 {
00397   ACE_ASSERT (aname != 0);
00398   Activator_Info_Ptr info = this->get_activator (aname);
00399 
00400   if (! info.null ())
00401     {
00402       if (info->token != token && this->debug_ > 0)
00403         {
00404           ACE_DEBUG ((LM_DEBUG, "ImR: Ignoring unregister activator:%s. Wrong token.\n", aname));
00405           return;
00406         }
00407 
00408       this->unregister_activator_i (aname);
00409 
00410       if (this->debug_ > 0)
00411         ACE_DEBUG ((LM_DEBUG, "ImR: Activator %s unregistered.\n", aname));
00412     }
00413   else
00414     {
00415       if (this->debug_ > 0)
00416         ACE_DEBUG ((LM_DEBUG, "ImR: Ignoring unregister activator:%s. Unknown activator.\n", aname));
00417     }
00418 }

void ImR_Locator_i::unregister_activator_i ( const char *  activator  )  [private]

Definition at line 421 of file ImR_Locator_i.cpp.

References ACE_ASSERT, Locator_Repository::remove_activator(), and repository_.

Referenced by register_activator(), and unregister_activator().

00422 {
00423   ACE_ASSERT (aname != 0);
00424   int err = this->repository_.remove_activator (aname);
00425   ACE_UNUSED_ARG (err);
00426 }


Member Data Documentation

ImR_Adapter ImR_Locator_i::adapter_ [private]

Definition at line 132 of file ImR_Locator_i.h.

Referenced by init_with_orb().

int ImR_Locator_i::debug_ [private]

Definition at line 141 of file ImR_Locator_i.h.

Referenced by activate_perclient_server_i(), activate_server(), activate_server_i(), add_or_update_server(), connect_activator(), connect_server(), debug(), find(), fini(), init_with_orb(), is_alive(), is_alive_i(), run(), setup_multicast(), shutdown(), and start_server().

ImR_Forwarder ImR_Locator_i::forwarder_ [private]

Definition at line 129 of file ImR_Locator_i.h.

Referenced by init_with_orb().

PortableServer::POA_var ImR_Locator_i::imr_poa_ [private]

Definition at line 139 of file ImR_Locator_i.h.

Referenced by init_with_orb(), and list().

IORTable::Locator_var ImR_Locator_i::ins_locator_ [private]

The locator interface for the IORTable.

Definition at line 135 of file ImR_Locator_i.h.

Referenced by ImR_Locator_i().

TAO_IOR_Multicast ImR_Locator_i::ior_multicast_ [private]

Definition at line 143 of file ImR_Locator_i.h.

Referenced by run(), and teardown_multicast().

CORBA::ORB_var ImR_Locator_i::orb_ [private]

Definition at line 137 of file ImR_Locator_i.h.

Referenced by connect_activator(), connect_server(), fini(), init_with_orb(), is_alive(), register_activator(), run(), server_is_running(), set_timeout_policy(), and shutdown().

ACE_Time_Value ImR_Locator_i::ping_interval_ [private]

Definition at line 152 of file ImR_Locator_i.h.

Referenced by init_with_orb(), is_alive_i(), and run().

bool ImR_Locator_i::read_only_ [private]

Definition at line 150 of file ImR_Locator_i.h.

Referenced by init_with_orb(), and run().

Locator_Repository ImR_Locator_i::repository_ [private]

Definition at line 145 of file ImR_Locator_i.h.

Referenced by activate_perclient_server_i(), activate_server_by_name(), add_or_update_server(), find(), get_activator(), init_with_orb(), is_alive_i(), list(), notify_child_death(), register_activator(), remove_server(), run(), server_is_running(), server_is_shutting_down(), shutdown_server(), and unregister_activator_i().

PortableServer::POA_var ImR_Locator_i::root_poa_ [private]

Definition at line 138 of file ImR_Locator_i.h.

Referenced by findPOA(), fini(), and init_with_orb().

ACE_Time_Value ImR_Locator_i::startup_timeout_ [private]

Definition at line 151 of file ImR_Locator_i.h.

Referenced by connect_activator(), init_with_orb(), and run().

ImplementationRepository::AsyncStartupWaiter_var ImR_Locator_i::waiter_ [private]

Definition at line 148 of file ImR_Locator_i.h.

Referenced by init_with_orb(), and start_server().

AsyncStartupWaiter_i ImR_Locator_i::waiter_svt_ [private]

Definition at line 147 of file ImR_Locator_i.h.

Referenced by activate_server_i(), init_with_orb(), and server_is_running().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:47:02 2010 for TAO_Implementation_Repository by  doxygen 1.4.7