Updated logging to include the class/method so that it is more obvious where these...
[ACE_TAO.git] / TAO / tao / default_resource.cpp
blobe51280730e5bbb594ffd0228ca693b6fdbaeab54
1 // -*- C++ -*-
2 #include "tao/default_resource.h"
4 #include "tao/debug.h"
5 #include "tao/IIOP_Factory.h"
6 #include "tao/Acceptor_Registry.h"
7 #include "tao/Connector_Registry.h"
8 #include "tao/Reactive_Flushing_Strategy.h"
9 #include "tao/Block_Flushing_Strategy.h"
10 #include "tao/Leader_Follower_Flushing_Strategy.h"
11 #include "tao/LRU_Connection_Purging_Strategy.h"
12 #include "tao/LF_Strategy_Complete.h"
13 #include "tao/Codeset_Descriptor_Base.h"
14 #include "tao/Codeset_Manager_Factory_Base.h"
15 #include "tao/Codeset_Manager.h"
16 #include "tao/Null_Fragmentation_Strategy.h"
17 #include "tao/On_Demand_Fragmentation_Strategy.h"
18 #include "tao/MMAP_Allocator.h"
19 #include "tao/Load_Protocol_Factory_T.h"
20 #include "tao/Time_Policy_Manager.h"
22 #include "ace/TP_Reactor.h"
23 #include "ace/Malloc.h"
24 #include "ace/Reactor.h"
25 #include "ace/Malloc_T.h"
26 #include "ace/Local_Memory_Pool.h"
27 #include "ace/OS_NS_string.h"
28 #include "ace/OS_NS_strings.h"
30 #include <memory>
32 #if !defined (__ACE_INLINE__)
33 #include "tao/default_resource.inl"
34 #endif /* __ACE_INLINE__ */
36 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
39 TAO_Codeset_Parameters::TAO_Codeset_Parameters ()
40 : translators_ ()
41 , native_ (nullptr)
45 TAO_Codeset_Parameters::~TAO_Codeset_Parameters ()
47 for (TAO_Codeset_Parameters::iterator i =
48 this->translators ();
49 !i.done ();
50 i.advance ())
52 ACE_TCHAR** element = nullptr;
53 if (i.next (element))
54 ACE_OS::free (*element);
57 ACE_OS::free (this->native_);
60 const ACE_TCHAR*
61 TAO_Codeset_Parameters::native ()
63 return (this->native_);
66 void
67 TAO_Codeset_Parameters::apply_to (TAO_Codeset_Descriptor_Base *csd)
69 if (csd == nullptr)
70 return;
72 if (this->native () != nullptr)
73 csd->ncs (this->native ());
75 ACE_TCHAR** element = nullptr;
76 for (TAO_Codeset_Parameters::iterator i = this->translators ();
77 !i.done ();
78 i.advance ())
80 if (i.next (element))
81 csd->add_translator (*element);
85 void
86 TAO_Codeset_Parameters::native (const ACE_TCHAR* n)
88 ACE_OS::free (this->native_);
89 this->native_ = ACE_OS::strdup (n);
92 void
93 TAO_Codeset_Parameters::add_translator (const ACE_TCHAR*name)
95 this->translators_.enqueue_tail (ACE_OS::strdup (name));
98 TAO_Codeset_Parameters::iterator
99 TAO_Codeset_Parameters::translators ()
101 return this->translators_.begin ();
104 TAO_Default_Resource_Factory::TAO_Default_Resource_Factory ()
105 : use_locked_data_blocks_ (1)
106 , parser_names_count_ (0)
107 , parser_names_ (nullptr)
108 , protocol_factories_ ()
109 , connection_purging_type_ (TAO_CONNECTION_PURGING_STRATEGY)
110 , cache_maximum_ (TAO_CONNECTION_CACHE_MAXIMUM)
111 , purge_percentage_ (TAO_PURGE_PERCENT)
112 , max_muxed_connections_ (0)
113 , reactor_mask_signals_ (1)
114 , dynamically_allocated_reactor_ (false)
115 , options_processed_ (0)
116 , factory_disabled_ (0)
117 #if TAO_USE_OUTPUT_CDR_MMAP_MEMORY_POOL == 1
118 , output_cdr_allocator_type_ (MMAP_ALLOCATOR)
119 #else
120 , output_cdr_allocator_type_ (DEFAULT)
121 #endif
122 #if TAO_USE_LOCAL_MEMORY_POOL == 1
123 , use_local_memory_pool_ (true)
124 #else
125 , use_local_memory_pool_ (false)
126 #endif
127 , cached_connection_lock_type_ (TAO_THREAD_LOCK)
128 #if defined (TAO_USE_BLOCKING_FLUSHING)
129 , flushing_strategy_type_ (TAO_BLOCKING_FLUSHING)
130 #elif defined (TAO_USE_REACTIVE_FLUSHING)
131 , flushing_strategy_type_ (TAO_REACTIVE_FLUSHING)
132 #else
133 , flushing_strategy_type_ (TAO_LEADER_FOLLOWER_FLUSHING)
134 #endif
135 , char_codeset_parameters_ ()
136 , wchar_codeset_parameters_ ()
137 , resource_usage_strategy_ (TAO_Resource_Factory::TAO_EAGER)
138 , drop_replies_ (true)
140 #if TAO_USE_LAZY_RESOURCE_USAGE_STRATEGY == 1
141 this->resource_usage_strategy_ =
142 TAO_Resource_Factory::TAO_LAZY;
143 #endif /*TAO_USE_LAZY_RESOURCE_USAGE_STRATEGY*/
148 TAO_Default_Resource_Factory::~TAO_Default_Resource_Factory ()
150 const TAO_ProtocolFactorySetItor end = this->protocol_factories_.end ();
152 for (TAO_ProtocolFactorySetItor iterator =
153 this->protocol_factories_.begin ();
154 iterator != end;
155 ++iterator)
157 delete *iterator;
160 this->protocol_factories_.reset ();
162 for (int i = 0; i < this->parser_names_count_; ++i)
163 CORBA::string_free (this->parser_names_[i]);
165 delete [] this->parser_names_;
170 TAO_Default_Resource_Factory::init (int argc, ACE_TCHAR *argv[])
172 ACE_TRACE ("TAO_Default_Resource_Factory::init");
174 // If this factory has already been disabled then
175 // print a warning and exit because any options
176 // are useless
177 if (this->factory_disabled_)
179 TAOLIB_DEBUG ((LM_WARNING,
180 ACE_TEXT ("TAO (%P|%t) - Warning: Resource_Factory options ")
181 ACE_TEXT ("ignored. ")
182 ACE_TEXT ("Default Resource Factory is disabled\n")));
183 return 0;
185 this->options_processed_ = 1;
187 this->parser_names_count_ = 0;
189 int curarg = 0;
191 for (curarg = 0; curarg < argc; ++curarg)
193 // Parse thro' and find the number of Parsers to be loaded.
194 if (ACE_OS::strcasecmp (argv[curarg],
195 ACE_TEXT("-ORBIORParser")) == 0)
196 ++this->parser_names_count_;
198 ++curarg;
200 if (curarg == (argc-1) && this->parser_names_count_ != 0)
202 // This is the last loop..
203 ACE_NEW_RETURN (this->parser_names_,
204 char *[this->parser_names_count_],
205 -1);
207 for (int i = 0;
208 i < this->parser_names_count_;
209 ++i)
210 this->parser_names_[i] = nullptr;
212 this->index_ = 0;
216 for (curarg = 0; curarg < argc; ++curarg)
218 if (ACE_OS::strcasecmp (argv[curarg],
219 ACE_TEXT("-ORBReactorMaskSignals")) == 0)
221 ++curarg;
222 if (curarg < argc)
224 ACE_TCHAR* name = argv[curarg];
226 if (ACE_OS::strcasecmp (name, ACE_TEXT("0")) == 0)
227 this->reactor_mask_signals_ = 0;
228 else if (ACE_OS::strcasecmp (name, ACE_TEXT("1")) == 0)
229 this->reactor_mask_signals_= 1;
230 else
231 this->report_option_value_error (ACE_TEXT("-ORBReactorMaskSignals"), name);
235 else if (ACE_OS::strcasecmp (argv[curarg],
236 ACE_TEXT("-ORBProtocolFactory")) == 0)
238 TAO_ProtocolFactorySet *pset = this->get_protocol_factories ();
239 ++curarg;
240 if (curarg < argc)
242 TAO_Protocol_Item *item = nullptr;
243 ACE_NEW_RETURN (item,
244 TAO_Protocol_Item (ACE_TEXT_ALWAYS_CHAR(argv[curarg])),
245 -1);
246 if (pset->insert (item) == -1)
247 TAOLIB_ERROR ((LM_ERROR,
248 ACE_TEXT ("(%P|%t) Unable to add protocol factories ")
249 ACE_TEXT ("for %s: %m\n"),
250 argv[curarg]));
254 /// CodeSet Translators
255 else if (ACE_OS::strcasecmp (argv[curarg],
256 ACE_TEXT("-ORBNativeCharCodeSet")) == 0)
258 ++curarg;
259 if (curarg < argc)
260 this->char_codeset_parameters_.native (argv[curarg]);
263 else if (ACE_OS::strcasecmp (argv[curarg],
264 ACE_TEXT("-ORBNativeWCharCodeSet")) == 0)
266 ++curarg;
267 if (curarg < argc)
268 this->wchar_codeset_parameters_.native (argv[curarg]);
271 else if (ACE_OS::strcasecmp (argv[curarg],
272 ACE_TEXT("-ORBCharCodesetTranslator")) == 0)
274 ++curarg;
275 if (curarg < argc)
276 this->char_codeset_parameters_.add_translator (argv[curarg]);
279 /// CodeSet Translators
280 else if (ACE_OS::strcasecmp (argv[curarg],
281 ACE_TEXT("-ORBWCharCodesetTranslator")) == 0)
283 ++curarg;
284 if (curarg < argc)
285 this->wchar_codeset_parameters_.add_translator (argv[curarg]);
287 else if (ACE_OS::strcasecmp (argv[curarg],
288 ACE_TEXT("-ORBConnectionPurgingStrategy")) == 0)
290 ++curarg;
292 if (curarg < argc)
294 ACE_TCHAR* name = argv[curarg];
296 if (ACE_OS::strcasecmp (name,
297 ACE_TEXT("lru")) == 0)
298 this->connection_purging_type_ =
299 TAO_Resource_Factory::LRU;
300 else if (ACE_OS::strcasecmp (name,
301 ACE_TEXT("lfu")) == 0)
302 this->connection_purging_type_ =
303 TAO_Resource_Factory::LFU;
304 else if (ACE_OS::strcasecmp (name,
305 ACE_TEXT("fifo")) == 0)
306 this->connection_purging_type_ =
307 TAO_Resource_Factory::FIFO;
308 else if (ACE_OS::strcasecmp (name,
309 ACE_TEXT("null")) == 0)
310 this->connection_purging_type_ =
311 TAO_Resource_Factory::NOOP;
312 else
313 this->report_option_value_error (ACE_TEXT("-ORBConnectionPurgingStrategy"), name);
316 else if (ACE_OS::strcasecmp (argv[curarg],
317 ACE_TEXT("-ORBConnectionCacheMax")) == 0)
319 ++curarg;
320 if (curarg < argc)
321 this->cache_maximum_ = ACE_OS::atoi (argv[curarg]);
322 else
323 this->report_option_value_error (ACE_TEXT("-ORBConnectionCacheMax"), argv[curarg]);
326 else if (ACE_OS::strcasecmp (argv[curarg],
327 ACE_TEXT("-ORBConnectionCachePurgePercentage")) == 0)
329 ++curarg;
330 if (curarg < argc)
331 this->purge_percentage_ = ACE_OS::atoi (argv[curarg]);
332 else
333 this->report_option_value_error (ACE_TEXT("-ORBConnectionCachePurgePercentage"),
334 argv[curarg]);
336 else if (ACE_OS::strcasecmp (argv[curarg],
337 ACE_TEXT("-ORBIORParser")) == 0)
339 ++curarg;
341 if (curarg < argc)
343 this->add_to_ior_parser_names (ACE_TEXT_ALWAYS_CHAR(argv[curarg]));
347 else if (ACE_OS::strcasecmp (argv[curarg],
348 ACE_TEXT("-ORBConnectionCacheLock")) == 0)
350 ++curarg;
351 if (curarg < argc)
353 ACE_TCHAR* name = argv[curarg];
355 if (ACE_OS::strcasecmp (name,
356 ACE_TEXT("thread")) == 0)
357 this->cached_connection_lock_type_ = TAO_THREAD_LOCK;
358 else if (ACE_OS::strcasecmp (name,
359 ACE_TEXT("null")) == 0)
361 // @@ Bug 940 :This is a sort of hack now. We need to put
362 // this in a common place once we get the common
363 // switch that is documented in bug 940...
364 this->use_locked_data_blocks_ = 0;
365 this->cached_connection_lock_type_ = TAO_NULL_LOCK;
367 else
368 this->report_option_value_error (ACE_TEXT("-ORBConnectionCacheLock"), name);
371 else if (ACE_OS::strcasecmp (argv[curarg],
372 ACE_TEXT("-ORBResourceUsage")) == 0)
374 ++curarg;
375 if (curarg < argc)
377 ACE_TCHAR* name = argv[curarg];
379 if (ACE_OS::strcasecmp (name,
380 ACE_TEXT("eager")) == 0)
381 this->resource_usage_strategy_ = TAO_EAGER;
382 else if (ACE_OS::strcasecmp (name,
383 ACE_TEXT("lazy")) == 0)
385 this->resource_usage_strategy_ = TAO_LAZY;
387 else
388 this->report_option_value_error (ACE_TEXT("-ORBResourceUsage"), name);
391 else if (ACE_OS::strcasecmp (argv[curarg],
392 ACE_TEXT("-ORBFlushingStrategy")) == 0)
394 ++curarg;
395 if (curarg < argc)
397 ACE_TCHAR* name = argv[curarg];
399 if (ACE_OS::strcasecmp (name,
400 ACE_TEXT("leader_follower")) == 0)
401 this->flushing_strategy_type_ = TAO_LEADER_FOLLOWER_FLUSHING;
402 else if (ACE_OS::strcasecmp (name,
403 ACE_TEXT("reactive")) == 0)
404 this->flushing_strategy_type_ = TAO_REACTIVE_FLUSHING;
405 else if (ACE_OS::strcasecmp (name,
406 ACE_TEXT("blocking")) == 0)
407 this->flushing_strategy_type_ = TAO_BLOCKING_FLUSHING;
408 else
409 this->report_option_value_error (ACE_TEXT("-ORBFlushingStrategy"), name);
412 else if (ACE_OS::strcasecmp (argv[curarg],
413 ACE_TEXT ("-ORBMuxedConnectionMax")) == 0)
415 ++curarg;
416 if (curarg < argc)
417 this->max_muxed_connections_ =
418 ACE_OS::atoi (argv[curarg]);
419 else
420 this->report_option_value_error (ACE_TEXT("-ORBMuxedConnectionMax"),
421 argv[curarg]);
423 else if (ACE_OS::strcasecmp (argv[curarg],
424 ACE_TEXT("-ORBDropRepliesDuringShutdown")) == 0)
426 ++curarg;
427 if (curarg < argc)
429 int const tmp = ACE_OS::atoi (argv[curarg]);
431 if (tmp == 0)
432 this->drop_replies_ = false;
433 else
434 this->drop_replies_ = true;
436 else
437 this->report_option_value_error (ACE_TEXT("-ORBDropRepliesDuringShutdown"),
438 argv[curarg]);
440 else if (0 == ACE_OS::strcasecmp (argv[curarg],
441 ACE_TEXT("-ORBOutputCDRAllocator")))
443 ++curarg;
445 if (curarg < argc)
447 ACE_TCHAR const * const current_arg = argv[curarg];
449 if (ACE_OS::strcasecmp (current_arg,
450 ACE_TEXT("mmap")) == 0)
452 #if TAO_HAS_SENDFILE == 1
453 this->output_cdr_allocator_type_ = MMAP_ALLOCATOR;
454 #else
455 TAOLIB_DEBUG ((LM_WARNING,
456 ACE_TEXT ("MMAP allocator unsupport on this platform")));
457 #endif /* TAO_HAS_SENDFILE==1 */
459 else if (ACE_OS::strcasecmp (current_arg,
460 ACE_TEXT("local_memory_pool")) == 0
461 && this->output_cdr_allocator_type_ != DEFAULT)
463 this->output_cdr_allocator_type_ = LOCAL_MEMORY_POOL;
465 else if (ACE_OS::strcasecmp (current_arg,
466 ACE_TEXT("default")) == 0)
468 this->output_cdr_allocator_type_ = DEFAULT;
470 else
472 this->report_option_value_error (
473 ACE_TEXT("-ORBOutputCDRAllocator"), current_arg);
477 else if (0 == ACE_OS::strcasecmp (argv[curarg],
478 ACE_TEXT("-ORBZeroCopyWrite")))
480 #if TAO_HAS_SENDFILE == 1
481 this->output_cdr_allocator_type_ = MMAP_ALLOCATOR;
482 #else
483 TAOLIB_DEBUG ((LM_WARNING,
484 ACE_TEXT ("Zero copy writes unsupported on this platform\n")));
485 #endif /* TAO_HAS_SENDFILE==1 */
487 else if (ACE_OS::strncmp (argv[curarg],
488 ACE_TEXT ("-ORB"),
489 4) == 0)
491 // Can we assume there is an argument after the option?
492 // ++curarg;
493 TAOLIB_ERROR ((LM_ERROR,
494 ACE_TEXT ("TAO (%P|%t) - Default_Resource_Factory - ")
495 ACE_TEXT ("unknown option <%s>\n"),
496 argv[curarg]));
498 else
500 TAOLIB_DEBUG ((LM_DEBUG,
501 ACE_TEXT ("TAO (%P|%t) - Default_Resource_Factory - ")
502 ACE_TEXT ("ignoring option <%s>\n"),
503 argv[curarg]));
507 return 0;
511 TAO_Default_Resource_Factory::get_parser_names (char **&names,
512 int &number_of_names)
514 if (this->parser_names_count_ != 0)
516 // The user used some -ORBIORParser options, just return those.
517 names = this->parser_names_;
518 number_of_names = this->parser_names_count_;
520 return 0;
523 this->parser_names_count_ = 0;
524 #if (TAO_HAS_DDL_PARSER == 1)
525 ++this->parser_names_count_;
526 #endif
527 #if (TAO_HAS_FILE_PARSER == 1)
528 ++this->parser_names_count_;
529 #endif
530 #if (TAO_HAS_CORBALOC_PARSER == 1)
531 ++this->parser_names_count_;
532 #endif
533 #if (TAO_HAS_CORBANAME_PARSER == 1)
534 ++this->parser_names_count_;
535 #endif
536 #if (TAO_HAS_HTTP_PARSER == 1)
537 ++this->parser_names_count_;
538 #endif
539 #if (TAO_HAS_MCAST_PARSER == 1)
540 ++this->parser_names_count_;
541 #endif
542 ACE_NEW_RETURN (this->parser_names_,
543 char *[this->parser_names_count_],
544 -1);
546 CORBA::ULong index = 0;
548 #if (TAO_HAS_DDL_PARSER == 1)
549 this->parser_names_[index] = CORBA::string_dup ("DLL_Parser");
550 ++index;
551 #endif
553 #if (TAO_HAS_FILE_PARSER == 1)
554 this->parser_names_[index] = CORBA::string_dup ("FILE_Parser");
555 ++index;
556 #endif
558 #if (TAO_HAS_CORBALOC_PARSER == 1)
559 this->parser_names_[index] = CORBA::string_dup ("CORBALOC_Parser");
560 ++index;
561 #endif
563 #if (TAO_HAS_CORBANAME_PARSER == 1)
564 this->parser_names_[index] = CORBA::string_dup ("CORBANAME_Parser");
565 ++index;
566 #endif
568 #if (TAO_HAS_MCAST_PARSER == 1)
569 this->parser_names_[index] = CORBA::string_dup ("MCAST_Parser");
570 ++index;
571 #endif
573 #if (TAO_HAS_HTTP_PARSER == 1)
574 this->parser_names_[index] = CORBA::string_dup ("HTTP_Parser");
575 ++index;
576 #endif
578 names = this->parser_names_;
580 number_of_names = index;
582 return 0;
586 TAO_Default_Resource_Factory::add_to_ior_parser_names (const char *curarg)
588 this->parser_names_[this->index_] = CORBA::string_dup (curarg);
590 ++this->index_;
592 return 0;
596 // This is virtual and protected...
598 TAO_Default_Resource_Factory::load_default_protocols ()
600 #if defined (TAO_HAS_IIOP) && (TAO_HAS_IIOP != 0)
601 // If the user did not list any protocols in her svc.conf file
602 // then default to TAO's basic protocols.
603 // You do *NOT* need modify this code to add your own protocol,
604 // instead simply add the following to your svc.conf file:
606 // dynamic PP_Factory Service_Object * LIB:_make_PP_Protocol_Factory() ""
607 // static Resource_Factory "-ORBProtocolFactory PP_Factory"
609 // where "PP_Factory" is the name of your protocol, i.e. the
610 // second argument passed to the ACE_STATIC_SVC_DEFINE macro:
612 // ACE_STATIC_SVC_DEFINE (PP_Protocol_Factory,
613 // ACE_TEXT ("PP_Factory"), ...)
615 // "PP_Protocol_Factory" is the name of your protocol factory
616 // class. A "_make_" is prepended to your protocol factory
617 // class name by the ACE_FACTORY_DECLARE macro. The resulting
618 // factory function "_make_PP_Protocol_Factory()" is what should
619 // be used in the "dynamic" line in your svc.conf file.
621 // LIB is the base name of the shared library that implements
622 // the protocol. The directory containing your library must be
623 // in your library search path, typically defined by the
624 // LD_LIBRARY_PATH environment variable on UNIX systems, and/or
625 // the `/etc/ld.so.conf' file on some UNIX systems. Remember to
626 // run "ldconfig" if you modify `/etc/ld.so.conf'.
628 if (TAO::details::load_protocol_factory <TAO_IIOP_Protocol_Factory> (
629 this->protocol_factories_, "IIOP_Factory") == -1)
630 return -1;
631 #endif /* TAO_HAS_IIOP && TAO_HAS_IIOP != 0 */
633 return 0;
637 TAO_Default_Resource_Factory::init_protocol_factories ()
639 const TAO_ProtocolFactorySetItor end = protocol_factories_.end ();
640 TAO_ProtocolFactorySetItor factory = protocol_factories_.begin ();
642 if (factory == end)
644 return this->load_default_protocols ();
647 for (; factory != end; ++factory)
649 const ACE_CString &name = (*factory)->protocol_name ();
650 (*factory)->factory (
651 ACE_Dynamic_Service<TAO_Protocol_Factory>::instance (name.c_str ()));
652 if ((*factory)->factory () == nullptr)
654 TAOLIB_ERROR_RETURN ((LM_ERROR,
655 ACE_TEXT ("TAO (%P|%t) - Unable to load ")
656 ACE_TEXT ("protocol <%C>, %p\n"),
657 name.c_str (),
658 ACE_TEXT ("")),
659 -1);
662 if (TAO_debug_level > 0)
664 TAOLIB_DEBUG ((LM_DEBUG,
665 ACE_TEXT ("TAO (%P|%t) - Loaded protocol <%C>\n"),
666 name.c_str ()));
670 return 0;
674 TAO_Default_Resource_Factory::use_locked_data_blocks () const
676 return this->use_locked_data_blocks_;
679 TAO_ProtocolFactorySet *
680 TAO_Default_Resource_Factory::get_protocol_factories ()
682 return &protocol_factories_;
685 TAO_Acceptor_Registry *
686 TAO_Default_Resource_Factory::get_acceptor_registry ()
688 TAO_Acceptor_Registry *ar = nullptr;
690 ACE_NEW_RETURN(ar,
691 TAO_Acceptor_Registry,
692 nullptr);
694 return ar;
697 TAO_Connector_Registry *
698 TAO_Default_Resource_Factory::get_connector_registry ()
700 TAO_Connector_Registry *cr = nullptr;
702 ACE_NEW_RETURN(cr,
703 TAO_Connector_Registry,
704 nullptr);
706 return cr;
709 #if (TAO_HAS_TIME_POLICY == 1)
710 TAO_Time_Policy_Manager*
711 TAO_Default_Resource_Factory::time_policy_manager () const
713 // get time policy manager service
714 TAO_Time_Policy_Manager * tpm =
715 ACE_Dynamic_Service<TAO_Time_Policy_Manager>::instance (ACE_TEXT ("Time_Policy_Manager"));
717 if (tpm == nullptr)
719 TAOLIB_ERROR ((LM_ERROR,
720 ACE_TEXT ("TAO (%P|%t) - TAO_Default_Resource_Factory::time_policy_manager: ")
721 ACE_TEXT ("FAILED to retrieve service Time_Policy_Manager\n")));
724 return tpm;
726 #endif /* TAO_HAS_TIME_POLICY */
728 ACE_Timer_Queue *
729 TAO_Default_Resource_Factory::create_timer_queue () const
731 #if (TAO_HAS_TIME_POLICY == 1)
732 TAO_Time_Policy_Manager * tpm = this->time_policy_manager ();
733 if (tpm)
735 return tpm->create_timer_queue ();
737 #endif /* TAO_HAS_TIME_POLICY */
738 return nullptr;
741 void
742 TAO_Default_Resource_Factory::destroy_timer_queue (ACE_Timer_Queue *tmq) const
744 #if (TAO_HAS_TIME_POLICY == 1)
745 TAO_Time_Policy_Manager * tpm = this->time_policy_manager ();
746 if (tpm)
748 tpm->destroy_timer_queue (tmq);
750 #endif /* TAO_HAS_TIME_POLICY */
753 ACE_Reactor_Impl*
754 TAO_Default_Resource_Factory::allocate_reactor_impl () const
756 ACE_Reactor_Impl *impl = nullptr;
757 // get a timer queue (or not) from a possibly configured
758 // time policy
759 TAO_RSF_Timer_Queue_Ptr tmq (*this, this->create_timer_queue ());
760 ACE_NEW_RETURN (impl,
761 ACE_TP_Reactor (ACE::max_handles (),
763 (ACE_Sig_Handler*)nullptr,
764 tmq.get (),
765 this->reactor_mask_signals_,
766 ACE_Select_Reactor_Token::LIFO),
767 nullptr);
768 // safe to release timer queue
769 tmq.release ();
770 return impl;
773 ACE_Reactor *
774 TAO_Default_Resource_Factory::get_reactor ()
776 ACE_Reactor *reactor = nullptr;
777 ACE_NEW_RETURN (reactor,
778 ACE_Reactor (this->allocate_reactor_impl (), 1),
779 nullptr);
781 if (reactor->initialized () == 0)
783 // backup timer queue
784 ACE_Timer_Queue *tmq = reactor->timer_queue ();
785 // clean up reactor
786 delete reactor;
787 reactor = nullptr;
788 // clean up timer queue in case it was created by time policy
789 this->destroy_timer_queue (tmq);
791 else
792 this->dynamically_allocated_reactor_ = true;
794 return reactor;
797 void
798 TAO_Default_Resource_Factory::reclaim_reactor (ACE_Reactor *reactor)
800 if (this->dynamically_allocated_reactor_)
802 // backup timer queue
803 ACE_Timer_Queue *tmq = reactor->timer_queue ();
804 // clean up reactor
805 delete reactor;
806 // clean up timer queue in case it was created by time policy
807 this->destroy_timer_queue (tmq);
812 typedef ACE_Malloc<ACE_LOCAL_MEMORY_POOL,TAO_SYNCH_MUTEX> LOCKED_MALLOC;
813 typedef ACE_Allocator_Adapter<LOCKED_MALLOC> LOCKED_ALLOCATOR_POOL;
814 typedef ACE_New_Allocator LOCKED_ALLOCATOR_NO_POOL;
816 void
817 TAO_Default_Resource_Factory::use_local_memory_pool (bool flag)
819 this->use_local_memory_pool_ = flag;
821 if (this->output_cdr_allocator_type_ == DEFAULT)
822 this->output_cdr_allocator_type_ = LOCAL_MEMORY_POOL;
825 ACE_Allocator *
826 TAO_Default_Resource_Factory::input_cdr_dblock_allocator ()
828 ACE_Allocator *allocator = nullptr;
829 if (use_local_memory_pool_)
831 ACE_NEW_RETURN (allocator,
832 LOCKED_ALLOCATOR_POOL,
833 nullptr);
835 else
837 ACE_NEW_RETURN (allocator,
838 LOCKED_ALLOCATOR_NO_POOL,
839 nullptr);
842 return allocator;
845 ACE_Allocator *
846 TAO_Default_Resource_Factory::input_cdr_buffer_allocator ()
848 ACE_Allocator *allocator = nullptr;
849 if (use_local_memory_pool_)
851 ACE_NEW_RETURN (allocator,
852 LOCKED_ALLOCATOR_POOL,
853 nullptr);
855 else
857 ACE_NEW_RETURN (allocator,
858 LOCKED_ALLOCATOR_NO_POOL,
859 nullptr);
862 return allocator;
865 ACE_Allocator *
866 TAO_Default_Resource_Factory::input_cdr_msgblock_allocator ()
868 ACE_Allocator *allocator = nullptr;
869 if (use_local_memory_pool_)
871 ACE_NEW_RETURN (allocator,
872 LOCKED_ALLOCATOR_POOL,
873 nullptr);
875 else
877 ACE_NEW_RETURN (allocator,
878 LOCKED_ALLOCATOR_NO_POOL,
879 nullptr);
882 return allocator;
886 TAO_Default_Resource_Factory::input_cdr_allocator_type_locked ()
888 return 1;
891 ACE_Allocator*
892 TAO_Default_Resource_Factory::output_cdr_dblock_allocator ()
894 ACE_Allocator *allocator = nullptr;
895 if (use_local_memory_pool_)
897 ACE_NEW_RETURN (allocator,
898 LOCKED_ALLOCATOR_POOL,
899 nullptr);
901 else
903 ACE_NEW_RETURN (allocator,
904 LOCKED_ALLOCATOR_NO_POOL,
905 nullptr);
908 return allocator;
911 ACE_Allocator *
912 TAO_Default_Resource_Factory::output_cdr_buffer_allocator ()
914 ACE_Allocator *allocator = nullptr;
916 switch (this->output_cdr_allocator_type_)
918 case LOCAL_MEMORY_POOL:
919 ACE_NEW_RETURN (allocator,
920 LOCKED_ALLOCATOR_POOL,
921 nullptr);
923 break;
925 #if TAO_HAS_SENDFILE == 1
926 case MMAP_ALLOCATOR:
927 ACE_NEW_RETURN (allocator,
928 TAO_MMAP_Allocator,
929 nullptr);
931 break;
932 #endif /* TAO_HAS_SENDFILE==1 */
934 case DEFAULT:
935 default:
936 ACE_NEW_RETURN (allocator,
937 LOCKED_ALLOCATOR_NO_POOL,
938 nullptr);
940 break;
943 return allocator;
946 ACE_Allocator*
947 TAO_Default_Resource_Factory::output_cdr_msgblock_allocator ()
949 ACE_Allocator *allocator = nullptr;
950 if (use_local_memory_pool_)
952 ACE_NEW_RETURN (allocator,
953 LOCKED_ALLOCATOR_POOL,
954 nullptr);
956 else
958 ACE_NEW_RETURN (allocator,
959 LOCKED_ALLOCATOR_NO_POOL,
960 nullptr);
963 return allocator;
966 ACE_Allocator*
967 TAO_Default_Resource_Factory::amh_response_handler_allocator ()
969 ACE_Allocator *allocator = nullptr;
970 if (use_local_memory_pool_)
972 ACE_NEW_RETURN (allocator,
973 LOCKED_ALLOCATOR_POOL,
974 nullptr);
976 else
978 ACE_NEW_RETURN (allocator,
979 LOCKED_ALLOCATOR_NO_POOL,
980 nullptr);
983 return allocator;
986 ACE_Allocator*
987 TAO_Default_Resource_Factory::ami_response_handler_allocator ()
989 ACE_Allocator *allocator = nullptr;
990 if (use_local_memory_pool_)
992 ACE_NEW_RETURN (allocator,
993 LOCKED_ALLOCATOR_POOL,
994 nullptr);
996 else
998 ACE_NEW_RETURN (allocator,
999 LOCKED_ALLOCATOR_NO_POOL,
1000 nullptr);
1003 return allocator;
1007 TAO_Default_Resource_Factory::cache_maximum () const
1009 return this->cache_maximum_;
1013 TAO_Default_Resource_Factory::purge_percentage () const
1015 return this->purge_percentage_;
1019 TAO_Default_Resource_Factory::max_muxed_connections () const
1021 return this->max_muxed_connections_;
1025 ACE_Lock *
1026 TAO_Default_Resource_Factory::create_cached_connection_lock ()
1028 ACE_Lock *the_lock = nullptr;
1030 if (this->cached_connection_lock_type_ == TAO_NULL_LOCK)
1031 ACE_NEW_RETURN (the_lock,
1032 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>,
1033 nullptr);
1034 else
1035 ACE_NEW_RETURN (the_lock,
1036 ACE_Lock_Adapter<TAO_SYNCH_MUTEX>,
1037 nullptr);
1039 return the_lock;
1043 TAO_Default_Resource_Factory::locked_transport_cache ()
1045 if (this->cached_connection_lock_type_ == TAO_NULL_LOCK)
1046 return 0;
1048 return 1;
1051 TAO_Flushing_Strategy *
1052 TAO_Default_Resource_Factory::create_flushing_strategy ()
1054 TAO_Flushing_Strategy *strategy = nullptr;
1055 if (this->flushing_strategy_type_ == TAO_LEADER_FOLLOWER_FLUSHING)
1056 ACE_NEW_RETURN (strategy,
1057 TAO_Leader_Follower_Flushing_Strategy,
1058 nullptr);
1059 else if (this->flushing_strategy_type_ == TAO_REACTIVE_FLUSHING)
1060 ACE_NEW_RETURN (strategy,
1061 TAO_Reactive_Flushing_Strategy,
1062 nullptr);
1063 else
1064 ACE_NEW_RETURN (strategy,
1065 TAO_Block_Flushing_Strategy,
1066 nullptr);
1067 return strategy;
1070 TAO_Connection_Purging_Strategy *
1071 TAO_Default_Resource_Factory::create_purging_strategy ()
1073 TAO_Connection_Purging_Strategy *strategy = nullptr;
1075 if (this->connection_purging_type_ == TAO_Resource_Factory::LRU)
1077 ACE_NEW_RETURN (strategy,
1078 TAO_LRU_Connection_Purging_Strategy (
1079 this->cache_maximum ()),
1080 nullptr);
1082 else
1084 TAOLIB_ERROR ((LM_ERROR,
1085 ACE_TEXT ("TAO (%P|%t) - ")
1086 ACE_TEXT ("no usable purging strategy ")
1087 ACE_TEXT ("was found.\n")));
1090 return strategy;
1093 TAO_LF_Strategy *
1094 TAO_Default_Resource_Factory::create_lf_strategy ()
1096 TAO_LF_Strategy *strategy = nullptr;
1098 ACE_NEW_RETURN (strategy,
1099 TAO_LF_Strategy_Complete,
1100 nullptr);
1102 return strategy;
1105 TAO_GIOP_Fragmentation_Strategy*
1106 TAO_Default_Resource_Factory::create_fragmentation_strategy (
1107 TAO_Transport * transport,
1108 CORBA::ULong max_message_size) const
1110 TAO_GIOP_Fragmentation_Strategy* strategy = nullptr;
1112 // Minimum GIOP message size is 24 (a multiple of 8):
1113 // 12 GIOP Message Header
1114 // 4 GIOP Fragment Header (request ID)
1115 // + 8 Smallest payload, including padding.
1116 // ---
1117 // 24
1118 static CORBA::ULong const min_message_size = 24;
1120 // GIOP fragments are supported in GIOP 1.1 and better, but TAO only
1121 // supports them in 1.2 or better since GIOP 1.1 fragments do not
1122 // have a fragment message header.
1123 if (transport) // No transport. Cannot fragment.
1125 if (max_message_size < min_message_size
1126 || (TAO_DEF_GIOP_MAJOR == 1 && TAO_DEF_GIOP_MINOR < 2))
1128 // No maximum was set by the user.
1129 ACE_NEW_RETURN (strategy,
1130 TAO_Null_Fragmentation_Strategy,
1131 strategy);
1134 else
1136 ACE_NEW_RETURN (strategy,
1137 TAO_On_Demand_Fragmentation_Strategy (
1138 transport,
1139 max_message_size),
1140 strategy);
1144 return strategy;
1147 void
1148 TAO_Default_Resource_Factory::report_option_value_error (
1149 const ACE_TCHAR* option_name,
1150 const ACE_TCHAR* option_value)
1152 TAOLIB_DEBUG((LM_DEBUG,
1153 ACE_TEXT ("TAO (%P|%t) - Default_Resource_Factory - unknown ")
1154 ACE_TEXT ("argument <%s> for <%s>\n"),
1155 option_value, option_name));
1158 void
1159 TAO_Default_Resource_Factory::disable_factory ()
1161 this->factory_disabled_ = 1;
1162 if (this->options_processed_)
1164 TAOLIB_DEBUG ((LM_WARNING,
1165 ACE_TEXT ("TAO (%P|%t) - Warning: Resource_Factory options ignored\n")
1166 ACE_TEXT ("Default Resource Factory is disabled\n")));
1170 TAO_Codeset_Manager *
1171 TAO_Default_Resource_Factory::codeset_manager()
1173 TAO_Codeset_Manager_Factory_Base *factory =
1174 ACE_Dynamic_Service<TAO_Codeset_Manager_Factory_Base>::instance ("TAO_Codeset");
1176 if (factory == nullptr)
1178 if (TAO_debug_level >= 2)
1179 TAOLIB_DEBUG ((LM_DEBUG,
1180 ACE_TEXT ("TAO (%P|%t) - Default_Resource_Factory")
1181 ACE_TEXT (" - unable to find codeset manager factory.\n")));
1182 return nullptr;
1185 TAO_Codeset_Manager* mgr = factory->create ();
1187 if (mgr == nullptr)
1189 if (TAO_debug_level >= 2)
1190 TAOLIB_DEBUG ((LM_INFO,
1191 ACE_TEXT ("TAO (%P|%t) - Default_Resource_Factory")
1192 ACE_TEXT (" - unable to create codeset manager.\n")));
1193 return nullptr;
1197 std::unique_ptr<TAO_Codeset_Manager> safemgr (mgr);
1199 if (TAO_debug_level >= 1)
1200 TAOLIB_DEBUG ((LM_DEBUG,
1201 ACE_TEXT ("TAO (%P|%t) - Default_Resource_Factory - codeset manager=%@\n"),
1202 mgr));
1204 this->char_codeset_parameters_.apply_to (mgr->char_codeset_descriptor());
1205 this->wchar_codeset_parameters_.apply_to (mgr->wchar_codeset_descriptor());
1207 return safemgr.release ();
1210 TAO_Resource_Factory::Resource_Usage
1211 TAO_Default_Resource_Factory::resource_usage_strategy () const
1213 return this->resource_usage_strategy_;
1216 bool
1217 TAO_Default_Resource_Factory::drop_replies_during_shutdown () const
1219 return this->drop_replies_;
1222 // ****************************************************************
1224 ACE_STATIC_SVC_DEFINE (TAO_Default_Resource_Factory,
1225 ACE_TEXT ("Resource_Factory"),
1226 ACE_SVC_OBJ_T,
1227 &ACE_SVC_NAME (TAO_Default_Resource_Factory),
1228 ACE_Service_Type::DELETE_THIS
1229 | ACE_Service_Type::DELETE_OBJ,
1231 ACE_FACTORY_DEFINE (TAO, TAO_Default_Resource_Factory)
1233 TAO_END_VERSIONED_NAMESPACE_DECL