00001
00002
00003 #include "tao/Thread_Lane_Resources.h"
00004
00005 ACE_RCSID (tao,
00006 Thread_Lane_Resources,
00007 "$Id: Thread_Lane_Resources.cpp 87953 2009-12-07 09:48:57Z mcorino $")
00008
00009 #include "tao/Acceptor_Registry.h"
00010 #include "tao/LF_Follower.h"
00011 #include "tao/Leader_Follower.h"
00012 #include "tao/Connection_Handler.h"
00013 #include "tao/Transport.h"
00014 #include "tao/Connector_Registry.h"
00015 #include "tao/SystemException.h"
00016 #include "tao/ORB_Core.h"
00017 #include "tao/Transport_Descriptor_Interface.h"
00018
00019 #include "ace/Reactor.h"
00020
00021
00022 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00023
00024 TAO_Thread_Lane_Resources::TAO_Thread_Lane_Resources (
00025 TAO_ORB_Core &orb_core,
00026 TAO_New_Leader_Generator *new_leader_generator
00027 )
00028 : orb_core_ (orb_core),
00029 acceptor_registry_ (0),
00030 connector_registry_ (0),
00031 transport_cache_ (0),
00032 leader_follower_ (0),
00033 new_leader_generator_ (new_leader_generator),
00034 input_cdr_dblock_allocator_ (0),
00035 input_cdr_buffer_allocator_ (0),
00036 input_cdr_msgblock_allocator_ (0),
00037 transport_message_buffer_allocator_ (0),
00038 output_cdr_dblock_allocator_ (0),
00039 output_cdr_buffer_allocator_ (0),
00040 output_cdr_msgblock_allocator_ (0),
00041 amh_response_handler_allocator_ (0),
00042 ami_response_handler_allocator_ (0)
00043 {
00044
00045 ACE_NEW (this->transport_cache_,
00046 TAO::Transport_Cache_Manager (
00047 orb_core.resource_factory ()->purge_percentage (),
00048 orb_core.resource_factory ()->create_purging_strategy (),
00049 orb_core.resource_factory ()->cache_maximum (),
00050 orb_core.resource_factory ()->locked_transport_cache (),
00051 orb_core.orbid ()));
00052 }
00053
00054 TAO_Thread_Lane_Resources::~TAO_Thread_Lane_Resources (void)
00055 {
00056 }
00057
00058 TAO::Transport_Cache_Manager &
00059 TAO_Thread_Lane_Resources::transport_cache (void)
00060 {
00061 return *this->transport_cache_;
00062 }
00063
00064 int
00065 TAO_Thread_Lane_Resources::has_acceptor_registry_been_created (void) const
00066 {
00067 return this->acceptor_registry_ != 0;
00068 }
00069
00070 int
00071 TAO_Thread_Lane_Resources::is_collocated (const TAO_MProfile& mprofile)
00072 {
00073 if (!this->has_acceptor_registry_been_created ())
00074 {
00075 return 0;
00076 }
00077
00078 return this->acceptor_registry ().is_collocated (mprofile);
00079 }
00080
00081 TAO_Acceptor_Registry &
00082 TAO_Thread_Lane_Resources::acceptor_registry (void)
00083 {
00084
00085 if (this->acceptor_registry_ == 0)
00086 {
00087
00088
00089 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00090 ace_mon,
00091 this->lock_,
00092 *this->acceptor_registry_);
00093
00094 if (this->acceptor_registry_ == 0)
00095 {
00096
00097
00098 TAO_Resource_Factory &resource_factory =
00099 *this->orb_core_.resource_factory ();
00100
00101
00102 this->acceptor_registry_ =
00103 resource_factory.get_acceptor_registry ();
00104 }
00105 }
00106
00107 return *this->acceptor_registry_;
00108 }
00109
00110 TAO_Connector_Registry *
00111 TAO_Thread_Lane_Resources::connector_registry (void)
00112 {
00113
00114 if (this->connector_registry_ == 0)
00115 {
00116 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00117 ace_mon,
00118 this->lock_,
00119 0);
00120
00121 if (this->connector_registry_ == 0)
00122 {
00123
00124 TAO_Connector_Registry *connector_registry =
00125 this->orb_core_.resource_factory ()->get_connector_registry ();
00126
00127 if (connector_registry == 0)
00128 {
00129 throw ::CORBA::INITIALIZE (
00130 CORBA::SystemException::_tao_minor_code (
00131 TAO_CONNECTOR_REGISTRY_INIT_LOCATION_CODE,
00132 0),
00133 CORBA::COMPLETED_NO);
00134 }
00135
00136 if (connector_registry->open (&this->orb_core_) != 0)
00137 {
00138 throw ::CORBA::INITIALIZE (
00139 CORBA::SystemException::_tao_minor_code (
00140 TAO_CONNECTOR_REGISTRY_INIT_LOCATION_CODE,
00141 0),
00142 CORBA::COMPLETED_NO);
00143 }
00144
00145
00146
00147
00148 this->connector_registry_ = connector_registry;
00149 }
00150 }
00151
00152 return this->connector_registry_;
00153 }
00154
00155
00156 TAO_Leader_Follower &
00157 TAO_Thread_Lane_Resources::leader_follower (void)
00158 {
00159
00160 if (this->leader_follower_ == 0)
00161 {
00162 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
00163 ace_mon,
00164 this->lock_,
00165 *this->leader_follower_);
00166
00167 if (this->leader_follower_ == 0)
00168 {
00169
00170 ACE_NEW_RETURN (this->leader_follower_,
00171 TAO_Leader_Follower (&this->orb_core_,
00172 this->new_leader_generator_),
00173 *this->leader_follower_);
00174 }
00175 }
00176
00177 return *this->leader_follower_;
00178 }
00179
00180
00181 ACE_Allocator*
00182 TAO_Thread_Lane_Resources::input_cdr_dblock_allocator (void)
00183 {
00184 if (this->input_cdr_dblock_allocator_ == 0)
00185 {
00186
00187 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00188
00189 if (this->input_cdr_dblock_allocator_ == 0)
00190 {
00191 this->input_cdr_dblock_allocator_ =
00192 this->resource_factory ()->input_cdr_dblock_allocator ();
00193 }
00194 }
00195
00196 return this->input_cdr_dblock_allocator_;
00197 }
00198
00199
00200 ACE_Allocator*
00201 TAO_Thread_Lane_Resources::input_cdr_buffer_allocator (void)
00202 {
00203 if (this->input_cdr_buffer_allocator_ == 0)
00204 {
00205
00206 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00207
00208 if (this->input_cdr_buffer_allocator_ == 0)
00209 {
00210 this->input_cdr_buffer_allocator_ =
00211 this->resource_factory ()->input_cdr_buffer_allocator ();
00212 }
00213 }
00214
00215 return this->input_cdr_buffer_allocator_;
00216 }
00217
00218
00219 ACE_Allocator*
00220 TAO_Thread_Lane_Resources::input_cdr_msgblock_allocator (void)
00221 {
00222 if (this->input_cdr_msgblock_allocator_ == 0)
00223 {
00224
00225 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00226
00227 if (this->input_cdr_msgblock_allocator_ == 0)
00228 {
00229 this->input_cdr_msgblock_allocator_ =
00230 this->resource_factory ()->input_cdr_msgblock_allocator ();
00231 }
00232 }
00233
00234 return this->input_cdr_msgblock_allocator_;
00235 }
00236
00237 ACE_Allocator*
00238 TAO_Thread_Lane_Resources::transport_message_buffer_allocator (void)
00239 {
00240 if (this->transport_message_buffer_allocator_ == 0)
00241 {
00242
00243 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00244
00245 if (this->transport_message_buffer_allocator_ == 0)
00246 {
00247 this->transport_message_buffer_allocator_ =
00248 this->resource_factory ()->input_cdr_dblock_allocator ();
00249 }
00250 }
00251
00252 return this->transport_message_buffer_allocator_;
00253 }
00254
00255
00256 ACE_Allocator*
00257 TAO_Thread_Lane_Resources::output_cdr_dblock_allocator (void)
00258 {
00259 if (this->output_cdr_dblock_allocator_ == 0)
00260 {
00261
00262 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00263
00264 if (this->output_cdr_dblock_allocator_ == 0)
00265 {
00266 this->output_cdr_dblock_allocator_ =
00267 this->resource_factory ()->output_cdr_dblock_allocator ();
00268 }
00269 }
00270
00271 return this->output_cdr_dblock_allocator_;
00272 }
00273
00274
00275 ACE_Allocator*
00276 TAO_Thread_Lane_Resources::output_cdr_buffer_allocator (void)
00277 {
00278 if (this->output_cdr_buffer_allocator_ == 0)
00279 {
00280
00281 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00282
00283 if (this->output_cdr_buffer_allocator_ == 0)
00284 {
00285 this->output_cdr_buffer_allocator_ =
00286 this->resource_factory ()->output_cdr_buffer_allocator ();
00287 }
00288 }
00289
00290 return this->output_cdr_buffer_allocator_;
00291 }
00292
00293
00294 ACE_Allocator*
00295 TAO_Thread_Lane_Resources::output_cdr_msgblock_allocator (void)
00296 {
00297 if (this->output_cdr_msgblock_allocator_ == 0)
00298 {
00299
00300 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00301
00302 if (this->output_cdr_msgblock_allocator_ == 0)
00303 {
00304 this->output_cdr_msgblock_allocator_ =
00305 this->resource_factory ()->output_cdr_msgblock_allocator ();
00306 }
00307 }
00308
00309 return this->output_cdr_msgblock_allocator_;
00310 }
00311
00312 ACE_Allocator*
00313 TAO_Thread_Lane_Resources::amh_response_handler_allocator (void)
00314 {
00315 if (this->amh_response_handler_allocator_ == 0)
00316 {
00317
00318 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00319
00320 if (this->amh_response_handler_allocator_ == 0)
00321 {
00322 this->amh_response_handler_allocator_ =
00323 this->resource_factory ()->amh_response_handler_allocator ();
00324 }
00325 }
00326
00327 return this->amh_response_handler_allocator_;
00328 }
00329
00330 ACE_Allocator*
00331 TAO_Thread_Lane_Resources::ami_response_handler_allocator (void)
00332 {
00333 if (this->ami_response_handler_allocator_ == 0)
00334 {
00335
00336 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
00337
00338 if (this->ami_response_handler_allocator_ == 0)
00339 {
00340 this->ami_response_handler_allocator_ =
00341 this->resource_factory ()->ami_response_handler_allocator ();
00342 }
00343 }
00344
00345 return this->ami_response_handler_allocator_;
00346 }
00347
00348 int
00349 TAO_Thread_Lane_Resources::open_acceptor_registry (const TAO_EndpointSet &endpoint_set,
00350 bool ignore_address)
00351 {
00352
00353 TAO_Acceptor_Registry &ar = this->acceptor_registry ();
00354
00355
00356 return ar.open (&this->orb_core_,
00357 this->leader_follower ().reactor (),
00358 endpoint_set,
00359 ignore_address);
00360 }
00361
00362 TAO_Resource_Factory *
00363 TAO_Thread_Lane_Resources::resource_factory (void)
00364 {
00365 return this->orb_core_.resource_factory ();
00366 }
00367
00368 void
00369 TAO_Thread_Lane_Resources::finalize (void)
00370 {
00371
00372
00373 if (this->connector_registry_ != 0)
00374 {
00375 this->connector_registry_->close_all ();
00376 delete this->connector_registry_;
00377 this->connector_registry_ = 0;
00378 }
00379
00380
00381 if (this->acceptor_registry_ != 0)
00382 {
00383 this->acceptor_registry_->close_all ();
00384 delete this->acceptor_registry_;
00385 this->acceptor_registry_ = 0;
00386 }
00387
00388
00389 TAO::Connection_Handler_Set handlers;
00390
00391
00392
00393
00394
00395
00396 this->transport_cache_->close (handlers);
00397
00398
00399
00400 TAO_Connection_Handler **handler = 0;
00401
00402 for (TAO::Connection_Handler_Set::iterator iter (handlers);
00403 iter.next (handler);
00404 iter.advance ())
00405 {
00406
00407 (*handler)->close_connection ();
00408
00409
00410 (*handler)->transport ()->remove_reference ();
00411 }
00412
00413 delete this->transport_cache_;
00414 this->transport_cache_ = 0;
00415
00416 delete this->leader_follower_;
00417 this->leader_follower_ = 0;
00418
00419
00420
00421
00422 if (this->input_cdr_dblock_allocator_ != 0)
00423 {
00424 this->input_cdr_dblock_allocator_->remove ();
00425 delete this->input_cdr_dblock_allocator_;
00426 this->input_cdr_dblock_allocator_ = 0;
00427 }
00428
00429 if (this->input_cdr_buffer_allocator_ != 0)
00430 {
00431 this->input_cdr_buffer_allocator_->remove ();
00432 delete this->input_cdr_buffer_allocator_;
00433 this->input_cdr_buffer_allocator_ = 0;
00434 }
00435
00436 if (this->input_cdr_msgblock_allocator_ != 0)
00437 {
00438 this->input_cdr_msgblock_allocator_->remove ();
00439 delete this->input_cdr_msgblock_allocator_;
00440 this->input_cdr_msgblock_allocator_ = 0;
00441 }
00442
00443 if (this->transport_message_buffer_allocator_ != 0)
00444 {
00445 this->transport_message_buffer_allocator_->remove ();
00446 delete this->transport_message_buffer_allocator_;
00447 this->transport_message_buffer_allocator_ = 0;
00448 }
00449
00450 if (this->output_cdr_dblock_allocator_ != 0)
00451 {
00452 this->output_cdr_dblock_allocator_->remove ();
00453 delete this->output_cdr_dblock_allocator_;
00454 this->output_cdr_dblock_allocator_ = 0;
00455 }
00456
00457 if (this->output_cdr_buffer_allocator_ != 0)
00458 {
00459 this->output_cdr_buffer_allocator_->remove ();
00460 delete this->output_cdr_buffer_allocator_;
00461 this->output_cdr_buffer_allocator_ = 0;
00462 }
00463
00464 if (this->output_cdr_msgblock_allocator_ != 0)
00465 {
00466 this->output_cdr_msgblock_allocator_->remove ();
00467 delete this->output_cdr_msgblock_allocator_;
00468 this->output_cdr_msgblock_allocator_ = 0;
00469 }
00470
00471 if (this->amh_response_handler_allocator_ != 0)
00472 {
00473 this->amh_response_handler_allocator_->remove ();
00474 delete this->amh_response_handler_allocator_;
00475 this->amh_response_handler_allocator_ = 0;
00476 }
00477
00478 if (this->ami_response_handler_allocator_ != 0)
00479 {
00480 this->ami_response_handler_allocator_->remove ();
00481 delete this->ami_response_handler_allocator_;
00482 this->ami_response_handler_allocator_ = 0;
00483 }
00484 }
00485
00486 void
00487 TAO_Thread_Lane_Resources::shutdown_reactor (void)
00488 {
00489 TAO_Leader_Follower &leader_follower = this->leader_follower ();
00490
00491 ACE_GUARD (TAO_SYNCH_MUTEX,
00492 ace_mon,
00493 leader_follower.lock ());
00494
00495 ACE_Reactor *reactor = leader_follower.reactor ();
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505 if (!this->orb_core_.resource_factory ()->drop_replies_during_shutdown () &&
00506 leader_follower.has_clients ())
00507 {
00508 reactor->wakeup_all_threads ();
00509 return;
00510 }
00511
00512
00513
00514 reactor->end_reactor_event_loop ();
00515 }
00516
00517 void
00518 TAO_Thread_Lane_Resources::close_all_transports (void)
00519 {
00520
00521 if (!this->orb_core_.resource_factory ()->drop_replies_during_shutdown () ||
00522 this->transport_cache_ == 0)
00523 return;
00524
00525
00526 TAO::Connection_Handler_Set handlers;
00527
00528
00529
00530
00531
00532
00533 this->transport_cache_->close (handlers);
00534
00535
00536
00537 TAO_Connection_Handler **handler = 0;
00538
00539 for (TAO::Connection_Handler_Set::iterator iter (handlers);
00540 iter.next (handler);
00541 iter.advance ())
00542 {
00543
00544 (*handler)->close_connection ();
00545
00546
00547 (*handler)->transport ()->remove_reference ();
00548 }
00549 }
00550
00551 TAO_END_VERSIONED_NAMESPACE_DECL