1 #include "orbsvcs/Log_Macros.h"
2 #include "ImR_Locator_i.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"
20 #include "ace/OS_NS_sys_time.h"
21 #include "ace/Vector_T.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
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
;
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
);
53 int ImR_Locator_i::debug_
= 0;
55 ImR_Locator_i::ImR_Locator_i ()
56 : dsi_forwarder_ (*this)
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
68 ACE_NEW (locator
, INS_Locator (*this));
69 ins_locator_
= locator
;
72 ImR_Locator_i::~ImR_Locator_i ()
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
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 (),
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
));
119 case Options::REPO_HEAP_FILE
:
121 repository_
.reset(new Heap_Backing_Store(*this->opts_
, orb
));
124 case Options::REPO_XML_FILE
:
126 repository_
.reset(new XML_Backing_Store(*this->opts_
, orb
));
129 case Options::REPO_SHARED_FILES
:
131 repository_
.reset(new Shared_Backing_Store(*this->opts_
, orb
, this));
134 case Options::REPO_NONE
:
136 repository_
.reset(new No_Backing_Store(*this->opts_
, orb
));
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 (),
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
));
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
186 this->pinger_
.remove_server (active
->ping_id(), 0);
187 info
.edit()->reset_runtime ();
188 active
->reset_runtime ();
192 active
->death_notify
= false;
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
)
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 ());
240 ImR_Locator_i::run ()
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"),
266 (this->opts_
->readonly () ? "True" : "False")));
268 this->auto_start_servers ();
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
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
)
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);
343 ImR_Locator_i::signal_shutdown ()
345 this->orb_
->orb_core ()->reactor ()->notify (&this->shutdown_handler_
);
349 ImR_Locator_i::shutdown (bool wait_for_completion
)
351 this->repository_
->shutdown ();
352 this->orb_
->shutdown (wait_for_completion
);
356 ImR_Locator_i::opts () const
362 ImR_Locator_i::fini ()
367 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Shutting down...\n")));
369 this->root_poa_
->destroy (1, 1);
371 this->orb_
->destroy ();
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"));
385 ImR_Locator_i::register_activator
386 (ImplementationRepository::AMH_LocatorResponseHandler_ptr _tao_rh
,
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
);
407 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Activator registered for %C.\n"),
410 _tao_rh
->register_activator (token
);
414 ImR_Locator_i::unregister_activator
415 (ImplementationRepository::AMH_LocatorResponseHandler_ptr _tao_rh
,
419 ACE_ASSERT (aname
!= 0);
420 Activator_Info_Ptr info
= this->get_activator (aname
);
424 if (info
->token
!= token
&& debug_
> 0)
428 ACE_TEXT ("(%P|%t) ImR: Ignoring unregister activator:%C. Wrong token.\n"),
430 _tao_rh
->unregister_activator ();
434 this->unregister_activator_i (aname
);
437 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Activator %C unregistered.\n"),
445 ACE_TEXT ("(%P|%t) ImR: Ignoring unregister activator: %C. ")
446 ACE_TEXT ("Unknown activator.\n"),
449 _tao_rh
->unregister_activator ();
453 ImR_Locator_i::unregister_activator_i (const char* aname
)
455 int err
= this->repository_
->remove_activator (aname
);
456 ACE_UNUSED_ARG (err
);
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
));
467 UpdateableServerInfo
info (this->repository_
, name
);
471 ORBSVCS_DEBUG ((LM_DEBUG
,
472 ACE_TEXT ("(%P|%t) ImR: remote_acccess")
473 ACE_TEXT (" <%C> unregistered.\n"),
477 aam
= this->create_aam (info
);
479 /* mon.release (); */
480 aam
->remote_state (state
);
484 ImR_Locator_i::child_death_i (const char* name
, int pid
)
488 ORBSVCS_DEBUG ((LM_DEBUG
,
489 ACE_TEXT ("(%P|%t) ImR: Server <%C> has died with pid <%d>\n"),
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
);
504 info
.edit ()->reset_runtime ();
510 ORBSVCS_ERROR ((LM_ERROR
,
511 ACE_TEXT ("(%P|%t) ImR: Failed to find server/pid in repository.\n")));
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 ();
526 ImR_Locator_i::spawn_pid
527 (ImplementationRepository::AMH_LocatorResponseHandler_ptr _tao_rh
,
528 const char* name
, CORBA::Long pid
)
532 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Server <%C> spawned with pid <%d>.\n"),
536 UpdateableServerInfo
info(this->repository_
, name
);
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));
549 aam
= this->find_aam (name
, false);
553 aam
->update_prev_pid ();
555 info
.edit ()->active_info ()->pid
= pid
;
556 info
.edit ()->active_info ()->death_notify
= true;
562 ORBSVCS_ERROR ((LM_ERROR
,
563 ACE_TEXT ("(%P|%t) ImR: Failed to find server <%C> in repository\n"),
567 this->pinger_
.set_pid (name
, pid
);
569 _tao_rh
->spawn_pid ();
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 ();
581 ImR_Locator_i::activate_server_by_object (const char* object_name
)
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();
596 ImR_Locator_i::activate_server
597 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh
,
602 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Manually activating server <%C>\n"),
606 ImR_ResponseHandler
*rh
= 0;
608 ImR_Loc_ResponseHandler (ImR_Loc_ResponseHandler::LOC_ACTIVATE_SERVER
,
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
);
617 ImR_Locator_i::get_info_for_name (const char* name
, Server_Info_Ptr
&si
)
619 si
= this->repository_
->get_active_server (name
);
624 ImR_Locator_i::split_key (ACE_CString
&full
, ACE_CString
&key
, Server_Info_Ptr
&si
)
627 if (this->get_info_for_name (full
.c_str(), si
))
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
))
640 pos
= server
.rfind ('/');
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
);
655 rh
->send_exception ( new ImplementationRepository::NotFound
);
659 this->activate_server_i (info
, manual_start
, rh
);
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
);
672 ImR_Locator_i::activate_server_i (UpdateableServerInfo
& info
,
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
);
684 aam
= this->find_aam (info
->ping_id ());
687 ACE_GUARD (TAO_SYNCH_MUTEX
, mon
, this->lock_
);
688 aam
= this->create_aam (info
);
691 aam
->add_interest (rh
, manual_start
);
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
);
706 CORBA::PolicyList
policies (1);
708 policies
[0] = orb_
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
711 ret
= obj
->_set_policy_overrides (policies
, CORBA::ADD_OVERRIDE
);
713 policies
[0]->destroy ();
715 if (CORBA::is_nil (ret
.in ()))
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
)
729 ex
._tao_print_exception (ACE_TEXT ("(%P|%t) ImR_Locator_i::set_timeout_policy ()"));
737 ImR_Locator_i::add_or_update_server
738 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh
,
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"),
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
);
758 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Add/Update server <%C>\n"), server
));
760 UpdateableServerInfo
info(this->repository_
, server
);
764 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Adding server <%C>\n"), server
));
766 this->repository_
->add_server (server
, options
);
771 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Updating server <%C>\n"),
774 info
.edit ()->update_options (options
);
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"),
788 options
.activator
.in (),
789 options
.command_line
.in (),
790 options
.working_directory
.in (),
791 ImR_Utils::activationModeToString (options
.activation
),
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 ();
805 ImR_Locator_i::link_servers
806 (ImplementationRepository::AMH_AdministrationExtResponseHandler_ptr _tao_rh
,
808 const CORBA::StringSeq
& peers
)
810 Server_Info_Ptr root_si
= this->repository_
->get_active_server (name
);
813 CORBA::Exception
*ex
=
814 new ImplementationRepository::NotFound
;
815 ImplementationRepository::AMH_AdministrationExtExceptionHolder
h (ex
);
816 _tao_rh
->link_servers_excep (&h
);
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
);
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
);
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
);
846 this->repository_
->link_peers (root_si
, peers
);
848 _tao_rh
->link_servers ();
853 ImR_Locator_i::kill_server_i (const Server_Info_Ptr
&si
,
855 CORBA::Exception
*& ex
)
857 if (si
->is_mode(ImplementationRepository::PER_CLIENT
))
859 ex
= new ImplementationRepository::CannotComplete ("per-client server");
863 Activator_Info_Ptr ainfo
= this->get_activator (si
->activator
);
866 ex
= new ImplementationRepository::CannotComplete ("no activator");
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");
878 return actext
->kill_server (si
->key_name_
.c_str(), si
->pid
, signum
);
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;
888 if (!this->get_info_for_name (name
, si
))
890 ex
= new ImplementationRepository::NotFound
;
894 if (!si
->alt_info_
.null ())
898 if (!this->kill_server_i (si
, signum
, ex
))
902 ex
= new ImplementationRepository::CannotComplete ("server not running");
908 ImplementationRepository::AMH_AdministrationExtExceptionHolder
h (ex
);
909 _tao_rh
->kill_server_excep (&h
);
913 _tao_rh
->kill_server ();
914 AsyncAccessManager_ptr aam
= this->find_aam (si
->key_name_
.c_str ());
917 aam
->shutdown_initiated ();
922 ImR_Locator_i::remove_server_i (const Server_Info_Ptr
&info
)
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
);
937 ORBSVCS_DEBUG ((LM_DEBUG
,
938 ACE_TEXT ("(%P|%t) ImR: Removed Server <%C>.\n"),
939 info
->key_name_
.c_str()));
946 ORBSVCS_ERROR ((LM_ERROR
,
947 ACE_TEXT ("(%P|%t) ImR: Cannot find server <%C>.\n"),
948 info
->key_name_
.c_str()));
954 ImR_Locator_i::remove_server
955 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh
,
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"),
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
);
972 Server_Info_Ptr info
= this->repository_
->get_active_server (id
);
975 AsyncAccessManager_ptr
aam(this->find_aam (info
->key_name_
.c_str()));
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
);
990 this->remove_server_i (info
);
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
);
1001 _tao_rh
->remove_server ();
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;
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"),
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
);
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
);
1035 if (!si
->alt_info_
.null ())
1039 aam
= this->find_aam (si
->key_name_
.c_str ());
1042 this->remove_server_i (si
);
1043 _tao_rh
->force_remove_server ();
1047 ImR_ResponseHandler
*aam_rh
=
1048 new ImR_Loc_ResponseHandler (ImR_Loc_ResponseHandler::LOC_FORCE_REMOVE_SERVER
,
1050 if (aam
->force_remove_rh (aam_rh
))
1053 _tao_rh
->force_remove_server ();
1057 bool active
= (signum
> 0) ?
1058 this->kill_server_i (si
, signum
, ex
) :
1059 this->shutdown_server_i (si
, ex
, true);
1063 ImplementationRepository::AMH_AdministrationExtExceptionHolder
h (ex
);
1064 _tao_rh
->force_remove_server_excep (&h
);
1065 aam
->force_remove_rh (0);
1070 aam
->shutdown_initiated ();
1074 aam
->force_remove_rh (0);
1075 remove_server_i (si
);
1076 _tao_rh
->force_remove_server ();
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;
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
&)
1104 return PortableServer::POA::_nil ();
1108 ImR_Locator_i::shutdown_server_i (const Server_Info_Ptr
&si
,
1109 CORBA::Exception
*&ex_ret
,
1112 const CORBA::ULong TAO_MINOR_MASK
= 0x00000f80;
1113 const char *id
= si
->key_name_
.c_str();
1115 ORBSVCS_DEBUG ((LM_DEBUG
,
1116 ACE_TEXT ("(%P|%t) ImR: Shutting down server <%C>.\n"),
1119 UpdateableServerInfo
info (this->repository_
, si
);
1122 ORBSVCS_ERROR ((LM_ERROR
,
1123 ACE_TEXT ("(%P|%t) ImR: shutdown_server () ")
1124 ACE_TEXT ("Cannot find info for server <%C>\n"),
1126 ex_ret
= new ImplementationRepository::NotFound
;
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"),
1138 ex_ret
= new ImplementationRepository::NotFound
;
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 ()))
1152 ORBSVCS_DEBUG ((LM_DEBUG
,
1153 ACE_TEXT ("(%P|%t) ImR: ServerObject reference with timeout is nil.\n")));
1159 server
->shutdown ();
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.
1170 ORBSVCS_DEBUG ((LM_DEBUG
,
1171 ACE_TEXT ("(%P|%t) ImR: Timeout while waiting for <%C> shutdown.\n"),
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 ();
1184 ORBSVCS_DEBUG ((LM_DEBUG
,
1185 ACE_TEXT ("ImR: COMM_FAILURE while waiting for <%C> shutdown.\n"),
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 ();
1202 ORBSVCS_DEBUG ((LM_DEBUG
,
1203 ACE_TEXT ("ImR: TRANSIENT while waiting for <%C> shutdown.\n"),
1206 if (!force
&& this->opts_
->throw_shutdown_exceptions ())
1208 ex_ret
= ex
._tao_duplicate();
1211 catch (const CORBA::Exception
&ex
)
1215 ORBSVCS_DEBUG ((LM_DEBUG
,
1216 ACE_TEXT ("(%P|%t) ImR: Exception while shutting down <%C>\n"),
1219 if (!force
&& this->opts_
->throw_shutdown_exceptions ())
1221 ex_ret
= ex
._tao_duplicate();
1228 ImR_Locator_i::shutdown_server
1229 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh
,
1232 CORBA::Exception
*ex
= 0;
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
);
1243 if (this->shutdown_server_i (si
, ex
, false))
1245 AsyncAccessManager_ptr aam
= this->find_aam (si
->ping_id ());
1248 aam
->shutdown_initiated ();
1253 ImplementationRepository::AMH_AdministrationExceptionHolder
h (ex
);
1254 _tao_rh
->shutdown_server_excep (&h
);
1258 _tao_rh
->shutdown_server ();
1263 ImR_Locator_i::server_is_running
1264 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh
,
1266 const char* partial_ior
,
1267 ImplementationRepository::ServerObject_ptr server_object
)
1271 ORBSVCS_DEBUG ((LM_DEBUG
,
1272 ACE_TEXT ("(%P|%t) ImR: Server <%C> is running at <%C>\n"),
1275 CORBA::String_var sior
= orb_
->object_to_string (server_object
);
1279 ORBSVCS_DEBUG ((LM_DEBUG
,
1280 ACE_TEXT ("(%P|%t) ImR: Server <%C> callback at <%C>\n"),
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
);
1296 ORBSVCS_DEBUG ((LM_DEBUG
,
1297 ACE_TEXT ("(%P|%t) ImR: Auto adding NORMAL server <%C>\n"),
1302 if (this->repository_
->add_server (id
, partial_ior
, sior
.in (), srvobj
.in ()) == 0)
1304 si
= this->repository_
->get_active_server (id
);
1311 ORBSVCS_DEBUG ((LM_DEBUG
,
1312 ACE_TEXT ("(%P|%t) ImR: Auto adding failed, giving up <%C>\n"),
1315 CORBA::NO_MEMORY ex
;
1316 ImplementationRepository::AMH_AdministrationExceptionHolder
h (ex
._tao_duplicate());
1317 _tao_rh
->server_is_running_excep (&h
);
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));
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());
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 ());
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 ());
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"),
1361 aam
->server_is_running (partial_ior
, srvobj
.in());
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"),
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 ();
1382 ImR_Locator_i::server_is_shutting_down
1383 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh
,
1386 UpdateableServerInfo
info (this->repository_
, fqname
);
1391 ORBSVCS_DEBUG ((LM_DEBUG
,
1392 ACE_TEXT ("(%P|%t) ImR_Locator_i::server_is_shutting_down: ")
1393 ACE_TEXT ("Unknown server <%C>\n"),
1396 _tao_rh
->server_is_shutting_down ();
1402 ORBSVCS_DEBUG ((LM_DEBUG
,
1403 ACE_TEXT ("(%P|%t) ImR: Server <%C> is shutting down\n"),
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);
1414 aam
= this->find_aam(info
->ping_id(), true);
1418 aam
->server_is_shutting_down ();
1422 info
.edit ()->reset_runtime ();
1423 _tao_rh
->server_is_shutting_down ();
1428 (ImplementationRepository::AMH_AdministrationResponseHandler_ptr _tao_rh
,
1431 Server_Info_Ptr si
= this->repository_
->get_active_server (id
);
1432 ImplementationRepository::ServerInformation_var imr_info
;
1437 imr_info
= si
->createImRServerInfo ();
1440 ORBSVCS_DEBUG ((LM_DEBUG
, ACE_TEXT ("(%P|%t) ImR: Found server <%C>\n"), id
));
1444 ACE_NEW_THROW_EX (imr_info
,
1445 ImplementationRepository::ServerInformation
,
1446 CORBA::NO_MEMORY ());
1447 imr_info
->startup
.activation
= ImplementationRepository::NORMAL
;
1449 ORBSVCS_DEBUG ((LM_DEBUG
,
1450 ACE_TEXT ("(%P|%t) ImR: Cannot find server <%C>\n"),
1454 catch (const CORBA::Exception
&ex
)
1456 ImplementationRepository::AMH_AdministrationExceptionHolder
h (ex
._tao_duplicate());
1457 _tao_rh
->find_excep (&h
);
1460 _tao_rh
->find (imr_info
.in());
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
);
1489 ImR_Locator_i::get_activator (const ACE_CString
& aname
)
1491 Activator_Info_Ptr info
= this->repository_
->get_activator (aname
);
1494 this->connect_activator (*info
);
1500 ImR_Locator_i::connect_activator (Activator_Info
& info
)
1502 if (! CORBA::is_nil (info
.activator
.in ()) || info
.ior
.length () == 0)
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 ();
1516 if (this->opts_
->startup_timeout () > ACE_Time_Value::zero
)
1518 obj
= this->set_timeout_policy (obj
.in (), this->opts_
->startup_timeout ());
1522 ImplementationRepository::Activator::_unchecked_narrow (obj
.in ());
1524 if (CORBA::is_nil (info
.activator
.in ()))
1526 info
.reset_runtime ();
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 ();
1542 ImR_Locator_i::auto_start_servers ()
1544 if (this->repository_
->servers ().current_size () == 0)
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
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
)
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
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 (),
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 ();
1613 obj
= this->set_timeout_policy (obj
.in (), this->opts_
->ping_timeout ());
1616 ImplementationRepository::ServerObject::_unchecked_narrow (obj
.in ());
1618 if (CORBA::is_nil (sip
->server
.in ()))
1620 sip
->reset_runtime ();
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 (),
1633 catch (const CORBA::Exception
& )
1635 sip
->reset_runtime ();
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(),
1649 LiveListener_ptr
llp(listener
);
1650 return listener
->is_alive();
1654 ImR_Locator_i::debug ()
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());
1672 ImR_Locator_i::remove_aam (AsyncAccessManager_ptr
&aam
)
1674 if (this->aam_terminating_
.remove (aam
) == -1)
1676 this->aam_active_
.remove (aam
);
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_
);
1697 ImR_Locator_i::remove_aam (const char *name
)
1699 this->remove_aam_i (name
,true);
1700 this->remove_aam_i (name
,false);
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();
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();
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);
1747 aam
->started_running ();
1749 this->aam_active_
.insert_tail (aam
);
1750 return aam
._retn ();
1753 //-------------------------------------------------------------------------
1755 SyncListener::SyncListener (const char *server
,
1758 :LiveListener (server
),
1759 orb_ (CORBA::ORB::_duplicate (orb
)),
1761 status_ (LS_UNKNOWN
),
1767 SyncListener::~SyncListener ()
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))
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
;
1793 SyncListener::status_changed (LiveStatus status
)
1795 this->callback_
= true;
1796 this->status_
= status
;
1797 this->got_it_
= (status
!= LS_TRANSIENT
);
1801 //---------------------------------------------------------------------------
1803 ImR_SyncResponseHandler::ImR_SyncResponseHandler (const char *objkey
, CORBA::ORB_ptr orb
)
1806 orb_ (CORBA::ORB::_duplicate (orb
))
1810 ImR_SyncResponseHandler::~ImR_SyncResponseHandler ()
1815 ImR_SyncResponseHandler::send_ior (const char *pior
)
1817 ACE_CString
full (pior
);
1819 this->result_
= full
.c_str();
1823 ImR_SyncResponseHandler::send_exception (CORBA::Exception
*ex
)
1825 this->excep_
= ex
->_tao_duplicate();
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_
);
1840 return this->result_
._retn();
1843 //---------------------------------------------------------------------------
1845 ImR_Loc_ResponseHandler::ImR_Loc_ResponseHandler
1846 (Loc_Operation_Id opid
,
1847 ImplementationRepository::AMH_AdministrationResponseHandler_ptr rh
)
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
)
1857 ext_ (ImplementationRepository::AMH_AdministrationExtResponseHandler::_duplicate (rh
))
1861 ImR_Loc_ResponseHandler::~ImR_Loc_ResponseHandler ()
1866 ImR_Loc_ResponseHandler::send_ior (const char *)
1868 if (CORBA::is_nil (this->resp_
))
1870 this->send_ior_ext ("");
1873 switch (this->op_id_
)
1875 case LOC_ACTIVATE_SERVER
:
1876 resp_
->activate_server ();
1878 case LOC_ADD_OR_UPDATE_SERVER
:
1879 resp_
->add_or_update_server ();
1881 case LOC_REMOVE_SERVER
:
1882 resp_
->remove_server ();
1884 case LOC_SHUTDOWN_SERVER
:
1885 resp_
->shutdown_server ();
1887 case LOC_SERVER_IS_RUNNING
:
1888 resp_
->server_is_running ();
1890 case LOC_SERVER_IS_SHUTTING_DOWN
:
1891 resp_
->server_is_shutting_down ();
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 ();
1916 ImR_Loc_ResponseHandler::send_exception (CORBA::Exception
*ex
)
1918 if (CORBA::is_nil (this->resp_
))
1920 this->send_exception_ext (ex
);
1923 ImplementationRepository::AMH_AdministrationExceptionHolder
h (ex
);
1924 switch (this->op_id_
)
1926 case LOC_ACTIVATE_SERVER
:
1927 resp_
->activate_server_excep (&h
);
1929 case LOC_ADD_OR_UPDATE_SERVER
:
1930 resp_
->add_or_update_server_excep (&h
);
1932 case LOC_REMOVE_SERVER
:
1933 resp_
->remove_server_excep (&h
);
1935 case LOC_SHUTDOWN_SERVER
:
1936 resp_
->shutdown_server_excep (&h
);
1938 case LOC_SERVER_IS_RUNNING
:
1939 resp_
->server_is_running_excep (&h
);
1941 case LOC_SERVER_IS_SHUTTING_DOWN
:
1942 resp_
->server_is_shutting_down_excep (&h
);
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
);