Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / ImplRepo_Service / ImR_Locator_i.cpp
blob2e435ddae6f00b2be1ed08bcc6826123607cb7f5
1 #include "orbsvcs/Log_Macros.h"
2 #include "ImR_Locator_i.h"
3 #include "utils.h"
4 #include "Iterator.h"
5 #include "INS_Locator.h"
6 #include "UpdateableServerInfo.h"
8 #include "Locator_Repository.h"
9 #include "Config_Backing_Store.h"
10 #include "Shared_Backing_Store.h"
11 #include "XML_Backing_Store.h"
13 #include "orbsvcs/Time_Utilities.h"
15 #include "tao/Messaging/Messaging.h"
16 #include "tao/AnyTypeCode/Any.h"
17 #include "tao/ORB_Core.h"
19 #include "ace/ARGV.h"
20 #include "ace/OS_NS_sys_time.h"
21 #include "ace/Vector_T.h"
22 #include "ace/Task.h"
24 /// We want to give shutdown a little more time to work, so that we
25 /// can guarantee to the tao_imr utility that it has shutdown. The tao_imr
26 /// utility prints a different message depending on whether shutdown succeeds
27 /// or times out.
28 static const ACE_Time_Value DEFAULT_SHUTDOWN_TIMEOUT (0, 5000 * 1000);
30 static PortableServer::POA_ptr
31 createPersistentPOA (PortableServer::POA_ptr root_poa, const char* poa_name) {
32 PortableServer::LifespanPolicy_var life =
33 root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
35 PortableServer::IdAssignmentPolicy_var assign =
36 root_poa->create_id_assignment_policy (PortableServer::USER_ID);
38 CORBA::PolicyList pols;
39 pols.length (2);
40 pols[0] = PortableServer::LifespanPolicy::_duplicate (life.in ());
41 pols[1] = PortableServer::IdAssignmentPolicy::_duplicate (assign.in ());
43 PortableServer::POAManager_var mgr = root_poa->the_POAManager ();
44 PortableServer::POA_var poa =
45 root_poa->create_POA (poa_name, mgr.in (), pols);
47 life->destroy ();
48 assign->destroy ();
50 return poa._retn ();
53 int ImR_Locator_i::debug_ = 0;
55 ImR_Locator_i::ImR_Locator_i ()
56 : dsi_forwarder_ (*this)
57 , ins_locator_ (0)
58 , aam_active_ ()
59 , aam_terminating_ ()
60 , opts_ (0)
61 , lock_ ()
62 , shutdown_handler_ (this)
64 // Visual C++ 6.0 is not smart enough to do a direct assignment
65 // while allocating the INS_Locator. So, we have to do it in
66 // two steps.
67 INS_Locator* locator;
68 ACE_NEW (locator, INS_Locator (*this));
69 ins_locator_ = locator;
72 ImR_Locator_i::~ImR_Locator_i ()
76 int
77 ImR_Locator_i::init_with_orb (CORBA::ORB_ptr orb)
79 this->orb_ = CORBA::ORB::_duplicate (orb);
80 ImR_Locator_i::debug_ = this->opts_->debug ();
81 CORBA::Object_var obj =
82 this->orb_->resolve_initial_references ("RootPOA");
83 this->root_poa_ = PortableServer::POA::_narrow (obj.in ());
84 ACE_ASSERT (! CORBA::is_nil (this->root_poa_.in ()));
86 this->dsi_forwarder_.init (orb);
87 this->adapter_.init (& this->dsi_forwarder_);
88 this->pinger_.init (orb, this->opts_->ping_interval ());
90 this->opts_->pinger (&this->pinger_);
92 // Register the Adapter_Activator reference to be the RootPOA's
93 // Adapter Activator.
94 root_poa_->the_activator (&this->adapter_);
96 // Use a persistent POA so that any IOR
97 this->imr_poa_ = createPersistentPOA (this->root_poa_.in (),
98 "ImplRepo_Service");
99 ACE_ASSERT (! CORBA::is_nil (this->imr_poa_.in ()));
101 PortableServer::ObjectId_var id =
102 PortableServer::string_to_ObjectId ("ImplRepo_Service");
103 this->imr_poa_->activate_object_with_id (id.in (), this);
105 obj = this->imr_poa_->id_to_reference (id.in ());
106 ImplementationRepository::Locator_var locator =
107 ImplementationRepository::Locator::_narrow (obj.in ());
108 ACE_ASSERT(! CORBA::is_nil (locator.in ()));
109 const CORBA::String_var ior = this->orb_->object_to_string (obj.in ());
111 // create the selected Locator_Repository with backing store
112 switch (this->opts_->repository_mode ())
114 case Options::REPO_REGISTRY:
116 repository_.reset(new Registry_Backing_Store(*this->opts_, orb));
117 break;
119 case Options::REPO_HEAP_FILE:
121 repository_.reset(new Heap_Backing_Store(*this->opts_, orb));
122 break;
124 case Options::REPO_XML_FILE:
126 repository_.reset(new XML_Backing_Store(*this->opts_, orb));
127 break;
129 case Options::REPO_SHARED_FILES:
131 repository_.reset(new Shared_Backing_Store(*this->opts_, orb, this));
132 break;
134 case Options::REPO_NONE:
136 repository_.reset(new No_Backing_Store(*this->opts_, orb));
137 break;
139 default:
141 bool invalid_rmode_specified = false;
142 ACE_ASSERT (invalid_rmode_specified);
143 ACE_UNUSED_ARG (invalid_rmode_specified);
144 ORBSVCS_ERROR_RETURN ((
145 LM_ERROR, ACE_TEXT ("Repository failed to initialize\n")), -1);
149 // Register the ImR for use with INS
150 obj = orb->resolve_initial_references ("AsyncIORTable");
151 IORTable::Table_var ior_table = IORTable::Table::_narrow (obj.in ());
152 ACE_ASSERT (! CORBA::is_nil (ior_table.in ()));
153 ior_table->set_locator (this->ins_locator_.in ());
155 // Initialize the repository. This will load any values that
156 // may have been persisted before.
157 int result = this->repository_->init(this->root_poa_.in (),
158 this->imr_poa_.in (),
159 ior);
160 if (result != 0)
162 return result;
165 Locator_Repository::SIMap::ENTRY* entry = 0;
166 Locator_Repository::SIMap::ITERATOR it (this->repository_->servers ());
168 for (;it.next (entry) != 0; it.advance ())
170 UpdateableServerInfo info (this->repository_, entry->int_id_);
171 bool const is_alive = this->server_is_alive (info);
172 Server_Info *active = info.edit()->active_info ();
173 if (this->debug_ > 0)
175 ORBSVCS_DEBUG ((LM_DEBUG,
176 ACE_TEXT ("server <%C> is_alive = %d\n"),
177 active->ping_id(), is_alive));
180 if (!is_alive)
182 // We have read an existing configuration from the repository
183 // and when a server is not alive we reset it, it could have
184 // been shutdown when we where offline. We don't know its process
185 // id so pass zero
186 this->pinger_.remove_server (active->ping_id(), 0);
187 info.edit()->reset_runtime ();
188 active->reset_runtime ();
189 continue;
192 active->death_notify = false;
193 if (active->pid > 0)
195 Activator_Info_Ptr ainfo =
196 this->get_activator (active->activator);
198 if (!(ainfo.null () || CORBA::is_nil (ainfo->activator.in ())))
200 ImplementationRepository::ActivatorExt_var actx =
201 ImplementationRepository::ActivatorExt::_narrow (ainfo->activator.in ());
204 active->death_notify =
205 !CORBA::is_nil (actx.in ()) && actx->still_alive (active->pid);
207 catch (const CORBA::Exception &)
210 if (this->debug_ > 0)
212 ORBSVCS_DEBUG ((LM_DEBUG,
213 ACE_TEXT ("activator says death_notify = %d\n"),
214 active->death_notify));
220 // Only after verifying do we report the IOR and become open for business
221 return this->repository_->report_ior(this->imr_poa_.in ());
225 ImR_Locator_i::init (Options& opts)
227 this->opts_ = &opts;
228 ACE_CString cmdline = opts.cmdline ();
229 cmdline += " -orbuseimr 0";
230 ACE_ARGV av (ACE_TEXT_CHAR_TO_TCHAR (cmdline.c_str ()));
231 int argc = av.argc ();
232 ACE_TCHAR** argv = av.argv ();
234 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "TAO_ImR_Locator");
235 int err = this->init_with_orb (orb.in ());
236 return err;
240 ImR_Locator_i::run ()
242 if (debug_ > 0)
244 // This debug message was split into two calls to
245 // work around yet another bug in Visual Studio 2005.
246 // When this was a single debug message, the value for
247 // debug () came out garbled and the read-only string
248 // caused an ACCESS VIOLATION -- Chad Elliott 10/4/2006
249 ORBSVCS_DEBUG ((LM_DEBUG,
250 ACE_TEXT ("Implementation Repository: Running\n")
251 ACE_TEXT ("\tPing Interval : %dms\n")
252 ACE_TEXT ("\tPing Timeout : %dms\n")
253 ACE_TEXT ("\tStartup Timeout : %ds\n")
254 ACE_TEXT ("\tPersistence : %s\n")
255 ACE_TEXT ("\tMulticast : %C\n"),
256 this->opts_->ping_interval ().msec (),
257 this->opts_->ping_timeout ().msec (),
258 this->opts_->startup_timeout ().sec (),
259 this->repository_->repo_mode (),
260 (this->repository_->multicast () != 0 ?
261 "Enabled" : "Disabled")));
262 ORBSVCS_DEBUG ((LM_DEBUG,
263 ACE_TEXT ("\tDebug : %d\n")
264 ACE_TEXT ("\tReadOnly : %C\n\n"),
265 debug (),
266 (this->opts_->readonly () ? "True" : "False")));
268 this->auto_start_servers ();
270 this->orb_->run ();
272 return 0;
275 void
276 ImR_Locator_i::shutdown
277 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
278 CORBA::Boolean activators, CORBA::Boolean servers)
280 this->pinger_.shutdown ();
281 this->aam_active_.reset ();
282 this->aam_terminating_.reset ();
283 if (servers != 0 && this->repository_->servers ().current_size () > 0)
285 // Note : shutdown is oneway, so we can't throw
286 ORBSVCS_ERROR ((
287 LM_ERROR,
288 ACE_TEXT ("(%P|%t) ImR: Shutdown of all servers not implemented.\n")));
290 if (activators != 0 && this->repository_->activators ().current_size () > 0)
292 ACE_Vector<ImplementationRepository::Activator_var> acts;
293 Locator_Repository::AIMap::ENTRY* entry = 0;
294 Locator_Repository::AIMap::ITERATOR it (this->repository_->activators ());
295 for (;it.next (entry) != 0; it.advance ())
297 Activator_Info_Ptr info = entry->int_id_;
298 ACE_ASSERT (! info.null ());
299 this->connect_activator (*info);
300 if (! CORBA::is_nil (info->activator.in ()))
301 acts.push_back (info->activator);
304 int shutdown_errs = 0;
306 for (size_t i = 0; i < acts.size (); ++i)
310 acts[i]->shutdown ();
311 acts[i] = ImplementationRepository::Activator::_nil ();
313 catch (const CORBA::Exception& ex)
315 ++shutdown_errs;
316 if (debug_ > 1)
318 ex._tao_print_exception (ACE_TEXT ("(%P|%t) ImR: shutdown activator"));
322 if (debug_ > 0 && shutdown_errs > 0)
324 ORBSVCS_DEBUG (( LM_DEBUG,
325 ACE_TEXT ("(%P|%t) ImR: Some activators could not be shut down.\n")));
328 // Technically, we should wait for all the activators to unregister, but
329 // ,for now at least, it doesn't seem worth it.
330 this->shutdown (false);
332 _tao_rh->shutdown ();
336 ImR_Locator_i::Shutdown_Handler::handle_exception (ACE_HANDLE)
338 this->owner_->shutdown (false);
339 return 0;
342 void
343 ImR_Locator_i::signal_shutdown ()
345 this->orb_->orb_core ()->reactor ()->notify (&this->shutdown_handler_);
348 void
349 ImR_Locator_i::shutdown (bool wait_for_completion)
351 this->repository_->shutdown ();
352 this->orb_->shutdown (wait_for_completion);
355 const Options *
356 ImR_Locator_i::opts () const
358 return this->opts_;
362 ImR_Locator_i::fini ()
366 if (debug_ > 1)
367 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Shutting down...\n")));
369 this->root_poa_->destroy (1, 1);
371 this->orb_->destroy ();
373 if (debug_ > 0)
374 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Shut down successfully.\n")));
376 catch (const CORBA::Exception& ex)
378 ex._tao_print_exception (ACE_TEXT ("ImR_Locator_i::fini"));
379 throw;
381 return 0;
384 void
385 ImR_Locator_i::register_activator
386 (ImplementationRepository::AMH_LocatorResponseHandler_ptr _tao_rh,
387 const char* aname,
388 ImplementationRepository::Activator_ptr activator)
390 ACE_ASSERT (aname != 0);
391 ACE_ASSERT (! CORBA::is_nil (activator));
393 // Before we can register the activator, we need to ensure that any existing
394 // registration is purged.
395 this->unregister_activator_i (aname);
397 CORBA::String_var ior =
398 this->orb_->object_to_string (activator);
400 CORBA::Long token = ACE_OS::gettimeofday ().msec ();
402 int err = this->repository_->add_activator (aname, token, ior.in (), activator);
403 ACE_ASSERT (err == 0);
404 ACE_UNUSED_ARG (err);
406 if (debug_ > 0)
407 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Activator registered for %C.\n"),
408 aname));
410 _tao_rh->register_activator (token);
413 void
414 ImR_Locator_i::unregister_activator
415 (ImplementationRepository::AMH_LocatorResponseHandler_ptr _tao_rh,
416 const char* aname,
417 CORBA::Long token)
419 ACE_ASSERT (aname != 0);
420 Activator_Info_Ptr info = this->get_activator (aname);
422 if (! info.null ())
424 if (info->token != token && debug_ > 0)
426 ORBSVCS_DEBUG ((
427 LM_DEBUG,
428 ACE_TEXT ("(%P|%t) ImR: Ignoring unregister activator:%C. Wrong token.\n"),
429 aname));
430 _tao_rh->unregister_activator ();
431 return;
434 this->unregister_activator_i (aname);
436 if (debug_ > 0)
437 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Activator %C unregistered.\n"),
438 aname));
440 else
442 if (debug_ > 0)
443 ORBSVCS_DEBUG ((
444 LM_DEBUG,
445 ACE_TEXT ("(%P|%t) ImR: Ignoring unregister activator: %C. ")
446 ACE_TEXT ("Unknown activator.\n"),
447 aname));
449 _tao_rh->unregister_activator ();
452 void
453 ImR_Locator_i::unregister_activator_i (const char* aname)
455 int err = this->repository_->remove_activator (aname);
456 ACE_UNUSED_ARG (err);
459 void
460 ImR_Locator_i::remote_access_update (const char *name,
461 ImplementationRepository::AAM_Status state)
463 /* ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_); */
464 AsyncAccessManager_ptr aam (this->find_aam (name));
465 if (aam.is_nil())
467 UpdateableServerInfo info (this->repository_, name);
468 if (info.null ())
470 if (debug_ > 0)
471 ORBSVCS_DEBUG ((LM_DEBUG,
472 ACE_TEXT ("(%P|%t) ImR: remote_acccess")
473 ACE_TEXT (" <%C> unregistered.\n"),
474 name));
475 return;
477 aam = this->create_aam (info);
479 /* mon.release (); */
480 aam->remote_state (state);
483 void
484 ImR_Locator_i::child_death_i (const char* name, int pid)
486 if (debug_ > 1)
488 ORBSVCS_DEBUG ((LM_DEBUG,
489 ACE_TEXT ("(%P|%t) ImR: Server <%C> has died with pid <%d>\n"),
490 name, pid));
493 this->pinger_.remove_server (name, pid);
494 AsyncAccessManager_ptr aam (this->find_aam (name, false));
495 bool terminated = !aam.is_nil () && aam->notify_child_death (pid);
496 aam = this->find_aam (name, true);
497 if (!terminated && !aam.is_nil ())
499 terminated = aam->notify_child_death (pid);
501 UpdateableServerInfo info(this->repository_, name, pid);
502 if (! info.null ())
504 info.edit ()->reset_runtime ();
506 else
508 if (debug_ > 1)
510 ORBSVCS_ERROR ((LM_ERROR,
511 ACE_TEXT ("(%P|%t) ImR: Failed to find server/pid in repository.\n")));
516 void
517 ImR_Locator_i::child_death_pid
518 (ImplementationRepository::AMH_LocatorResponseHandler_ptr _tao_rh,
519 const char* name, CORBA::Long pid)
521 this->child_death_i (name, pid);
522 _tao_rh->child_death_pid ();
525 void
526 ImR_Locator_i::spawn_pid
527 (ImplementationRepository::AMH_LocatorResponseHandler_ptr _tao_rh,
528 const char* name, CORBA::Long pid)
530 if (debug_ > 1)
532 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Server <%C> spawned with pid <%d>.\n"),
533 name, pid));
536 UpdateableServerInfo info(this->repository_, name);
537 if (!info.null ())
539 if (debug_ > 4)
541 ORBSVCS_DEBUG ((LM_DEBUG,
542 ACE_TEXT ("(%P|%t) ImR: Server <%C> spawn_pid prev pid was <%d> becoming <%d>\n"),
543 name, info.edit ()->active_info ()->pid, pid));
546 AsyncAccessManager_ptr aam (this->find_aam (name, true));
547 if (aam.is_nil ())
549 aam = this->find_aam (name, false);
551 else
553 aam->update_prev_pid ();
555 info.edit ()->active_info ()->pid = pid;
556 info.edit ()->active_info ()->death_notify = true;
558 else
560 if (debug_ > 1)
562 ORBSVCS_ERROR ((LM_ERROR,
563 ACE_TEXT ("(%P|%t) ImR: Failed to find server <%C> in repository\n"),
564 name));
567 this->pinger_.set_pid (name, pid);
569 _tao_rh->spawn_pid ();
572 char*
573 ImR_Locator_i::activate_server_by_name (const char* name, bool manual_start)
575 ImR_SyncResponseHandler rh ("", this->orb_.in());
576 this->activate_server_by_name (name, manual_start, &rh);
577 return rh.wait_for_result ();
580 char*
581 ImR_Locator_i::activate_server_by_object (const char* object_name)
583 Server_Info_Ptr si;
584 ACE_CString key;
585 ACE_CString full (object_name);
586 if (this->split_key (full, key, si))
588 ImR_SyncResponseHandler rh (key.c_str(), this->orb_.in());
589 this->activate_server_by_info (si, &rh);
590 return rh.wait_for_result ();
592 throw ImplementationRepository::NotFound();
595 void
596 ImR_Locator_i::activate_server
597 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
598 const char* server)
600 if (debug_ > 1)
602 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Manually activating server <%C>\n"),
603 server));
606 ImR_ResponseHandler *rh = 0;
607 ACE_NEW (rh,
608 ImR_Loc_ResponseHandler (ImR_Loc_ResponseHandler::LOC_ACTIVATE_SERVER,
609 _tao_rh));
611 // This is the version called by tao_imr to activate the server, manually
612 // starting it if necessary.
613 activate_server_by_name (server, true, rh);
616 bool
617 ImR_Locator_i::get_info_for_name (const char* name, Server_Info_Ptr &si)
619 si = this->repository_->get_active_server (name);
620 return !si.null();
623 bool
624 ImR_Locator_i::split_key (ACE_CString &full, ACE_CString &key, Server_Info_Ptr &si)
626 key = full;
627 if (this->get_info_for_name (full.c_str(), si))
629 return true;
632 ACE_CString::size_type pos = full.rfind ('/');
633 while (pos != ACE_CString::npos)
635 ACE_CString server = full.substring (0, pos);
636 if (this->get_info_for_name (server.c_str (), si))
638 return true;
640 pos = server.rfind ('/');
643 return false;
646 void
647 ImR_Locator_i::activate_server_by_name (const char* name, bool manual_start,
648 ImR_ResponseHandler *rh)
650 // Activate the server, starting it if necessary. Don't start MANUAL
651 // servers unless manual_start=true
652 UpdateableServerInfo info (this->repository_, name);
653 if (info.null ())
655 rh->send_exception ( new ImplementationRepository::NotFound );
657 else
659 this->activate_server_i (info, manual_start, rh);
663 void
664 ImR_Locator_i::activate_server_by_info (const Server_Info_Ptr &si,
665 ImR_ResponseHandler *rh)
667 UpdateableServerInfo info (this->repository_, si, true);
668 this->activate_server_i (info, false, rh);
671 void
672 ImR_Locator_i::activate_server_i (UpdateableServerInfo& info,
673 bool manual_start,
674 ImR_ResponseHandler *rh)
676 AsyncAccessManager_ptr aam;
677 if (info->is_mode(ImplementationRepository::PER_CLIENT))
679 ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
680 aam = this->create_aam (info);
682 else
684 aam = this->find_aam (info->ping_id ());
685 if (aam.is_nil())
687 ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
688 aam = this->create_aam (info);
691 aam->add_interest (rh, manual_start);
694 CORBA::Object_ptr
695 ImR_Locator_i::set_timeout_policy (CORBA::Object_ptr obj, const ACE_Time_Value& to)
697 CORBA::Object_var ret (CORBA::Object::_duplicate (obj));
701 TimeBase::TimeT timeout;
702 ORBSVCS_Time::Time_Value_to_TimeT (timeout, to);
703 CORBA::Any tmp;
704 tmp <<= timeout;
706 CORBA::PolicyList policies (1);
707 policies.length (1);
708 policies[0] = orb_->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
709 tmp);
711 ret = obj->_set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
713 policies[0]->destroy ();
715 if (CORBA::is_nil (ret.in ()))
717 if (debug_ > 0)
719 ORBSVCS_DEBUG ((LM_DEBUG,
720 ACE_TEXT ("(%P|%t) ImR: Unable to set timeout policy.\n")));
722 ret = CORBA::Object::_duplicate (obj);
725 catch (const CORBA::Exception& ex)
727 if (debug_ > 0)
729 ex._tao_print_exception (ACE_TEXT ("(%P|%t) ImR_Locator_i::set_timeout_policy ()"));
733 return ret._retn ();
736 void
737 ImR_Locator_i::add_or_update_server
738 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
739 const char* server,
740 const ImplementationRepository::StartupOptions &options)
742 if (this->opts_->readonly ())
744 ORBSVCS_DEBUG ((LM_DEBUG,
745 ACE_TEXT ("(%P|%t) ImR: Cannot add/update server <%C> due to locked ")
746 ACE_TEXT ("database.\n"),
747 server));
748 CORBA::Exception *ex =
749 new CORBA::NO_PERMISSION (CORBA::SystemException::_tao_minor_code
750 (TAO_IMPLREPO_MINOR_CODE,0),
751 CORBA::COMPLETED_NO);
752 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
753 _tao_rh->add_or_update_server_excep (&h);
754 return;
757 if (debug_ > 0)
758 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Add/Update server <%C>\n"), server));
760 UpdateableServerInfo info(this->repository_, server);
761 if (info.null ())
763 if (debug_ > 1)
764 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Adding server <%C>\n"), server));
766 this->repository_->add_server (server, options);
768 else
770 if (debug_ > 1)
771 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Updating server <%C>\n"),
772 server));
774 info.edit ()->update_options (options);
775 info.update_repo();
778 if (debug_ > 1)
780 // Note : The info var may be null, so we use options.
781 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Server: <%C>\n")
782 ACE_TEXT ("\tActivator: <%C>\n")
783 ACE_TEXT ("\tCommand Line: <%C>\n")
784 ACE_TEXT ("\tWorking Directory: <%C>\n")
785 ACE_TEXT ("\tActivation: <%C>\n")
786 ACE_TEXT ("\tStart Limit: <%d>\n"),
787 server,
788 options.activator.in (),
789 options.command_line.in (),
790 options.working_directory.in (),
791 ImR_Utils::activationModeToString (options.activation),
792 options.start_limit
795 for (CORBA::ULong i = 0; i < options.environment.length (); ++i)
796 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("Environment variable <%C>=<%C>\n"),
797 options.environment[i].name.in (),
798 options.environment[i].value.in ()));
801 _tao_rh->add_or_update_server ();
804 void
805 ImR_Locator_i::link_servers
806 (ImplementationRepository::AMH_AdministrationExtResponseHandler_ptr _tao_rh,
807 const char * name,
808 const CORBA::StringSeq & peers)
810 Server_Info_Ptr root_si = this->repository_->get_active_server (name);
811 if (root_si.null())
813 CORBA::Exception *ex =
814 new ImplementationRepository::NotFound;
815 ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
816 _tao_rh->link_servers_excep (&h);
817 return;
819 else if (!root_si->alt_info_.null())
821 ACE_CString errstr = name;
822 errstr += " is not a base POA";
823 CORBA::Exception *ex =
824 new ImplementationRepository::CannotComplete (errstr.c_str());
825 ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
826 _tao_rh->link_servers_excep (&h);
827 return;
830 for (CORBA::ULong i = 0; i < peers.length(); i++)
832 ACE_CString peer(peers[i]);
833 Server_Info_Ptr si = this->repository_->get_active_server (peer);
834 if (!si.null ())
836 ACE_CString errstr(peers[i]);
837 errstr += " is already registered";
838 CORBA::Exception *ex =
839 new ImplementationRepository::CannotComplete (errstr.c_str());
840 ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
841 _tao_rh->link_servers_excep (&h);
842 return;
846 this->repository_->link_peers (root_si, peers);
848 _tao_rh->link_servers ();
849 return;
852 bool
853 ImR_Locator_i::kill_server_i (const Server_Info_Ptr &si,
854 CORBA::Short signum,
855 CORBA::Exception *& ex)
857 if (si->is_mode(ImplementationRepository::PER_CLIENT))
859 ex = new ImplementationRepository::CannotComplete ("per-client server");
860 return false;
863 Activator_Info_Ptr ainfo = this->get_activator (si->activator);
864 if (ainfo.null ())
866 ex = new ImplementationRepository::CannotComplete ("no activator");
867 return false;
870 ImplementationRepository::ActivatorExt_var actext =
871 ImplementationRepository::ActivatorExt::_narrow (ainfo->activator.in());
873 if (CORBA::is_nil (actext.in()))
875 ex = new ImplementationRepository::CannotComplete ("activator incompatible");
876 return false;
878 return actext->kill_server (si->key_name_.c_str(), si->pid, signum);
881 void
882 ImR_Locator_i::kill_server
883 (ImplementationRepository::AMH_AdministrationExtResponseHandler_ptr _tao_rh,
884 const char * name, CORBA::Short signum)
886 CORBA::Exception *ex = 0;
887 Server_Info_Ptr si;
888 if (!this->get_info_for_name (name, si))
890 ex = new ImplementationRepository::NotFound;
892 else
894 if (!si->alt_info_.null ())
896 si = si->alt_info_;
898 if (!this->kill_server_i (si, signum, ex))
900 if (ex == 0)
902 ex = new ImplementationRepository::CannotComplete ("server not running");
906 if (ex != 0)
908 ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
909 _tao_rh->kill_server_excep (&h);
910 return;
913 _tao_rh->kill_server ();
914 AsyncAccessManager_ptr aam = this->find_aam (si->key_name_.c_str ());
915 if (!aam.is_nil ())
917 aam->shutdown_initiated ();
921 void
922 ImR_Locator_i::remove_server_i (const Server_Info_Ptr &info)
924 if (debug_ > 1)
926 ORBSVCS_DEBUG ((LM_DEBUG,
927 ACE_TEXT ("(%P|%t) ImR: Removing Server <%C>...\n"),
928 info->key_name_.c_str()));
931 ACE_CString poa_name = info->poa_name;
932 if (this->repository_->remove_server (info->key_name_, this) == 0)
934 this->destroy_poa (poa_name);
935 if (debug_ > 0)
937 ORBSVCS_DEBUG ((LM_DEBUG,
938 ACE_TEXT ("(%P|%t) ImR: Removed Server <%C>.\n"),
939 info->key_name_.c_str()));
942 else
944 if (debug_ > 0)
946 ORBSVCS_ERROR ((LM_ERROR,
947 ACE_TEXT ("(%P|%t) ImR: Cannot find server <%C>.\n"),
948 info->key_name_.c_str()));
953 void
954 ImR_Locator_i::remove_server
955 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
956 const char* id)
958 if (this->opts_->readonly ())
960 ORBSVCS_ERROR ((LM_ERROR,
961 ACE_TEXT ("(%P|%t) ImR: Can't remove server <%C> due to locked database.\n"),
962 id));
963 CORBA::Exception *ex =
964 new CORBA::NO_PERMISSION (CORBA::SystemException::_tao_minor_code
965 (TAO_IMPLREPO_MINOR_CODE, 0),
966 CORBA::COMPLETED_NO);
967 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
968 _tao_rh->remove_server_excep (&h);
969 return;
972 Server_Info_Ptr info = this->repository_->get_active_server (id);
973 if (! info.null ())
975 AsyncAccessManager_ptr aam(this->find_aam (info->key_name_.c_str()));
976 if (!aam.is_nil())
978 if (debug_ > 0)
979 ORBSVCS_DEBUG ((LM_DEBUG,
980 ACE_TEXT ("(%P|%t) ImR: Can't remove active server <%C>.\n"),
981 info->key_name_.c_str()));
982 CORBA::Exception *ex =
983 new CORBA::NO_PERMISSION (CORBA::SystemException::_tao_minor_code
984 (TAO_IMPLREPO_MINOR_CODE, EBUSY),
985 CORBA::COMPLETED_NO);
986 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
987 _tao_rh->remove_server_excep (&h);
988 return;
990 this->remove_server_i (info);
992 else
994 ORBSVCS_ERROR ((LM_ERROR,
995 ACE_TEXT ("(%P|%t) ImR: Can't remove unknown server <%C>.\n"), id));
996 CORBA::Exception *ex = new ImplementationRepository::NotFound;
997 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
998 _tao_rh->remove_server_excep (&h);
999 return;
1001 _tao_rh->remove_server ();
1004 void
1005 ImR_Locator_i::force_remove_server
1006 (ImplementationRepository::AMH_AdministrationExtResponseHandler_ptr _tao_rh,
1007 const char *name, CORBA::Short signum)
1009 CORBA::Exception *ex = 0;
1010 Server_Info_Ptr si;
1011 AsyncAccessManager_ptr aam;
1012 if (this->opts_->readonly ())
1014 ORBSVCS_ERROR ((LM_ERROR,
1015 ACE_TEXT ("(%P|%t) ImR: Can't remove server <%C> due to locked database.\n"),
1016 name));
1017 ex =
1018 new CORBA::NO_PERMISSION (CORBA::SystemException::_tao_minor_code
1019 (TAO_IMPLREPO_MINOR_CODE, 0),
1020 CORBA::COMPLETED_NO);
1021 ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
1022 _tao_rh->force_remove_server_excep (&h);
1023 return;
1027 if (!this->get_info_for_name (name, si))
1029 ex = new ImplementationRepository::NotFound;
1030 ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
1031 _tao_rh->force_remove_server_excep (&h);
1032 return;
1035 if (!si->alt_info_.null ())
1037 si = si->alt_info_;
1039 aam = this->find_aam (si->key_name_.c_str ());
1040 if (aam.is_nil ())
1042 this->remove_server_i (si);
1043 _tao_rh->force_remove_server ();
1044 return;
1047 ImR_ResponseHandler *aam_rh =
1048 new ImR_Loc_ResponseHandler (ImR_Loc_ResponseHandler::LOC_FORCE_REMOVE_SERVER,
1049 _tao_rh);
1050 if (aam->force_remove_rh (aam_rh))
1052 delete aam_rh;
1053 _tao_rh->force_remove_server ();
1054 return;
1057 bool active = (signum > 0) ?
1058 this->kill_server_i (si, signum, ex) :
1059 this->shutdown_server_i (si, ex, true);
1061 if (ex != 0)
1063 ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
1064 _tao_rh->force_remove_server_excep (&h);
1065 aam->force_remove_rh (0);
1066 return;
1068 if (active)
1070 aam->shutdown_initiated ();
1072 else
1074 aam->force_remove_rh (0);
1075 remove_server_i (si);
1076 _tao_rh->force_remove_server ();
1080 void
1081 ImR_Locator_i::destroy_poa (const ACE_CString &poa_name)
1083 PortableServer::POA_var poa = findPOA (poa_name.c_str());
1084 if (! CORBA::is_nil (poa.in ()))
1086 bool etherealize = true;
1087 bool wait = false;
1088 poa->destroy (etherealize, wait);
1093 PortableServer::POA_ptr
1094 ImR_Locator_i::findPOA (const char* name)
1098 bool activate_it = false;
1099 return root_poa_->find_POA (name, activate_it);
1101 catch (const CORBA::Exception&)
1102 {// Ignore
1104 return PortableServer::POA::_nil ();
1107 bool
1108 ImR_Locator_i::shutdown_server_i (const Server_Info_Ptr &si,
1109 CORBA::Exception *&ex_ret,
1110 bool force)
1112 const CORBA::ULong TAO_MINOR_MASK = 0x00000f80;
1113 const char *id = si->key_name_.c_str();
1114 if (debug_ > 0)
1115 ORBSVCS_DEBUG ((LM_DEBUG,
1116 ACE_TEXT ("(%P|%t) ImR: Shutting down server <%C>.\n"),
1117 id));
1119 UpdateableServerInfo info (this->repository_, si);
1120 if (info.null ())
1122 ORBSVCS_ERROR ((LM_ERROR,
1123 ACE_TEXT ("(%P|%t) ImR: shutdown_server () ")
1124 ACE_TEXT ("Cannot find info for server <%C>\n"),
1125 id));
1126 ex_ret = new ImplementationRepository::NotFound;
1127 return false;
1130 this->connect_server (info);
1132 if (CORBA::is_nil (info->active_info()->server.in ()))
1134 ORBSVCS_ERROR ((LM_ERROR,
1135 ACE_TEXT ("(%P|%t) ImR: shutdown_server ()")
1136 ACE_TEXT (" Cannot connect to server <%C>\n"),
1137 id));
1138 ex_ret = new ImplementationRepository::NotFound;
1139 return false;
1144 CORBA::Object_var obj = this->set_timeout_policy (info->active_info()->server.in (),
1145 DEFAULT_SHUTDOWN_TIMEOUT);
1146 ImplementationRepository::ServerObject_var server =
1147 ImplementationRepository::ServerObject::_unchecked_narrow (obj.in ());
1148 if (CORBA::is_nil(server.in ()))
1150 if (debug_ > 1)
1152 ORBSVCS_DEBUG ((LM_DEBUG,
1153 ACE_TEXT ("(%P|%t) ImR: ServerObject reference with timeout is nil.\n")));
1154 return false;
1157 else
1159 server->shutdown ();
1160 return true;
1163 catch (const CORBA::TIMEOUT &ex)
1165 info.edit ()->reset_runtime ();
1166 // Note : This is a good thing. It means we didn't waste our time waiting for
1167 // the server to finish shutting down.
1168 if (debug_ > 1)
1170 ORBSVCS_DEBUG ((LM_DEBUG,
1171 ACE_TEXT ("(%P|%t) ImR: Timeout while waiting for <%C> shutdown.\n"),
1172 id));
1174 if (!force && this->opts_->throw_shutdown_exceptions ())
1176 ex_ret = ex._tao_duplicate();
1179 catch (const CORBA::COMM_FAILURE& ex)
1181 info.edit ()->reset_runtime ();
1182 if (debug_ > 1)
1184 ORBSVCS_DEBUG ((LM_DEBUG,
1185 ACE_TEXT ("ImR: COMM_FAILURE while waiting for <%C> shutdown.\n"),
1186 id));
1188 if (!force && this->opts_->throw_shutdown_exceptions ())
1190 ex_ret = ex._tao_duplicate();
1193 catch (const CORBA::TRANSIENT& ex)
1195 CORBA::ULong const minor = ex.minor () & TAO_MINOR_MASK;
1196 if (minor != TAO_POA_DISCARDING && minor != TAO_POA_HOLDING)
1198 info.edit ()->reset_runtime ();
1200 if (debug_ > 1)
1202 ORBSVCS_DEBUG ((LM_DEBUG,
1203 ACE_TEXT ("ImR: TRANSIENT while waiting for <%C> shutdown.\n"),
1204 id));
1206 if (!force && this->opts_->throw_shutdown_exceptions ())
1208 ex_ret = ex._tao_duplicate();
1211 catch (const CORBA::Exception &ex)
1213 if (debug_ > 1)
1215 ORBSVCS_DEBUG ((LM_DEBUG,
1216 ACE_TEXT ("(%P|%t) ImR: Exception while shutting down <%C>\n"),
1217 id));
1219 if (!force && this->opts_->throw_shutdown_exceptions ())
1221 ex_ret = ex._tao_duplicate();
1224 return false;
1227 void
1228 ImR_Locator_i::shutdown_server
1229 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
1230 const char* name)
1232 CORBA::Exception *ex = 0;
1233 Server_Info_Ptr si;
1235 if (!this->get_info_for_name (name, si))
1237 ex = new ImplementationRepository::NotFound;
1238 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
1239 _tao_rh->shutdown_server_excep (&h);
1240 return;
1243 if (this->shutdown_server_i (si, ex, false))
1245 AsyncAccessManager_ptr aam = this->find_aam (si->ping_id ());
1246 if (!aam.is_nil())
1248 aam->shutdown_initiated ();
1251 if (ex != 0)
1253 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
1254 _tao_rh->shutdown_server_excep (&h);
1256 else
1258 _tao_rh->shutdown_server ();
1262 void
1263 ImR_Locator_i::server_is_running
1264 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
1265 const char* id,
1266 const char* partial_ior,
1267 ImplementationRepository::ServerObject_ptr server_object)
1269 if (debug_ > 0)
1271 ORBSVCS_DEBUG ((LM_DEBUG,
1272 ACE_TEXT ("(%P|%t) ImR: Server <%C> is running at <%C>\n"),
1273 id, partial_ior));
1275 CORBA::String_var sior = orb_->object_to_string (server_object);
1277 if (debug_ > 1)
1279 ORBSVCS_DEBUG ((LM_DEBUG,
1280 ACE_TEXT ("(%P|%t) ImR: Server <%C> callback at <%C>\n"),
1281 id, sior.in ()));
1284 if (this->opts_->unregister_if_address_reused ())
1285 this->repository_->unregister_if_address_reused (id, partial_ior, this);
1287 CORBA::Object_var obj = this->set_timeout_policy (server_object, this->opts_->ping_timeout ());
1288 ImplementationRepository::ServerObject_var srvobj =
1289 ImplementationRepository::ServerObject::_narrow (obj.in());
1291 UpdateableServerInfo info (this->repository_, id);
1292 if (info.null ())
1294 if (debug_ > 0)
1296 ORBSVCS_DEBUG ((LM_DEBUG,
1297 ACE_TEXT ("(%P|%t) ImR: Auto adding NORMAL server <%C>\n"),
1298 id));
1301 Server_Info_Ptr si;
1302 if (this->repository_->add_server (id, partial_ior, sior.in (), srvobj.in ()) == 0)
1304 si = this->repository_->get_active_server (id);
1307 if (si.null ())
1309 if (debug_ > 0)
1311 ORBSVCS_DEBUG ((LM_DEBUG,
1312 ACE_TEXT ("(%P|%t) ImR: Auto adding failed, giving up <%C>\n"),
1313 id));
1315 CORBA::NO_MEMORY ex;
1316 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
1317 _tao_rh->server_is_running_excep (&h);
1318 return;
1320 info.server_info (si);
1321 this->pinger_.add_server (si->ping_id (), this->opts_->ping_external (), srvobj.in(), info->active_info ()->pid);
1323 ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
1324 AsyncAccessManager_ptr aam (this->create_aam (info, true));
1326 else
1328 if (ImR_Locator_i::debug () > 4)
1330 ORBSVCS_DEBUG ((LM_DEBUG,
1331 ACE_TEXT ("(%P|%t) ImR_Locator_i::server_is_running <%C> has mode <%C>\n"),
1332 id, ImR_Utils::activationModeToString(info->mode ())));
1335 AsyncAccessManager_ptr aam;
1336 if (!info->is_mode(ImplementationRepository::PER_CLIENT))
1338 info.edit ()->set_contact (partial_ior, sior.in(), srvobj.in());
1340 info.update_repo();
1341 // Add the server to our pinger list
1342 this->pinger_.add_server (info->ping_id(), true, srvobj.in(), info->pid);
1344 aam = this->find_aam (info->ping_id ());
1346 else
1348 // In case of a per client activation there could be multiple AAM for a specific server (ping_id)
1349 // we need to make sure we take an AAM that is not running yet
1350 aam = this->find_not_running_aam (info->ping_id ());
1353 if (!aam.is_nil())
1355 if (ImR_Locator_i::debug () > 4)
1357 ORBSVCS_DEBUG ((LM_DEBUG,
1358 ACE_TEXT ("(%P|%t) ImR_Locator_i::server_is_running <%C> aam is not nil\n"),
1359 id));
1361 aam->server_is_running (partial_ior, srvobj.in());
1363 else
1365 if (ImR_Locator_i::debug () > 4)
1367 ORBSVCS_DEBUG ((LM_DEBUG,
1368 ACE_TEXT ("(%P|%t) ImR_Locator_i::server_is_running <%C> aam is nil\n"),
1369 id));
1371 if (!info->is_mode(ImplementationRepository::PER_CLIENT))
1373 ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
1374 aam = this->create_aam (info, true);
1378 _tao_rh->server_is_running ();
1381 void
1382 ImR_Locator_i::server_is_shutting_down
1383 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
1384 const char* fqname)
1386 UpdateableServerInfo info (this->repository_, fqname);
1387 if (info.null ())
1389 if (debug_ > 1)
1391 ORBSVCS_DEBUG ((LM_DEBUG,
1392 ACE_TEXT ("(%P|%t) ImR_Locator_i::server_is_shutting_down: ")
1393 ACE_TEXT ("Unknown server <%C>\n"),
1394 fqname));
1396 _tao_rh->server_is_shutting_down ();
1397 return;
1400 if (debug_ > 0)
1402 ORBSVCS_DEBUG ((LM_DEBUG,
1403 ACE_TEXT ("(%P|%t) ImR: Server <%C> is shutting down\n"),
1404 fqname));
1407 if (!info->is_mode(ImplementationRepository::PER_CLIENT))
1409 this->pinger_.remove_server (info->ping_id(), info->pid);
1411 AsyncAccessManager_ptr aam = this->find_aam (info->ping_id (), false);
1412 if (aam.is_nil())
1414 aam = this->find_aam(info->ping_id(), true);
1416 if (!aam.is_nil())
1418 aam->server_is_shutting_down ();
1422 info.edit ()->reset_runtime ();
1423 _tao_rh->server_is_shutting_down ();
1426 void
1427 ImR_Locator_i::find
1428 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
1429 const char* id)
1431 Server_Info_Ptr si = this->repository_->get_active_server (id);
1432 ImplementationRepository::ServerInformation_var imr_info;
1435 if (! si.null ())
1437 imr_info = si->createImRServerInfo ();
1439 if (debug_ > 1)
1440 ORBSVCS_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) ImR: Found server <%C>\n"), id));
1442 else
1444 ACE_NEW_THROW_EX (imr_info,
1445 ImplementationRepository::ServerInformation,
1446 CORBA::NO_MEMORY ());
1447 imr_info->startup.activation= ImplementationRepository::NORMAL;
1448 if (debug_ > 1)
1449 ORBSVCS_DEBUG ((LM_DEBUG,
1450 ACE_TEXT ("(%P|%t) ImR: Cannot find server <%C>\n"),
1451 id));
1454 catch (const CORBA::Exception &ex)
1456 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
1457 _tao_rh->find_excep (&h);
1458 return;
1460 _tao_rh->find (imr_info.in());
1463 void
1464 ImR_Locator_i::list
1465 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh,
1466 CORBA::ULong how_many,
1467 CORBA::Boolean active)
1469 AsyncListManager *l = 0;
1472 ACE_NEW_THROW_EX (l,
1473 AsyncListManager (this->repository_.get(),
1474 this->root_poa_.in(),
1475 active ? &this->pinger_ : 0),
1476 CORBA::NO_MEMORY ());
1477 AsyncListManager_ptr lister (l);
1478 l->list (_tao_rh, how_many);
1480 catch (const CORBA::Exception &ex)
1482 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex._tao_duplicate());
1483 _tao_rh->find_excep (&h);
1484 return;
1488 Activator_Info_Ptr
1489 ImR_Locator_i::get_activator (const ACE_CString& aname)
1491 Activator_Info_Ptr info = this->repository_->get_activator (aname);
1492 if (! info.null ())
1494 this->connect_activator (*info);
1496 return info;
1499 void
1500 ImR_Locator_i::connect_activator (Activator_Info& info)
1502 if (! CORBA::is_nil (info.activator.in ()) || info.ior.length () == 0)
1503 return;
1507 CORBA::Object_var obj =
1508 this->orb_->string_to_object (info.ior.c_str ());
1510 if (CORBA::is_nil (obj.in ()))
1512 info.reset_runtime ();
1513 return;
1516 if (this->opts_->startup_timeout () > ACE_Time_Value::zero)
1518 obj = this->set_timeout_policy (obj.in (), this->opts_->startup_timeout ());
1521 info.activator =
1522 ImplementationRepository::Activator::_unchecked_narrow (obj.in ());
1524 if (CORBA::is_nil (info.activator.in ()))
1526 info.reset_runtime ();
1527 return;
1530 if (debug_ > 1)
1531 ORBSVCS_DEBUG ((LM_DEBUG,
1532 ACE_TEXT ("(%P|%t) ImR: Connected to activator <%C>\n"),
1533 info.name.c_str ()));
1535 catch (const CORBA::Exception& )
1537 info.reset_runtime ();
1541 void
1542 ImR_Locator_i::auto_start_servers ()
1544 if (this->repository_->servers ().current_size () == 0)
1545 return;
1547 Locator_Repository::SIMap::ENTRY* server_entry;
1548 Locator_Repository::SIMap::ITERATOR server_iter (this->repository_->servers ());
1550 // For each of the entries in the Locator_Repository, get the startup
1551 // information and activate the servers, if they are not already
1552 // running.
1553 for (;server_iter.next (server_entry) != 0; server_iter.advance ())
1555 UpdateableServerInfo info(this->repository_, server_entry->int_id_);
1556 ACE_ASSERT (! info.null ());
1560 if (info->is_mode (ImplementationRepository::AUTO_START)
1561 && info->active_info()->cmdline.length () > 0)
1563 ImR_ResponseHandler rh;
1564 this->activate_server_i (info, true, &rh);
1567 catch (const CORBA::Exception& ex)
1569 if (debug_ > 1)
1571 ORBSVCS_DEBUG ((LM_DEBUG,
1572 ACE_TEXT ("(%P|%t) ImR: AUTO_START Could not activate <%C>\n"),
1573 server_entry->ext_id_.c_str ()));
1574 ex._tao_print_exception ("AUTO_START");
1576 // Ignore exceptions
1581 void
1582 ImR_Locator_i::connect_server (UpdateableServerInfo& info)
1584 Server_Info *sip = info.edit ()->active_info ();
1585 if (! CORBA::is_nil (sip->server.in ()))
1587 if (!this->pinger_.has_server (sip->key_name_.c_str()))
1589 this->pinger_.add_server (sip->key_name_.c_str(),
1590 this->opts_->ping_external (),
1591 sip->server.in(),
1592 sip->pid);
1594 return; // already connected
1597 if (sip->ior.length () == 0)
1599 sip->reset_runtime ();
1600 return; // can't connect
1605 CORBA::Object_var obj = orb_->string_to_object (sip->ior.c_str ());
1607 if (CORBA::is_nil (obj.in ()))
1609 sip->reset_runtime ();
1610 return;
1613 obj = this->set_timeout_policy (obj.in (), this->opts_->ping_timeout ());
1615 sip->server =
1616 ImplementationRepository::ServerObject::_unchecked_narrow (obj.in ());
1618 if (CORBA::is_nil (sip->server.in ()))
1620 sip->reset_runtime ();
1621 return;
1624 if (debug_ > 1)
1625 ORBSVCS_DEBUG ((LM_DEBUG,
1626 ACE_TEXT ("(%P|%t) ImR: Connected to server <%C>\n"),
1627 sip->key_name_.c_str ()));
1628 this->pinger_.add_server (sip->key_name_.c_str(),
1629 this->opts_->ping_external (),
1630 sip->server.in(),
1631 sip->pid);
1633 catch (const CORBA::Exception& )
1635 sip->reset_runtime ();
1639 bool
1640 ImR_Locator_i::server_is_alive (UpdateableServerInfo& info)
1642 this->connect_server (info);
1643 SyncListener *listener = 0;
1644 ACE_NEW_RETURN (listener,
1645 SyncListener (info->ping_id(),
1646 this->orb_.in(),
1647 this->pinger_),
1648 false);
1649 LiveListener_ptr llp(listener);
1650 return listener->is_alive();
1654 ImR_Locator_i::debug ()
1656 return debug_;
1659 LiveCheck&
1660 ImR_Locator_i::pinger ()
1662 return this->pinger_;
1665 PortableServer::POA_ptr
1666 ImR_Locator_i::root_poa ()
1668 return PortableServer::POA::_duplicate (this->root_poa_.in());
1671 void
1672 ImR_Locator_i::remove_aam (AsyncAccessManager_ptr &aam)
1674 if (this->aam_terminating_.remove (aam) == -1)
1676 this->aam_active_.remove (aam);
1680 void
1681 ImR_Locator_i::remove_aam_i (const char *name, bool active)
1683 AAM_Set &set = active ? this->aam_active_ : this->aam_terminating_;
1685 for (AAM_Set::ITERATOR i = set.begin(); i != set.end(); ++i)
1687 if ((*i)->has_server (name))
1689 ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);
1690 set.remove (*i);
1691 return;
1696 void
1697 ImR_Locator_i::remove_aam (const char *name)
1699 this->remove_aam_i (name,true);
1700 this->remove_aam_i (name,false);
1703 void
1704 ImR_Locator_i::make_terminating (AsyncAccessManager_ptr &aam,
1705 const char *name, int pid)
1707 this->aam_active_.remove (aam);
1708 this->aam_terminating_.insert_tail (aam);
1709 this->pinger_.remove_server (name, pid);
1712 AsyncAccessManager *
1713 ImR_Locator_i::find_aam (const char *name, bool active)
1715 AAM_Set &set = active ? this->aam_active_ : this->aam_terminating_;
1716 for (AAM_Set::ITERATOR i = set.begin(); i != set.end(); ++i)
1718 if ((*i)->has_server (name))
1720 return (*i)->_add_ref();
1723 return 0;
1726 AsyncAccessManager *
1727 ImR_Locator_i::find_not_running_aam (const char *name, bool active)
1729 AAM_Set &set = active ? this->aam_active_ : this->aam_terminating_;
1730 for (AAM_Set::ITERATOR i = set.begin(); i != set.end(); ++i)
1732 if ((*i)->has_server (name) && (!(*i)->is_running ()))
1734 return (*i)->_add_ref();
1737 return 0;
1740 AsyncAccessManager *
1741 ImR_Locator_i::create_aam (UpdateableServerInfo &info, bool running)
1743 AsyncAccessManager_ptr aam;
1744 ACE_NEW_RETURN (aam, AsyncAccessManager (info, *this), 0);
1745 if (running)
1747 aam->started_running ();
1749 this->aam_active_.insert_tail (aam);
1750 return aam._retn ();
1753 //-------------------------------------------------------------------------
1755 SyncListener::SyncListener (const char *server,
1756 CORBA::ORB_ptr orb,
1757 LiveCheck &pinger)
1758 :LiveListener (server),
1759 orb_ (CORBA::ORB::_duplicate (orb)),
1760 pinger_ (pinger),
1761 status_ (LS_UNKNOWN),
1762 got_it_ (false),
1763 callback_ (false)
1767 SyncListener::~SyncListener ()
1771 bool
1772 SyncListener::is_alive ()
1774 this->callback_ = true;
1775 while (!this->got_it_)
1777 if (this->callback_)
1779 if (!this->pinger_.add_poll_listener (this))
1781 return false;
1784 this->callback_ = false;
1785 ACE_Time_Value delay (10,0);
1786 this->orb_->perform_work (delay);
1788 this->got_it_ = false;
1789 return this->status_ != LS_DEAD;
1792 bool
1793 SyncListener::status_changed (LiveStatus status)
1795 this->callback_ = true;
1796 this->status_ = status;
1797 this->got_it_ = (status != LS_TRANSIENT);
1798 return true;
1801 //---------------------------------------------------------------------------
1803 ImR_SyncResponseHandler::ImR_SyncResponseHandler (const char *objkey, CORBA::ORB_ptr orb)
1804 :excep_ (0),
1805 key_ (objkey),
1806 orb_ (CORBA::ORB::_duplicate (orb))
1810 ImR_SyncResponseHandler::~ImR_SyncResponseHandler ()
1814 void
1815 ImR_SyncResponseHandler::send_ior (const char *pior)
1817 ACE_CString full (pior);
1818 full += this->key_;
1819 this->result_ = full.c_str();
1822 void
1823 ImR_SyncResponseHandler::send_exception (CORBA::Exception *ex)
1825 this->excep_ = ex->_tao_duplicate();
1828 char *
1829 ImR_SyncResponseHandler::wait_for_result ()
1831 while (this->result_.in() == 0 && this->excep_ == 0)
1833 this->orb_->perform_work ();
1835 if (this->excep_ != 0)
1837 TAO_AMH_DSI_Exception_Holder h(this->excep_);
1838 h.raise_invoke ();
1840 return this->result_._retn();
1843 //---------------------------------------------------------------------------
1845 ImR_Loc_ResponseHandler::ImR_Loc_ResponseHandler
1846 (Loc_Operation_Id opid,
1847 ImplementationRepository::AMH_AdministrationResponseHandler_ptr rh)
1848 :op_id_ (opid),
1849 resp_ (ImplementationRepository::AMH_AdministrationResponseHandler::_duplicate (rh))
1853 ImR_Loc_ResponseHandler::ImR_Loc_ResponseHandler
1854 (Loc_Operation_Id opid,
1855 ImplementationRepository::AMH_AdministrationExtResponseHandler_ptr rh)
1856 :op_id_ (opid),
1857 ext_ (ImplementationRepository::AMH_AdministrationExtResponseHandler::_duplicate (rh))
1861 ImR_Loc_ResponseHandler::~ImR_Loc_ResponseHandler ()
1865 void
1866 ImR_Loc_ResponseHandler::send_ior (const char *)
1868 if (CORBA::is_nil (this->resp_))
1870 this->send_ior_ext ("");
1871 return;
1873 switch (this->op_id_)
1875 case LOC_ACTIVATE_SERVER:
1876 resp_->activate_server ();
1877 break;
1878 case LOC_ADD_OR_UPDATE_SERVER:
1879 resp_->add_or_update_server ();
1880 break;
1881 case LOC_REMOVE_SERVER:
1882 resp_->remove_server ();
1883 break;
1884 case LOC_SHUTDOWN_SERVER:
1885 resp_->shutdown_server ();
1886 break;
1887 case LOC_SERVER_IS_RUNNING:
1888 resp_->server_is_running ();
1889 break;
1890 case LOC_SERVER_IS_SHUTTING_DOWN:
1891 resp_->server_is_shutting_down ();
1892 break;
1893 default:
1894 break;
1897 delete this;
1900 void
1901 ImR_Loc_ResponseHandler::send_ior_ext (const char *)
1903 switch (this->op_id_)
1905 case LOC_FORCE_REMOVE_SERVER:
1906 ext_->force_remove_server ();
1907 break;
1908 default:
1909 break;
1912 delete this;
1915 void
1916 ImR_Loc_ResponseHandler::send_exception (CORBA::Exception *ex)
1918 if (CORBA::is_nil (this->resp_))
1920 this->send_exception_ext (ex);
1921 return;
1923 ImplementationRepository::AMH_AdministrationExceptionHolder h (ex);
1924 switch (this->op_id_)
1926 case LOC_ACTIVATE_SERVER:
1927 resp_->activate_server_excep (&h);
1928 break;
1929 case LOC_ADD_OR_UPDATE_SERVER:
1930 resp_->add_or_update_server_excep (&h);
1931 break;
1932 case LOC_REMOVE_SERVER:
1933 resp_->remove_server_excep (&h);
1934 break;
1935 case LOC_SHUTDOWN_SERVER:
1936 resp_->shutdown_server_excep (&h);
1937 break;
1938 case LOC_SERVER_IS_RUNNING:
1939 resp_->server_is_running_excep (&h);
1940 break;
1941 case LOC_SERVER_IS_SHUTTING_DOWN:
1942 resp_->server_is_shutting_down_excep (&h);
1943 break;
1944 default:
1945 break;
1947 delete this;
1949 void
1950 ImR_Loc_ResponseHandler::send_exception_ext (CORBA::Exception *ex)
1952 ImplementationRepository::AMH_AdministrationExtExceptionHolder h (ex);
1953 switch (this->op_id_)
1955 case LOC_FORCE_REMOVE_SERVER:
1956 ext_->force_remove_server_excep (&h);
1957 break;
1958 default:
1959 break;
1961 delete this;