00001
00002
00003 #include "tao/default_resource.h"
00004
00005 #include "tao/debug.h"
00006 #include "tao/IIOP_Factory.h"
00007 #include "tao/Protocol_Factory.h"
00008 #include "tao/Acceptor_Registry.h"
00009 #include "tao/Connector_Registry.h"
00010 #include "tao/Reactive_Flushing_Strategy.h"
00011 #include "tao/Block_Flushing_Strategy.h"
00012 #include "tao/Leader_Follower_Flushing_Strategy.h"
00013 #include "tao/LRU_Connection_Purging_Strategy.h"
00014 #include "tao/LF_Strategy_Complete.h"
00015 #include "tao/Codeset_Descriptor_Base.h"
00016 #include "tao/Codeset_Manager_Factory_Base.h"
00017 #include "tao/Codeset_Manager.h"
00018 #include "tao/Null_Fragmentation_Strategy.h"
00019 #include "tao/On_Demand_Fragmentation_Strategy.h"
00020 #include "tao/MMAP_Allocator.h"
00021
00022 #include "ace/TP_Reactor.h"
00023 #include "ace/Dynamic_Service.h"
00024 #include "ace/Malloc.h"
00025 #include "ace/Auto_Ptr.h"
00026 #include "ace/Reactor.h"
00027 #include "ace/Malloc_T.h"
00028 #include "ace/Local_Memory_Pool.h"
00029 #include "ace/OS_NS_string.h"
00030 #include "ace/OS_NS_strings.h"
00031
00032 ACE_RCSID (tao,
00033 default_resource,
00034 "default_resource.cpp,v 1.143 2006/06/20 06:05:29 jwillemsen Exp")
00035
00036 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00037
00038 TAO_Default_Resource_Factory::TAO_Default_Resource_Factory (void)
00039 : use_locked_data_blocks_ (1)
00040 , parser_names_count_ (0)
00041 , parser_names_ (0)
00042 , protocol_factories_ ()
00043 , connection_purging_type_ (TAO_CONNECTION_PURGING_STRATEGY)
00044 , cache_maximum_ (TAO_CONNECTION_CACHE_MAXIMUM)
00045 , purge_percentage_ (TAO_PURGE_PERCENT)
00046 , max_muxed_connections_ (0)
00047 , reactor_mask_signals_ (1)
00048 , dynamically_allocated_reactor_ (0)
00049 , options_processed_ (0)
00050 , factory_disabled_ (0)
00051 #if TAO_USE_OUTPUT_CDR_MMAP_MEMORY_POOL == 1
00052 , output_cdr_allocator_type_ (MMAP_ALLOCATOR)
00053 #else
00054 , output_cdr_allocator_type_ (DEFAULT)
00055 #endif
00056 #if TAO_USE_LOCAL_MEMORY_POOL == 1
00057 , use_local_memory_pool_ (true)
00058 #else
00059 , use_local_memory_pool_ (false)
00060 #endif
00061 , cached_connection_lock_type_ (TAO_THREAD_LOCK)
00062 , object_key_table_lock_type_ (TAO_THREAD_LOCK)
00063 , corba_object_lock_type_ (TAO_THREAD_LOCK)
00064 , flushing_strategy_type_ (TAO_LEADER_FOLLOWER_FLUSHING)
00065 , codeset_manager_ (0)
00066 , char_codeset_descriptor_ (0)
00067 , wchar_codeset_descriptor_ (0)
00068 , resource_usage_strategy_ (TAO_Resource_Factory::TAO_EAGER)
00069 , drop_replies_ (true)
00070 , principal_(0)
00071 {
00072 #if TAO_USE_LAZY_RESOURCE_USAGE_STRATEGY == 1
00073 this->resource_usage_strategy_ =
00074 TAO_Resource_Factory::TAO_LAZY;
00075 #endif
00076
00077
00078 }
00079
00080 TAO_Default_Resource_Factory::~TAO_Default_Resource_Factory (void)
00081 {
00082 const TAO_ProtocolFactorySetItor end = this->protocol_factories_.end ();
00083
00084 for (TAO_ProtocolFactorySetItor iterator =
00085 this->protocol_factories_.begin ();
00086 iterator != end;
00087 ++iterator)
00088 {
00089 delete *iterator;
00090 }
00091
00092 this->protocol_factories_.reset ();
00093
00094 for (int i = 0; i < this->parser_names_count_; ++i)
00095 CORBA::string_free (this->parser_names_[i]);
00096
00097 delete [] this->parser_names_;
00098
00099 delete codeset_manager_;
00100 codeset_manager_ = 0;
00101
00102 delete principal_;
00103 }
00104
00105 int
00106 TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[])
00107 {
00108 ACE_TRACE ("TAO_Default_Resource_Factory::init");
00109
00110
00111
00112
00113 if (this->factory_disabled_) {
00114 ACE_DEBUG ((LM_WARNING,
00115 ACE_TEXT ("TAO (%P|%t) Warning: Resource_Factory options ")
00116 ACE_TEXT ("ignored\n")
00117 ACE_TEXT ("Default Resource Factory is disabled\n")));
00118 return 0;
00119 }
00120 this->options_processed_ = 1;
00121
00122 this->parser_names_count_ = 0;
00123
00124 int curarg = 0;
00125
00126 for (curarg = 0; curarg < argc; ++curarg)
00127 {
00128
00129 if (ACE_OS::strcasecmp (argv[curarg],
00130 ACE_TEXT("-ORBIORParser")) == 0)
00131 ++this->parser_names_count_;
00132
00133 ++curarg;
00134
00135 if (curarg == (argc-1) && this->parser_names_count_ != 0)
00136 {
00137
00138 ACE_NEW_RETURN (this->parser_names_,
00139 char *[this->parser_names_count_],
00140 -1);
00141
00142 for (int i = 0;
00143 i < this->parser_names_count_;
00144 ++i)
00145 this->parser_names_[i] = 0;
00146
00147 this->index_ = 0;
00148 }
00149 }
00150
00151 for (curarg = 0; curarg < argc; ++curarg)
00152 {
00153 if (ACE_OS::strcasecmp (argv[curarg],
00154 ACE_TEXT("-ORBReactorMaskSignals")) == 0)
00155 {
00156 ++curarg;
00157 if (curarg < argc)
00158 {
00159 ACE_TCHAR* name = argv[curarg];
00160
00161 if (ACE_OS::strcasecmp (name, ACE_TEXT("0")) == 0)
00162 this->reactor_mask_signals_ = 0;
00163 else if (ACE_OS::strcasecmp (name, ACE_TEXT("1")) == 0)
00164 this->reactor_mask_signals_= 1;
00165 else
00166 this->report_option_value_error (ACE_TEXT("-ORBReactorMaskSignals"), name);
00167 }
00168 }
00169
00170 else if (ACE_OS::strcasecmp (argv[curarg],
00171 ACE_TEXT("-ORBProtocolFactory")) == 0)
00172 {
00173 TAO_ProtocolFactorySet *pset = this->get_protocol_factories ();
00174 ++curarg;
00175 if (curarg < argc)
00176 {
00177 TAO_Protocol_Item *item = 0;
00178 ACE_NEW_RETURN (item,
00179 TAO_Protocol_Item (ACE_TEXT_ALWAYS_CHAR(argv[curarg])),
00180 -1);
00181 if (pset->insert (item) == -1)
00182 ACE_ERROR ((LM_ERROR,
00183 ACE_TEXT ("(%P|%t) Unable to add protocol factories ")
00184 ACE_TEXT ("for %s: %m\n"),
00185 argv[curarg]));
00186 }
00187 }
00188
00189
00190 else if (ACE_OS::strcasecmp (argv[curarg],
00191 ACE_TEXT("-ORBNativeCharCodeSet")) == 0)
00192 {
00193 ++curarg;
00194 if (curarg < argc)
00195 {
00196 if (this->char_codeset_descriptor_ == 0)
00197 this->init_codeset_descriptors();
00198 if (this->char_codeset_descriptor_)
00199 this->char_codeset_descriptor_->ncs (argv[curarg]);
00200 }
00201 }
00202
00203 else if (ACE_OS::strcasecmp (argv[curarg],
00204 ACE_TEXT("-ORBNativeWCharCodeSet")) == 0)
00205 {
00206 ++curarg;
00207 if (curarg < argc)
00208 {
00209 if (this->wchar_codeset_descriptor_ == 0)
00210 this->init_codeset_descriptors();
00211 if (this->wchar_codeset_descriptor_)
00212 this->wchar_codeset_descriptor_->ncs (argv[curarg]);
00213 }
00214 }
00215
00216 else if (ACE_OS::strcasecmp (argv[curarg],
00217 ACE_TEXT("-ORBCharCodesetTranslator")) == 0)
00218 {
00219 ++curarg;
00220 if (curarg < argc)
00221 {
00222 if (this->char_codeset_descriptor_ == 0)
00223 this->init_codeset_descriptors();
00224 if (this->char_codeset_descriptor_)
00225 this->char_codeset_descriptor_->add_translator (argv[curarg]);
00226 }
00227 }
00228
00229
00230 else if (ACE_OS::strcasecmp (argv[curarg],
00231 ACE_TEXT("-ORBWCharCodesetTranslator")) == 0)
00232 {
00233 ++curarg;
00234 if (curarg < argc)
00235 {
00236 if (this->wchar_codeset_descriptor_ == 0)
00237 this->init_codeset_descriptors();
00238 if (this->wchar_codeset_descriptor_)
00239 this->wchar_codeset_descriptor_->add_translator (argv[curarg]);
00240 }
00241 }
00242
00243 else if (ACE_OS::strcasecmp (argv[curarg],
00244 ACE_TEXT("-ORBConnectionCachingStrategy")) == 0)
00245 {
00246 ++curarg;
00247
00248
00249
00250 ACE_DEBUG ((LM_DEBUG,
00251 ACE_TEXT ("(%P|%t) This option would be deprecated \n")
00252 ACE_TEXT ("(%P|%t) Please use -ORBConnectionPurgingStrategy ")
00253 ACE_TEXT ("instead \n")));
00254
00255 if (curarg < argc)
00256 {
00257 ACE_TCHAR* name = argv[curarg];
00258
00259 if (ACE_OS::strcasecmp (name,
00260 ACE_TEXT ("lru")) == 0)
00261 this->connection_purging_type_ =
00262 TAO_Resource_Factory::LRU;
00263 else if (ACE_OS::strcasecmp (name,
00264 ACE_TEXT ("lfu")) == 0)
00265 this->connection_purging_type_ =
00266 TAO_Resource_Factory::LFU;
00267 else if (ACE_OS::strcasecmp (name,
00268 ACE_TEXT ("fifo")) == 0)
00269 this->connection_purging_type_ =
00270 TAO_Resource_Factory::FIFO;
00271 else if (ACE_OS::strcasecmp (name,
00272 ACE_TEXT ("null")) == 0)
00273 this->connection_purging_type_ =
00274 TAO_Resource_Factory::NOOP;
00275 else
00276 this->report_option_value_error (ACE_TEXT ("-ORBConnectionCachingStrategy"), name);
00277 }
00278 }
00279 else if (ACE_OS::strcasecmp (argv[curarg],
00280 ACE_TEXT("-ORBConnectionPurgingStrategy")) == 0)
00281 {
00282 ++curarg;
00283
00284 if (curarg < argc)
00285 {
00286 ACE_TCHAR* name = argv[curarg];
00287
00288 if (ACE_OS::strcasecmp (name,
00289 ACE_TEXT("lru")) == 0)
00290 this->connection_purging_type_ =
00291 TAO_Resource_Factory::LRU;
00292 else if (ACE_OS::strcasecmp (name,
00293 ACE_TEXT("lfu")) == 0)
00294 this->connection_purging_type_ =
00295 TAO_Resource_Factory::LFU;
00296 else if (ACE_OS::strcasecmp (name,
00297 ACE_TEXT("fifo")) == 0)
00298 this->connection_purging_type_ =
00299 TAO_Resource_Factory::FIFO;
00300 else if (ACE_OS::strcasecmp (name,
00301 ACE_TEXT("null")) == 0)
00302 this->connection_purging_type_ =
00303 TAO_Resource_Factory::NOOP;
00304 else
00305 this->report_option_value_error (ACE_TEXT("-ORBConnectionPurgingStrategy"), name);
00306 }
00307 }
00308 else if (ACE_OS::strcasecmp (argv[curarg],
00309 ACE_TEXT("-ORBConnectionCacheMax")) == 0)
00310 {
00311 ++curarg;
00312 if (curarg < argc)
00313 this->cache_maximum_ = ACE_OS::atoi (argv[curarg]);
00314 else
00315 this->report_option_value_error (ACE_TEXT("-ORBConnectionCacheMax"), argv[curarg]);
00316 }
00317
00318 else if (ACE_OS::strcasecmp (argv[curarg],
00319 ACE_TEXT("-ORBConnectionCachePurgePercentage")) == 0)
00320 {
00321 ++curarg;
00322 if (curarg < argc)
00323 this->purge_percentage_ = ACE_OS::atoi (argv[curarg]);
00324 else
00325 this->report_option_value_error (ACE_TEXT("-ORBConnectionCachePurgePercentage"),
00326 argv[curarg]);
00327 }
00328 else if (ACE_OS::strcasecmp (argv[curarg],
00329 ACE_TEXT("-ORBIORParser")) == 0)
00330 {
00331 ++curarg;
00332
00333 if (curarg < argc)
00334 {
00335 this->add_to_ior_parser_names (ACE_TEXT_ALWAYS_CHAR(argv[curarg]));
00336 }
00337 }
00338
00339 else if (ACE_OS::strcasecmp (argv[curarg],
00340 ACE_TEXT("-ORBConnectionCacheLock")) == 0)
00341 {
00342 ++curarg;
00343 if (curarg < argc)
00344 {
00345 ACE_TCHAR* name = argv[curarg];
00346
00347 if (ACE_OS::strcasecmp (name,
00348 ACE_TEXT("thread")) == 0)
00349 this->cached_connection_lock_type_ = TAO_THREAD_LOCK;
00350 else if (ACE_OS::strcasecmp (name,
00351 ACE_TEXT("null")) == 0)
00352 {
00353
00354
00355
00356 this->use_locked_data_blocks_ = 0;
00357 this->cached_connection_lock_type_ = TAO_NULL_LOCK;
00358 }
00359 else
00360 this->report_option_value_error (ACE_TEXT("-ORBConnectionCacheLock"), name);
00361 }
00362 }
00363 else if (ACE_OS::strcasecmp (argv[curarg],
00364 ACE_TEXT("-ORBObjectKeyTableLock")) == 0)
00365 {
00366 ++curarg;
00367 if (curarg < argc)
00368 {
00369 ACE_TCHAR* name = argv[curarg];
00370
00371 if (ACE_OS::strcasecmp (name,
00372 ACE_TEXT("thread")) == 0)
00373 this->object_key_table_lock_type_ = TAO_THREAD_LOCK;
00374 else if (ACE_OS::strcasecmp (name,
00375 ACE_TEXT("null")) == 0)
00376 {
00377
00378
00379
00380 this->object_key_table_lock_type_ = TAO_NULL_LOCK;
00381 }
00382 else
00383 this->report_option_value_error (ACE_TEXT("-ORBObjectKeyTableLock"), name);
00384 }
00385 }
00386 else if (ACE_OS::strcasecmp (argv[curarg],
00387 ACE_TEXT("-ORBCorbaObjectLock")) == 0)
00388 {
00389 ++curarg;
00390 if (curarg < argc)
00391 {
00392 ACE_TCHAR* name = argv[curarg];
00393
00394 if (ACE_OS::strcasecmp (name,
00395 ACE_TEXT("thread")) == 0)
00396 this->corba_object_lock_type_ = TAO_THREAD_LOCK;
00397 else if (ACE_OS::strcasecmp (name,
00398 ACE_TEXT("null")) == 0)
00399 {
00400
00401
00402
00403 this->corba_object_lock_type_ = TAO_NULL_LOCK;
00404 }
00405 else
00406 this->report_option_value_error (ACE_TEXT("-ORBCorbaObjectLock"), name);
00407 }
00408 }
00409 else if (ACE_OS::strcasecmp (argv[curarg],
00410 ACE_TEXT("-ORBResourceUsage")) == 0)
00411 {
00412 ++curarg;
00413 if (curarg < argc)
00414 {
00415 ACE_TCHAR* name = argv[curarg];
00416
00417 if (ACE_OS::strcasecmp (name,
00418 ACE_TEXT("eager")) == 0)
00419 this->resource_usage_strategy_ = TAO_EAGER;
00420 else if (ACE_OS::strcasecmp (name,
00421 ACE_TEXT("lazy")) == 0)
00422 {
00423 this->resource_usage_strategy_ = TAO_LAZY;
00424 }
00425 else
00426 this->report_option_value_error (ACE_TEXT("-ORBResourceUsage"), name);
00427 }
00428 }
00429 else if (ACE_OS::strcasecmp (argv[curarg],
00430 ACE_TEXT("-ORBFlushingStrategy")) == 0)
00431 {
00432 ++curarg;
00433
00434
00435
00436
00437 if (curarg < argc)
00438 {
00439 ACE_TCHAR* name = argv[curarg];
00440
00441 if (ACE_OS::strcasecmp (name,
00442 ACE_TEXT("leader_follower")) == 0)
00443 this->flushing_strategy_type_ = TAO_LEADER_FOLLOWER_FLUSHING;
00444 else if (ACE_OS::strcasecmp (name,
00445 ACE_TEXT("reactive")) == 0)
00446 this->flushing_strategy_type_ = TAO_REACTIVE_FLUSHING;
00447 else if (ACE_OS::strcasecmp (name,
00448 ACE_TEXT("blocking")) == 0)
00449 this->flushing_strategy_type_ = TAO_BLOCKING_FLUSHING;
00450 else
00451 this->report_option_value_error (ACE_TEXT("-ORBFlushingStrategy"), name);
00452 }
00453
00454 }
00455 else if (ACE_OS::strcasecmp (argv[curarg],
00456 ACE_TEXT ("-ORBMuxedConnectionMax")) == 0)
00457 {
00458 ++curarg;
00459 if (curarg < argc)
00460 this->max_muxed_connections_ =
00461 ACE_OS::atoi (argv[curarg]);
00462 else
00463 this->report_option_value_error (ACE_TEXT("-ORBMuxedConnectionMax"),
00464 argv[curarg]);
00465 }
00466 else if (ACE_OS::strcasecmp (argv[curarg],
00467 ACE_TEXT("-ORBDropRepliesDuringShutdown")) == 0)
00468 {
00469 ++curarg;
00470 if (curarg < argc)
00471 {
00472 int tmp = ACE_OS::atoi (argv[curarg]);
00473
00474 if (tmp == 0)
00475 this->drop_replies_ = false;
00476 else
00477 this->drop_replies_ = true;
00478 }
00479 else
00480 this->report_option_value_error (ACE_TEXT("-ORBDropRepliesDuringShutdown"),
00481 argv[curarg]);
00482 }
00483 else if (0 == ACE_OS::strcasecmp (argv[curarg],
00484 ACE_TEXT("-ORBOutputCDRAllocator")))
00485 {
00486 ++curarg;
00487
00488 if (curarg < argc)
00489 {
00490 ACE_TCHAR const * const current_arg = argv[curarg];
00491
00492 if (ACE_OS::strcasecmp (current_arg,
00493 ACE_TEXT("mmap")) == 0)
00494 {
00495 #ifdef ACE_HAS_SENDFILE
00496 this->output_cdr_allocator_type_ = MMAP_ALLOCATOR;
00497 #else
00498 ACE_DEBUG ((LM_WARNING,
00499 ACE_TEXT ("MMAP allocator unsupport on this platform")));
00500 #endif
00501 }
00502 else if (ACE_OS::strcasecmp (current_arg,
00503 ACE_TEXT("local_memory_pool")) == 0
00504 && this->output_cdr_allocator_type_ != DEFAULT)
00505 {
00506 this->output_cdr_allocator_type_ = LOCAL_MEMORY_POOL;
00507 }
00508 else if (ACE_OS::strcasecmp (current_arg,
00509 ACE_TEXT("default")) == 0)
00510 {
00511 this->output_cdr_allocator_type_ = DEFAULT;
00512 }
00513 else
00514 {
00515 this->report_option_value_error (
00516 ACE_TEXT("-ORBOutputCDRAllocator"), current_arg);
00517 }
00518 }
00519 }
00520 else if (0 == ACE_OS::strcasecmp (argv[curarg],
00521 ACE_TEXT("-ORBZeroCopyWrite")))
00522 {
00523 #ifdef ACE_HAS_SENDFILE
00524 this->output_cdr_allocator_type_ = MMAP_ALLOCATOR;
00525 #else
00526 ACE_DEBUG ((LM_WARNING,
00527 ACE_TEXT ("Zero copy writes unsupported on this platform\n")));
00528 #endif
00529 }
00530 else if (ACE_OS::strncmp (argv[curarg],
00531 ACE_TEXT ("-ORB"),
00532 4) == 0)
00533 {
00534
00535
00536 ACE_ERROR ((LM_ERROR,
00537 ACE_TEXT ("Default_Resource_Factory - ")
00538 ACE_TEXT ("unknown option <%s>\n"),
00539 argv[curarg]));
00540 }
00541 else
00542 {
00543 ACE_DEBUG ((LM_DEBUG,
00544 ACE_TEXT ("Default_Resource_Factory - ")
00545 ACE_TEXT ("ignoring option <%s>\n"),
00546 argv[curarg]));
00547 }
00548 }
00549
00550 return 0;
00551 }
00552
00553 int
00554 TAO_Default_Resource_Factory::get_parser_names (char **&names,
00555 int &number_of_names)
00556 {
00557 if (this->parser_names_count_ != 0)
00558 {
00559
00560 names = this->parser_names_;
00561 number_of_names = this->parser_names_count_;
00562
00563 return 0;
00564 }
00565
00566
00567 this->parser_names_count_ = 5;
00568 this->parser_names_ =
00569 new char *[this->parser_names_count_];
00570
00571 CORBA::ULong index = 0;
00572
00573 this->parser_names_[index] = CORBA::string_dup ("DLL_Parser");
00574 ++index;
00575
00576 this->parser_names_[index] = CORBA::string_dup ("FILE_Parser");
00577 ++index;
00578
00579 this->parser_names_[index] = CORBA::string_dup ("CORBALOC_Parser");
00580 ++index;
00581
00582 this->parser_names_[index] = CORBA::string_dup ("CORBANAME_Parser");
00583 ++index;
00584
00585 this->parser_names_[index] = CORBA::string_dup ("MCAST_Parser");
00586 ++index;
00587
00588 names = this->parser_names_;
00589
00590 number_of_names = index;
00591
00592 return 0;
00593 }
00594
00595 int
00596 TAO_Default_Resource_Factory::add_to_ior_parser_names (const char *curarg)
00597 {
00598 this->parser_names_[this->index_] = CORBA::string_dup (curarg);
00599
00600 ++this->index_;
00601
00602 return 0;
00603 }
00604
00605
00606 int
00607 TAO_Default_Resource_Factory::load_default_protocols (void)
00608 {
00609 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0)
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637 TAO_Protocol_Factory *protocol_factory = 0;
00638 auto_ptr<TAO_Protocol_Factory> safe_protocol_factory;
00639
00640 TAO_Protocol_Item *item = 0;
00641
00642
00643
00644
00645 bool transfer_ownership = false;
00646
00647 protocol_factory =
00648 ACE_Dynamic_Service<TAO_Protocol_Factory>::instance ("IIOP_Factory");
00649
00650 if (protocol_factory == 0)
00651 {
00652 if (TAO_debug_level > 0)
00653 ACE_ERROR ((LM_WARNING,
00654 ACE_TEXT ("TAO (%P|%t) No %s found in ")
00655 ACE_TEXT ("Service Repository. ")
00656 ACE_TEXT ("Using default instance IIOP ")
00657 ACE_TEXT ("Protocol Factory.\n"),
00658 ACE_TEXT ("IIOP Protocol Factory")));
00659
00660 ACE_NEW_RETURN (protocol_factory,
00661 TAO_IIOP_Protocol_Factory,
00662 -1);
00663
00664 ACE_AUTO_PTR_RESET (safe_protocol_factory,
00665 protocol_factory,
00666 TAO_Protocol_Factory);
00667
00668 transfer_ownership = true;
00669
00670 }
00671 else
00672 {
00673 transfer_ownership = false;
00674 }
00675
00676 ACE_NEW_RETURN (item,
00677 TAO_Protocol_Item ("IIOP_Factory"),
00678 -1);
00679
00680
00681
00682
00683
00684
00685
00686 item->factory ((transfer_ownership ?
00687 safe_protocol_factory.release () :
00688 protocol_factory),
00689 transfer_ownership);
00690
00691 if (this->protocol_factories_.insert (item) == -1)
00692 {
00693 ACE_ERROR ((LM_ERROR,
00694 ACE_TEXT ("TAO (%P|%t) Unable to add ")
00695 ACE_TEXT ("<%s> to protocol factory set.\n"),
00696 ACE_TEXT_CHAR_TO_TCHAR (item->protocol_name ().c_str ())));
00697
00698 delete item;
00699
00700 if (transfer_ownership == 0)
00701 delete protocol_factory;
00702
00703 return -1;
00704 }
00705
00706 if (TAO_debug_level > 0)
00707 {
00708 ACE_DEBUG ((LM_DEBUG,
00709 ACE_TEXT ("TAO (%P|%t) Loaded default ")
00710 ACE_TEXT ("protocol <IIOP_Factory>\n")));
00711 }
00712
00713 #endif
00714
00715 return 0;
00716 }
00717
00718 int
00719 TAO_Default_Resource_Factory::init_protocol_factories (void)
00720 {
00721 const TAO_ProtocolFactorySetItor end = protocol_factories_.end ();
00722 TAO_ProtocolFactorySetItor factory = protocol_factories_.begin ();
00723
00724 if (factory == end)
00725 {
00726 return this->load_default_protocols ();
00727 }
00728
00729 for (; factory != end; ++factory)
00730 {
00731 const ACE_CString &name = (*factory)->protocol_name ();
00732 (*factory)->factory (
00733 ACE_Dynamic_Service<TAO_Protocol_Factory>::instance (name.c_str ()));
00734 if ((*factory)->factory () == 0)
00735 {
00736 ACE_ERROR_RETURN ((LM_ERROR,
00737 ACE_TEXT ("TAO (%P|%t) Unable to load ")
00738 ACE_TEXT ("protocol <%s>, %p\n"),
00739 ACE_TEXT_CHAR_TO_TCHAR(name.c_str ()),
00740 ACE_TEXT ("")),
00741 -1);
00742 }
00743
00744 if (TAO_debug_level > 0)
00745 {
00746 ACE_DEBUG ((LM_DEBUG,
00747 ACE_TEXT ("TAO (%P|%t) Loaded protocol <%s>\n"),
00748 ACE_TEXT_CHAR_TO_TCHAR(name.c_str ())));
00749 }
00750 }
00751
00752 return 0;
00753 }
00754
00755 int
00756 TAO_Default_Resource_Factory::use_locked_data_blocks (void) const
00757 {
00758 return this->use_locked_data_blocks_;
00759 }
00760
00761 TAO_ProtocolFactorySet *
00762 TAO_Default_Resource_Factory::get_protocol_factories (void)
00763 {
00764 return &protocol_factories_;
00765 }
00766
00767 TAO_Acceptor_Registry *
00768 TAO_Default_Resource_Factory::get_acceptor_registry (void)
00769 {
00770 TAO_Acceptor_Registry *ar = 0;
00771
00772 ACE_NEW_RETURN(ar,
00773 TAO_Acceptor_Registry,
00774 0);
00775
00776 return ar;
00777 }
00778
00779 TAO_Connector_Registry *
00780 TAO_Default_Resource_Factory::get_connector_registry (void)
00781 {
00782 TAO_Connector_Registry *cr = 0;
00783
00784 ACE_NEW_RETURN(cr,
00785 TAO_Connector_Registry,
00786 0);
00787
00788 return cr;
00789 }
00790
00791 ACE_Reactor_Impl*
00792 TAO_Default_Resource_Factory::allocate_reactor_impl (void) const
00793 {
00794 ACE_Reactor_Impl *impl = 0;
00795
00796
00797
00798
00799 ACE_NEW_RETURN (impl,
00800 ACE_TP_Reactor (ACE::max_handles (),
00801 1,
00802 (ACE_Sig_Handler*)0,
00803 (ACE_Timer_Queue*)0,
00804 this->reactor_mask_signals_,
00805 ACE_Select_Reactor_Token::LIFO),
00806 0);
00807
00808 return impl;
00809 }
00810
00811 ACE_Reactor *
00812 TAO_Default_Resource_Factory::get_reactor (void)
00813 {
00814 ACE_Reactor *reactor = 0;
00815 ACE_NEW_RETURN (reactor,
00816 ACE_Reactor (this->allocate_reactor_impl (), 1),
00817 0);
00818
00819 if (reactor->initialized () == 0)
00820 {
00821 delete reactor;
00822 reactor = 0;
00823 }
00824 else
00825 this->dynamically_allocated_reactor_ = 1;
00826
00827 return reactor;
00828 }
00829
00830 void
00831 TAO_Default_Resource_Factory::reclaim_reactor (ACE_Reactor *reactor)
00832 {
00833 if (this->dynamically_allocated_reactor_ == 1)
00834 delete reactor;
00835 }
00836
00837
00838 typedef ACE_Malloc<ACE_LOCAL_MEMORY_POOL,TAO_SYNCH_MUTEX> LOCKED_MALLOC;
00839 typedef ACE_Allocator_Adapter<LOCKED_MALLOC> LOCKED_ALLOCATOR_POOL;
00840 typedef ACE_New_Allocator LOCKED_ALLOCATOR_NO_POOL;
00841
00842 void
00843 TAO_Default_Resource_Factory::use_local_memory_pool (bool flag)
00844 {
00845 this->use_local_memory_pool_ = flag;
00846
00847 if (this->output_cdr_allocator_type_ == DEFAULT)
00848 this->output_cdr_allocator_type_ = LOCAL_MEMORY_POOL;
00849 }
00850
00851 ACE_Allocator *
00852 TAO_Default_Resource_Factory::input_cdr_dblock_allocator (void)
00853 {
00854 ACE_Allocator *allocator = 0;
00855 if (use_local_memory_pool_)
00856 {
00857 ACE_NEW_RETURN (allocator,
00858 LOCKED_ALLOCATOR_POOL,
00859 0);
00860 }
00861 else
00862 {
00863 ACE_NEW_RETURN (allocator,
00864 LOCKED_ALLOCATOR_NO_POOL,
00865 0);
00866 }
00867
00868 return allocator;
00869 }
00870
00871 ACE_Allocator *
00872 TAO_Default_Resource_Factory::input_cdr_buffer_allocator (void)
00873 {
00874 ACE_Allocator *allocator = 0;
00875 if (use_local_memory_pool_)
00876 {
00877 ACE_NEW_RETURN (allocator,
00878 LOCKED_ALLOCATOR_POOL,
00879 0);
00880 }
00881 else
00882 {
00883 ACE_NEW_RETURN (allocator,
00884 LOCKED_ALLOCATOR_NO_POOL,
00885 0);
00886 }
00887
00888 return allocator;
00889 }
00890
00891 ACE_Allocator *
00892 TAO_Default_Resource_Factory::input_cdr_msgblock_allocator (void)
00893 {
00894 ACE_Allocator *allocator = 0;
00895 if (use_local_memory_pool_)
00896 {
00897 ACE_NEW_RETURN (allocator,
00898 LOCKED_ALLOCATOR_POOL,
00899 0);
00900 }
00901 else
00902 {
00903 ACE_NEW_RETURN (allocator,
00904 LOCKED_ALLOCATOR_NO_POOL,
00905 0);
00906 }
00907
00908 return allocator;
00909 }
00910
00911 int
00912 TAO_Default_Resource_Factory::input_cdr_allocator_type_locked (void)
00913 {
00914 return 1;
00915 }
00916
00917 ACE_Allocator*
00918 TAO_Default_Resource_Factory::output_cdr_dblock_allocator (void)
00919 {
00920 ACE_Allocator *allocator = 0;
00921 if (use_local_memory_pool_)
00922 {
00923 ACE_NEW_RETURN (allocator,
00924 LOCKED_ALLOCATOR_POOL,
00925 0);
00926 }
00927 else
00928 {
00929 ACE_NEW_RETURN (allocator,
00930 LOCKED_ALLOCATOR_NO_POOL,
00931 0);
00932 }
00933
00934 return allocator;
00935 }
00936
00937 ACE_Allocator *
00938 TAO_Default_Resource_Factory::output_cdr_buffer_allocator (void)
00939 {
00940 ACE_Allocator *allocator = 0;
00941
00942 switch (this->output_cdr_allocator_type_)
00943 {
00944 case LOCAL_MEMORY_POOL:
00945 ACE_NEW_RETURN (allocator,
00946 LOCKED_ALLOCATOR_POOL,
00947 0);
00948
00949 break;
00950
00951 #ifdef ACE_HAS_SENDFILE
00952 case MMAP_ALLOCATOR:
00953 ACE_NEW_RETURN (allocator,
00954 TAO_MMAP_Allocator,
00955 0);
00956
00957 break;
00958 #endif
00959
00960 case DEFAULT:
00961 default:
00962 ACE_NEW_RETURN (allocator,
00963 LOCKED_ALLOCATOR_NO_POOL,
00964 0);
00965
00966 break;
00967 }
00968
00969 return allocator;
00970 }
00971
00972 ACE_Allocator*
00973 TAO_Default_Resource_Factory::output_cdr_msgblock_allocator (void)
00974 {
00975 ACE_Allocator *allocator = 0;
00976 if (use_local_memory_pool_)
00977 {
00978 ACE_NEW_RETURN (allocator,
00979 LOCKED_ALLOCATOR_POOL,
00980 0);
00981 }
00982 else
00983 {
00984 ACE_NEW_RETURN (allocator,
00985 LOCKED_ALLOCATOR_NO_POOL,
00986 0);
00987 }
00988
00989 return allocator;
00990 }
00991
00992 ACE_Allocator*
00993 TAO_Default_Resource_Factory::amh_response_handler_allocator (void)
00994 {
00995 ACE_Allocator *allocator = 0;
00996 if (use_local_memory_pool_)
00997 {
00998 ACE_NEW_RETURN (allocator,
00999 LOCKED_ALLOCATOR_POOL,
01000 0);
01001 }
01002 else
01003 {
01004 ACE_NEW_RETURN (allocator,
01005 LOCKED_ALLOCATOR_NO_POOL,
01006 0);
01007 }
01008
01009 return allocator;
01010 }
01011
01012 ACE_Allocator*
01013 TAO_Default_Resource_Factory::ami_response_handler_allocator (void)
01014 {
01015 ACE_Allocator *allocator = 0;
01016 if (use_local_memory_pool_)
01017 {
01018 ACE_NEW_RETURN (allocator,
01019 LOCKED_ALLOCATOR_POOL,
01020 0);
01021 }
01022 else
01023 {
01024 ACE_NEW_RETURN (allocator,
01025 LOCKED_ALLOCATOR_NO_POOL,
01026 0);
01027 }
01028
01029 return allocator;
01030 }
01031
01032 int
01033 TAO_Default_Resource_Factory::cache_maximum (void) const
01034 {
01035 return this->cache_maximum_;
01036 }
01037
01038 int
01039 TAO_Default_Resource_Factory::purge_percentage (void) const
01040 {
01041 return this->purge_percentage_;
01042 }
01043
01044 int
01045 TAO_Default_Resource_Factory::max_muxed_connections (void) const
01046 {
01047 return this->max_muxed_connections_;
01048 }
01049
01050
01051 ACE_Lock *
01052 TAO_Default_Resource_Factory::create_cached_connection_lock (void)
01053 {
01054 ACE_Lock *the_lock = 0;
01055
01056 if (this->cached_connection_lock_type_ == TAO_NULL_LOCK)
01057 ACE_NEW_RETURN (the_lock,
01058 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>,
01059 0);
01060 else
01061 ACE_NEW_RETURN (the_lock,
01062 ACE_Lock_Adapter<TAO_SYNCH_MUTEX>,
01063 0);
01064
01065 return the_lock;
01066 }
01067
01068 int
01069 TAO_Default_Resource_Factory::locked_transport_cache (void)
01070 {
01071 if (this->cached_connection_lock_type_ == TAO_NULL_LOCK)
01072 return 0;
01073
01074 return 1;
01075 }
01076
01077
01078 ACE_Lock *
01079 TAO_Default_Resource_Factory::create_object_key_table_lock (void)
01080 {
01081 ACE_Lock *the_lock = 0;
01082
01083 if (this->object_key_table_lock_type_ == TAO_NULL_LOCK)
01084 ACE_NEW_RETURN (the_lock,
01085 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>,
01086 0);
01087 else
01088 ACE_NEW_RETURN (the_lock,
01089 ACE_Lock_Adapter<TAO_SYNCH_MUTEX>,
01090 0);
01091
01092 return the_lock;
01093 }
01094
01095 ACE_Lock *
01096 TAO_Default_Resource_Factory::create_corba_object_lock (void)
01097 {
01098 ACE_Lock *the_lock = 0;
01099
01100 if (this->corba_object_lock_type_ == TAO_NULL_LOCK)
01101 ACE_NEW_RETURN (the_lock,
01102 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>,
01103 0);
01104 else
01105 ACE_NEW_RETURN (the_lock,
01106 ACE_Lock_Adapter<TAO_SYNCH_MUTEX>,
01107 0);
01108
01109 return the_lock;
01110 }
01111
01112 TAO_Flushing_Strategy *
01113 TAO_Default_Resource_Factory::create_flushing_strategy (void)
01114 {
01115 TAO_Flushing_Strategy *strategy = 0;
01116 if (this->flushing_strategy_type_ == TAO_LEADER_FOLLOWER_FLUSHING)
01117 ACE_NEW_RETURN (strategy,
01118 TAO_Leader_Follower_Flushing_Strategy,
01119 0);
01120 else if (this->flushing_strategy_type_ == TAO_REACTIVE_FLUSHING)
01121 ACE_NEW_RETURN (strategy,
01122 TAO_Reactive_Flushing_Strategy,
01123 0);
01124 else
01125 ACE_NEW_RETURN (strategy,
01126 TAO_Block_Flushing_Strategy,
01127 0);
01128 return strategy;
01129 }
01130
01131 TAO_Connection_Purging_Strategy *
01132 TAO_Default_Resource_Factory::create_purging_strategy (void)
01133 {
01134 TAO_Connection_Purging_Strategy *strategy = 0;
01135
01136 if (this->connection_purging_type_ == TAO_Resource_Factory::LRU)
01137 {
01138 ACE_NEW_RETURN (strategy,
01139 TAO_LRU_Connection_Purging_Strategy (
01140 this->cache_maximum ()),
01141 0);
01142 }
01143 else
01144 {
01145 ACE_ERROR ((LM_ERROR,
01146 ACE_TEXT ("TAO (%P|%t) - ")
01147 ACE_TEXT ("no usable purging strategy ")
01148 ACE_TEXT ("was found.\n")));
01149 }
01150
01151 return strategy;
01152 }
01153
01154 TAO_LF_Strategy *
01155 TAO_Default_Resource_Factory::create_lf_strategy (void)
01156 {
01157 TAO_LF_Strategy *strategy = 0;
01158
01159 ACE_NEW_RETURN (strategy,
01160 TAO_LF_Strategy_Complete,
01161 0);
01162
01163 return strategy;
01164 }
01165
01166 auto_ptr<TAO_GIOP_Fragmentation_Strategy>
01167 TAO_Default_Resource_Factory::create_fragmentation_strategy (
01168 TAO_Transport * transport,
01169 CORBA::ULong max_message_size) const
01170 {
01171 auto_ptr<TAO_GIOP_Fragmentation_Strategy> strategy (0);
01172
01173 TAO_GIOP_Fragmentation_Strategy * tmp = 0;
01174
01175
01176
01177
01178
01179
01180
01181 static CORBA::ULong const min_message_size = 24;
01182
01183
01184
01185
01186
01187
01188 if (transport)
01189 {
01190 if (max_message_size < min_message_size
01191 || (TAO_DEF_GIOP_MAJOR == 1 && TAO_DEF_GIOP_MINOR < 2))
01192 {
01193
01194 ACE_NEW_RETURN (tmp,
01195 TAO_Null_Fragmentation_Strategy,
01196 strategy);
01197
01198 }
01199 else
01200 {
01201 ACE_NEW_RETURN (tmp,
01202 TAO_On_Demand_Fragmentation_Strategy (
01203 transport,
01204 max_message_size),
01205 strategy);
01206 }
01207 }
01208
01209 ACE_AUTO_PTR_RESET (strategy,
01210 tmp,
01211 TAO_GIOP_Fragmentation_Strategy);
01212
01213 return strategy;
01214 }
01215
01216 void
01217 TAO_Default_Resource_Factory::report_option_value_error (
01218 const ACE_TCHAR* option_name,
01219 const ACE_TCHAR* option_value)
01220 {
01221 ACE_DEBUG((LM_DEBUG,
01222 ACE_TEXT ("Default_Resource_Factory - unknown argument")
01223 ACE_TEXT (" <%s> for <%s>\n"),
01224 option_value, option_name));
01225 }
01226
01227 void
01228 TAO_Default_Resource_Factory::disable_factory (void)
01229 {
01230 this->factory_disabled_ = 1;
01231 if (this->options_processed_)
01232 {
01233 ACE_DEBUG ((LM_WARNING,
01234 ACE_TEXT ("TAO (%P|%t) Warning: Resource_Factory options ignored\n")
01235 ACE_TEXT ("Default Resource Factory is disabled\n")));
01236 }
01237 }
01238
01239 TAO_Codeset_Manager *
01240 TAO_Default_Resource_Factory::codeset_manager(void)
01241 {
01242 if (this->codeset_manager_)
01243 return this->codeset_manager_;
01244
01245 TAO_Codeset_Manager_Factory_Base *factory =
01246 ACE_Dynamic_Service<TAO_Codeset_Manager_Factory_Base>::instance ("TAO_Codeset");
01247 this->codeset_manager_ = factory->create ();
01248
01249 return this->codeset_manager_;
01250 }
01251
01252 void
01253 TAO_Default_Resource_Factory::init_codeset_descriptors(void)
01254 {
01255 if (this->char_codeset_descriptor_)
01256 return;
01257 if (this->codeset_manager() == 0)
01258 return;
01259
01260 this->char_codeset_descriptor_ =
01261 this->codeset_manager_->char_codeset_descriptor();
01262 this->wchar_codeset_descriptor_ =
01263 this->codeset_manager_->wchar_codeset_descriptor();
01264 }
01265
01266 TAO_Resource_Factory::Resource_Usage
01267 TAO_Default_Resource_Factory::resource_usage_strategy (void) const
01268 {
01269 return this->resource_usage_strategy_;
01270 }
01271
01272 bool
01273 TAO_Default_Resource_Factory::drop_replies_during_shutdown (void) const
01274 {
01275 return this->drop_replies_;
01276 }
01277
01278 TAO_END_VERSIONED_NAMESPACE_DECL
01279
01280
01281
01282 ACE_STATIC_SVC_DEFINE (TAO_Default_Resource_Factory,
01283 ACE_TEXT ("Resource_Factory"),
01284 ACE_SVC_OBJ_T,
01285 &ACE_SVC_NAME (TAO_Default_Resource_Factory),
01286 ACE_Service_Type::DELETE_THIS
01287 | ACE_Service_Type::DELETE_OBJ,
01288 0)
01289 ACE_FACTORY_DEFINE (TAO, TAO_Default_Resource_Factory)