advanced_resource.cpp

Go to the documentation of this file.
00001 // advanced_resource.cpp,v 1.48 2006/04/06 18:21:57 elliott_c Exp
00002 #include "ace/Service_Config.h"
00003 #include "tao/Strategies/advanced_resource.h"
00004 
00005 #include "tao/Strategies/UIOP_Factory.h"
00006 #include "tao/Strategies/SHMIOP_Factory.h"
00007 #include "tao/Strategies/DIOP_Factory.h"
00008 #include "tao/Strategies/SCIOP_Factory.h"
00009 
00010 #include "tao/Strategies/LFU_Connection_Purging_Strategy.h"
00011 #include "tao/Strategies/FIFO_Connection_Purging_Strategy.h"
00012 #include "tao/Strategies/NULL_Connection_Purging_Strategy.h"
00013 
00014 #include "tao/Strategies/LF_Strategy_Null.h"
00015 
00016 #include "tao/debug.h"
00017 #include "tao/LRU_Connection_Purging_Strategy.h"
00018 #include "tao/LF_Strategy_Complete.h"
00019 #include "tao/LF_Follower.h"
00020 #include "tao/Leader_Follower.h"
00021 #include "tao/StringSeqC.h"
00022 #include "tao/ORB_Core.h"
00023 #include "tao/Protocol_Factory.h"
00024 
00025 #include "ace/Arg_Shifter.h"
00026 #include "ace/Auto_Ptr.h"
00027 #include "ace/Dynamic_Service.h"
00028 #include "ace/Service_Config.h"
00029 #include "ace/Select_Reactor.h"
00030 #include "ace/WFMO_Reactor.h"
00031 #include "ace/Msg_WFMO_Reactor.h"
00032 #include "ace/TP_Reactor.h"
00033 #include "ace/Malloc_T.h"
00034 #include "ace/Local_Memory_Pool.h"
00035 #include "ace/Null_Mutex.h"
00036 #include "ace/OS_NS_strings.h"
00037 
00038 ACE_RCSID(Strategies, advanced_resource, "advanced_resource.cpp,v 1.48 2006/04/06 18:21:57 elliott_c Exp")
00039 
00040 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00041 
00042 TAO_Resource_Factory_Changer::TAO_Resource_Factory_Changer (void)
00043 {
00044 
00045   TAO_ORB_Core::set_resource_factory ("Advanced_Resource_Factory");
00046   ACE_Service_Config::process_directive (ace_svc_desc_TAO_Advanced_Resource_Factory);
00047 
00048 #if TAO_HAS_UIOP == 1
00049   ACE_Service_Config::process_directive (ace_svc_desc_TAO_UIOP_Protocol_Factory);
00050 #endif /* TAO_HAS_UIOP == 1 */
00051 
00052 #if TAO_HAS_SHMIOP == 1
00053   ACE_Service_Config::process_directive (ace_svc_desc_TAO_SHMIOP_Protocol_Factory);
00054 #endif /* TAO_HAS_SHMIOP == 1 */
00055 
00056 #if TAO_HAS_DIOP == 1
00057   ACE_Service_Config::process_directive (ace_svc_desc_TAO_DIOP_Protocol_Factory);
00058 #endif /* TAO_HAS_DIOP == 1 */
00059 
00060 #if TAO_HAS_SCIOP == 1
00061   ACE_Service_Config::process_directive (ace_svc_desc_TAO_SCIOP_Protocol_Factory);
00062 #endif /* TAO_HAS_SCIOP == 1 */
00063 
00064 }
00065 
00066 TAO_Advanced_Resource_Factory::TAO_Advanced_Resource_Factory (void)
00067   : reactor_type_ (TAO_REACTOR_TP),
00068     threadqueue_type_ (TAO_THREAD_QUEUE_NOT_SET),
00069     cdr_allocator_type_ (TAO_ALLOCATOR_THREAD_LOCK),
00070     amh_response_handler_allocator_lock_type_ (TAO_ALLOCATOR_THREAD_LOCK),
00071     ami_response_handler_allocator_lock_type_ (TAO_ALLOCATOR_THREAD_LOCK)
00072 {
00073   // Constructor
00074 }
00075 
00076 TAO_Advanced_Resource_Factory::~TAO_Advanced_Resource_Factory (void)
00077 {
00078   // Destructor
00079   TAO_ProtocolFactorySetItor end = this->protocol_factories_.end ();
00080 
00081   for (TAO_ProtocolFactorySetItor iterator =
00082          this->protocol_factories_.begin ();
00083        iterator != end;
00084        ++iterator)
00085     delete *iterator;
00086 
00087   this->protocol_factories_.reset ();
00088 }
00089 
00090 int
00091 TAO_Advanced_Resource_Factory::init (int argc, ACE_TCHAR** argv)
00092 {
00093   ACE_TRACE ("TAO_Advanced_Resource_Factory::init");
00094 
00095   // If this factory has already been disabled then
00096   // print a warning and exit because any options
00097   // are useless
00098   if (this->factory_disabled_) {
00099     ACE_DEBUG ((LM_WARNING,
00100                 ACE_TEXT ("TAO (%P|%t) Warning: Resource_Factory options ignored\n")
00101                 ACE_TEXT ("Advanced Resource Factory is disabled\n")));
00102     return 0;
00103   }
00104   this->options_processed_ = 1;
00105 
00106 
00107   // If the default resource factory exists, then disable it.
00108   // This causes any directives for the "Resource_Factory" to
00109   // report warnings.
00110   // Note: this is also being done in init_protocol_factories()
00111   // to cover the case where init() is not called.
00112   TAO_Resource_Factory *default_resource_factory =
00113     ACE_Dynamic_Service<TAO_Resource_Factory>::instance ("Resource_Factory");
00114   if (default_resource_factory != 0)
00115     {
00116       default_resource_factory->disable_factory ();
00117     }
00118 
00119   ACE_Arg_Shifter arg_shifter (argc, argv);
00120 
00121   //for (int curarg = 0; curarg < argc; ++curarg)
00122   const ACE_TCHAR *current_arg = 0;
00123   while (arg_shifter.is_anything_left ())
00124     {
00125       if (arg_shifter.cur_arg_strncasecmp (ACE_TEXT("-ORBReactorRegistry")) == 0)
00126         {
00127           ACE_ERROR_RETURN ((LM_ERROR,
00128                              ACE_TEXT("TAO_Advanced_Resource_Factory::init - ")
00129                              ACE_TEXT("-ORBReactorRegistry no longer supported\n")),
00130                             -1);
00131 
00132         }
00133       else if (0 != (current_arg = arg_shifter.get_the_parameter
00134                 (ACE_TEXT("-ORBReactorLock"))))
00135         {
00136           ACE_DEBUG ((LM_DEBUG,
00137                       ACE_TEXT("TAO_Advanced_Resource_Factory - obsolete -ORBReactorLock ")
00138                       ACE_TEXT("option, please use -ORBReactorType\n")));
00139 
00140           if (ACE_OS::strcasecmp (current_arg, ACE_TEXT("null")) == 0)
00141             this->reactor_type_ = TAO_REACTOR_SELECT_ST;
00142           else if (ACE_OS::strcasecmp (current_arg, ACE_TEXT("token")) == 0)
00143             this->reactor_type_= TAO_REACTOR_SELECT_MT;
00144 
00145           arg_shifter.consume_arg ();
00146         }
00147       else if (0 != (current_arg = arg_shifter.get_the_parameter
00148                 (ACE_TEXT("-ORBReactorType"))))
00149         {
00150           if (ACE_OS::strcasecmp (current_arg,
00151                                   ACE_TEXT("select_mt")) == 0)
00152             this->reactor_type_ = TAO_REACTOR_SELECT_MT;
00153           else if (ACE_OS::strcasecmp (current_arg,
00154                                        ACE_TEXT("select_st")) == 0)
00155             this->reactor_type_ = TAO_REACTOR_SELECT_ST;
00156           else if (ACE_OS::strcasecmp (current_arg,
00157                                        ACE_TEXT("wfmo")) == 0)
00158 #if defined(ACE_WIN32)
00159             this->reactor_type_ = TAO_REACTOR_WFMO;
00160 #else
00161             this->report_unsupported_error (ACE_TEXT("WFMO Reactor"));
00162 #endif /* ACE_WIN32 */
00163           else if (ACE_OS::strcasecmp (current_arg,
00164                                        ACE_TEXT("msg_wfmo")) == 0)
00165 #if defined(ACE_WIN32)
00166             this->reactor_type_ = TAO_REACTOR_MSGWFMO;
00167 #else
00168             this->report_unsupported_error (ACE_TEXT("MsgWFMO Reactor"));
00169 #endif /* ACE_WIN32 */
00170 
00171           else if (ACE_OS::strcasecmp (current_arg,
00172                                        ACE_TEXT("tp")) == 0)
00173             this->reactor_type_ = TAO_REACTOR_TP;
00174           else if (ACE_OS::strcasecmp (current_arg,
00175                                        ACE_TEXT("fl")) == 0)
00176             this->report_option_value_error (
00177                 ACE_TEXT("FlReactor not supported by Advanced_Resources_Factory. Please use TAO_FlResource_Loader instead."),
00178                          current_arg);
00179           else if (ACE_OS::strcasecmp (current_arg,
00180                                        ACE_TEXT("tk")) == 0)
00181             this->report_option_value_error (
00182                 ACE_TEXT("TkReactor not supported by Advanced_Resources_Factory. Please use TAO_TkResource_Loader instead."),
00183                          current_arg);
00184           else
00185             this->report_option_value_error (ACE_TEXT("-ORBReactorType"), current_arg);
00186 
00187           arg_shifter.consume_arg ();
00188         }
00189       else if (0 != (current_arg = arg_shifter.get_the_parameter
00190                 (ACE_TEXT("-ORBInputCDRAllocator"))))
00191         {
00192           if (ACE_OS::strcasecmp (current_arg,
00193                                   ACE_TEXT("null")) == 0)
00194             {
00195               this->cdr_allocator_type_ = TAO_ALLOCATOR_NULL_LOCK;
00196               this->use_locked_data_blocks_ = 0;
00197             }
00198           else if (ACE_OS::strcasecmp (current_arg,
00199                                        ACE_TEXT("thread")) == 0)
00200             {
00201               this->cdr_allocator_type_ = TAO_ALLOCATOR_THREAD_LOCK;
00202               this->use_locked_data_blocks_ = 1;
00203             }
00204           else
00205             {
00206               this->report_option_value_error (ACE_TEXT("-ORBInputCDRAllocator"), current_arg);
00207             }
00208 
00209           arg_shifter.consume_arg ();
00210         }
00211       else if (0 != (current_arg = arg_shifter.get_the_parameter
00212                 (ACE_TEXT("-ORBAMHResponseHandlerAllocator"))))
00213         {
00214           if (ACE_OS::strcasecmp (current_arg,
00215                                   ACE_TEXT("null")) == 0)
00216             {
00217               this->amh_response_handler_allocator_lock_type_ = TAO_ALLOCATOR_NULL_LOCK;
00218             }
00219           else if (ACE_OS::strcasecmp (current_arg,
00220                                        ACE_TEXT("thread")) == 0)
00221             {
00222               this->amh_response_handler_allocator_lock_type_ = TAO_ALLOCATOR_THREAD_LOCK;
00223             }
00224           else
00225             {
00226               this->report_option_value_error (ACE_TEXT("-ORBAMHResponseHandlerAllocator"), current_arg);
00227             }
00228 
00229           arg_shifter.consume_arg ();
00230         }
00231       else if (0 != (current_arg = arg_shifter.get_the_parameter
00232                 (ACE_TEXT("-ORBAMIResponseHandlerAllocator"))))
00233         {
00234           if (ACE_OS::strcasecmp (current_arg,
00235                                   ACE_TEXT("null")) == 0)
00236             {
00237               this->ami_response_handler_allocator_lock_type_ = TAO_ALLOCATOR_NULL_LOCK;
00238             }
00239           else if (ACE_OS::strcasecmp (current_arg,
00240                                        ACE_TEXT("thread")) == 0)
00241             {
00242               this->ami_response_handler_allocator_lock_type_ = TAO_ALLOCATOR_THREAD_LOCK;
00243             }
00244           else
00245             {
00246               this->report_option_value_error (ACE_TEXT("-ORBAMIResponseHandlerAllocator"), current_arg);
00247             }
00248 
00249           arg_shifter.consume_arg ();
00250         }
00251       else if (0 != (current_arg = arg_shifter.get_the_parameter
00252                 (ACE_TEXT("-ORBReactorThreadQueue"))))
00253         {
00254           if (ACE_OS::strcasecmp (current_arg,
00255                                   ACE_TEXT ("LIFO")) == 0)
00256             this->threadqueue_type_ = TAO_THREAD_QUEUE_LIFO;
00257           else if (ACE_OS::strcasecmp (current_arg,
00258                                        ACE_TEXT ("FIFO")) == 0)
00259             this->threadqueue_type_ = TAO_THREAD_QUEUE_FIFO;
00260           else
00261             this->report_option_value_error (ACE_TEXT ("-ORBReactorThreadQueue"),
00262                                              current_arg);
00263 
00264           arg_shifter.consume_arg ();
00265         }
00266       else
00267         // Any arguments that don't match are ignored so that they can
00268         // be passed to the TAO_Default_Resource_Factory.
00269         arg_shifter.ignore_arg ();
00270     }
00271 
00272   // If -ORBReactorThreadQueue was passed, make sure it matches the
00273   // correct reactor type.  Currently, only the tp reactor can take
00274   // advantage of the LIFO strategy, select_mt hangs.
00275   if (this->threadqueue_type_ != TAO_THREAD_QUEUE_NOT_SET &&
00276       this->reactor_type_ != TAO_REACTOR_TP)
00277     ACE_DEBUG ((LM_DEBUG,
00278                 ACE_TEXT ("TAO_Advanced_Resource_Factory: -ORBReactorThreadQueue ")
00279                 ACE_TEXT ("option can only be used with -ORBReactorType ")
00280                 ACE_TEXT ("tp.\n")));
00281   // Explicitely set the default only if not set.
00282   else if (this->threadqueue_type_ == TAO_THREAD_QUEUE_NOT_SET)
00283     this->threadqueue_type_ = TAO_THREAD_QUEUE_LIFO;
00284 
00285   return this->TAO_Default_Resource_Factory::init (argc, argv);
00286 }
00287 
00288 int
00289 TAO_Advanced_Resource_Factory::load_default_protocols (void)
00290 {
00291   const int r =
00292     this->TAO_Default_Resource_Factory::load_default_protocols ();
00293 
00294   this->protocol_factories_ =
00295     this->TAO_Default_Resource_Factory::protocol_factories_;
00296 
00297   this->TAO_Default_Resource_Factory::protocol_factories_.reset ();
00298 
00299   if (r == -1)
00300     return -1;
00301   // Load the UIOP and SHMIOP protocols...
00302 
00303   return 0;
00304 }
00305 
00306 int
00307 TAO_Advanced_Resource_Factory::init_protocol_factories (void)
00308 {
00309 
00310   // If the default resource factory exists, then disable it.
00311   // This causes any directives for the "Resource_Factory" to
00312   // report warnings.
00313   // This is needed to ensure warnings when no static directive
00314   // for this factory is used (and init() is not called).
00315   TAO_Resource_Factory *default_resource_factory =
00316     ACE_Dynamic_Service<TAO_Resource_Factory>::instance ("Resource_Factory");
00317   if (default_resource_factory != 0)
00318     {
00319       default_resource_factory->disable_factory();
00320     }
00321 
00322   TAO_ProtocolFactorySetItor end = protocol_factories_.end ();
00323   TAO_ProtocolFactorySetItor factory = protocol_factories_.begin ();
00324 
00325   if (factory == end)
00326     {
00327       TAO_Protocol_Factory *protocol_factory = 0;
00328       auto_ptr<TAO_Protocol_Factory> safe_protocol_factory;
00329 
00330       TAO_Protocol_Item *item = 0;
00331 
00332       // If a protocol factory is obtained from the Service
00333       // Configurator then do not transfer ownership to the
00334       // TAO_Protocol_Item.
00335       int transfer_ownership = 0;
00336 
00337       int r = this->load_default_protocols ();
00338 
00339       if (r == -1)
00340         return -1;
00341 
00342 #if TAO_HAS_UIOP == 1
00343       protocol_factory =
00344         ACE_Dynamic_Service<TAO_Protocol_Factory>::instance ("UIOP_Factory");
00345 
00346       if (protocol_factory == 0)
00347         {
00348           if (TAO_debug_level > 0)
00349             ACE_ERROR ((LM_WARNING,
00350                         ACE_TEXT("(%P|%t) WARNING - No %s found in Service Repository.")
00351                         ACE_TEXT("  Using default instance.\n"),
00352                         ACE_TEXT("UIOP Protocol Factory")));
00353 
00354           ACE_NEW_RETURN (protocol_factory,
00355                           TAO_UIOP_Protocol_Factory,
00356                           -1);
00357 
00358           ACE_AUTO_PTR_RESET (safe_protocol_factory,
00359                               protocol_factory,
00360                               TAO_Protocol_Factory);
00361 
00362           transfer_ownership = 1;
00363         }
00364       else
00365         {
00366           transfer_ownership = 0;
00367         }
00368 
00369       ACE_NEW_RETURN (item, TAO_Protocol_Item ("UIOP_Factory"), -1);
00370       // If the TAO_Protocol_Item retains ownership of the
00371       // TAO_Protocol_Factory then we used an auto_ptr<> above, so
00372       // release the TAO_Protocol_Factory from it.  Otherwise, we
00373       // obtained the TAO_Protocol_Factory from the Service
00374       // Configurator so an auto_ptr<> wasn't used since the Service
00375       // Configurator retains ownership, hence there was no need to
00376       // use an auto_ptr<> in this method.
00377       item->factory ((transfer_ownership ?
00378                       safe_protocol_factory.release () :
00379                       protocol_factory),
00380                      transfer_ownership);
00381 
00382       if (this->protocol_factories_.insert (item) == -1)
00383         {
00384           ACE_ERROR ((LM_ERROR,
00385                       ACE_TEXT("TAO (%P|%t) Unable to add ")
00386                       ACE_TEXT("<%s> to protocol factory set.\n"),
00387                       ACE_TEXT_CHAR_TO_TCHAR(item->protocol_name ().c_str ())));
00388 
00389           delete item;
00390 
00391           if (transfer_ownership == 0)
00392             delete protocol_factory;
00393 
00394           return -1;
00395         }
00396 
00397       if (TAO_debug_level > 0)
00398         {
00399           ACE_DEBUG ((LM_DEBUG,
00400                       ACE_TEXT("TAO (%P|%t) Loaded default ")
00401                       ACE_TEXT("protocol <UIOP_Factory>\n")));
00402         }
00403 #endif /* TAO_HAS_UIOP == 1 */
00404 
00405 #if defined (TAO_HAS_SHMIOP) && (TAO_HAS_SHMIOP != 0)
00406       protocol_factory =
00407         ACE_Dynamic_Service<TAO_Protocol_Factory>::instance ("SHMIOP_Factory");
00408 
00409       if (protocol_factory == 0)
00410         {
00411           if (TAO_debug_level > 0)
00412             ACE_ERROR ((LM_WARNING,
00413                         ACE_TEXT("(%P|%t) WARNING - No %s found in Service Repository.")
00414                         ACE_TEXT("  Using default instance.\n"),
00415                         ACE_TEXT("SHMIOP Protocol Factory")));
00416 
00417           ACE_NEW_RETURN (protocol_factory,
00418                           TAO_SHMIOP_Protocol_Factory,
00419                           -1);
00420 
00421           ACE_AUTO_PTR_RESET (safe_protocol_factory,
00422                               protocol_factory,
00423                               TAO_Protocol_Factory);
00424 
00425           transfer_ownership = 1;
00426         }
00427       else
00428         {
00429           transfer_ownership = 0;
00430         }
00431 
00432       ACE_NEW_RETURN (item, TAO_Protocol_Item ("SHMIOP_Factory"), -1);
00433       // If the TAO_Protocol_Item retains ownership of the
00434       // TAO_Protocol_Factory then we used an auto_ptr<> above, so
00435       // release the TAO_Protocol_Factory from it.  Otherwise, we
00436       // obtained the TAO_Protocol_Factory from the Service
00437       // Configurator so an auto_ptr<> wasn't used since the Service
00438       // Configurator retains ownership, hence there was no need to
00439       // use an auto_ptr<> in this method.
00440       item->factory ((transfer_ownership ?
00441                       safe_protocol_factory.release () :
00442                       protocol_factory),
00443                      transfer_ownership);
00444 
00445       if (this->protocol_factories_.insert (item) == -1)
00446         {
00447           ACE_ERROR ((LM_ERROR,
00448                       ACE_TEXT("TAO (%P|%t) Unable to add ")
00449                       ACE_TEXT("<%s> to protocol factory set.\n"),
00450                       ACE_TEXT_CHAR_TO_TCHAR(item->protocol_name ().c_str ())));
00451 
00452           delete item;
00453 
00454           if (transfer_ownership == 0)
00455             delete protocol_factory;
00456 
00457           return -1;
00458         }
00459 
00460       if (TAO_debug_level > 0)
00461         {
00462           ACE_DEBUG ((LM_DEBUG,
00463                       ACE_TEXT("TAO (%P|%t) Loaded default ")
00464                       ACE_TEXT("protocol <SHMIOP_Factory>\n")));
00465         }
00466 #endif /* TAO_HAS_SHMIOP && TAO_HAS_SHMIOP != 0 */
00467 
00468 #if defined (TAO_HAS_DIOP) && (TAO_HAS_DIOP != 0)
00469       protocol_factory =
00470         ACE_Dynamic_Service<TAO_Protocol_Factory>::instance ("DIOP_Factory");
00471 
00472       if (protocol_factory == 0)
00473         {
00474           if (TAO_debug_level > 0)
00475             ACE_ERROR ((LM_WARNING,
00476                         ACE_TEXT("(%P|%t) WARNING - No %s found in Service Repository.")
00477                         ACE_TEXT("  Using default instance.\n"),
00478                         ACE_TEXT("DIOP Protocol Factory")));
00479 
00480           ACE_NEW_RETURN (protocol_factory,
00481                           TAO_DIOP_Protocol_Factory,
00482                           -1);
00483 
00484           ACE_AUTO_PTR_RESET (safe_protocol_factory,
00485                               protocol_factory,
00486                               TAO_Protocol_Factory);
00487 
00488           transfer_ownership = 1;
00489         }
00490       else
00491         {
00492           transfer_ownership = 0;
00493         }
00494 
00495       ACE_NEW_RETURN (item, TAO_Protocol_Item ("DIOP_Factory"), -1);
00496       // If the TAO_Protocol_Item retains ownership of the
00497       // TAO_Protocol_Factory then we used an auto_ptr<> above, so
00498       // release the TAO_Protocol_Factory from it.  Otherwise, we
00499       // obtained the TAO_Protocol_Factory from the Service
00500       // Configurator so an auto_ptr<> wasn't used since the Service
00501       // Configurator retains ownership, hence there was no need to
00502       // use an auto_ptr<> in this method.
00503       item->factory ((transfer_ownership ?
00504                       safe_protocol_factory.release () :
00505                       protocol_factory),
00506                      transfer_ownership);
00507 
00508       if (this->protocol_factories_.insert (item) == -1)
00509         {
00510           ACE_ERROR ((LM_ERROR,
00511                       ACE_TEXT("TAO (%P|%t) Unable to add ")
00512                       ACE_TEXT("<%s> to protocol factory set.\n"),
00513                       ACE_TEXT_CHAR_TO_TCHAR(item->protocol_name ().c_str ())));
00514 
00515           delete item;
00516 
00517           if (transfer_ownership == 0)
00518             delete protocol_factory;
00519 
00520           return -1;
00521         }
00522 
00523       if (TAO_debug_level > 0)
00524         {
00525           ACE_DEBUG ((LM_DEBUG,
00526                       ACE_TEXT("TAO (%P|%t) Loaded default ")
00527                       ACE_TEXT("protocol <DIOP_Factory>\n")));
00528         }
00529 #endif /* TAO_HAS_DIOP && TAO_HAS_DIOP != 0 */
00530 
00531 #if defined (TAO_HAS_SCIOP) && (TAO_HAS_SCIOP != 0)
00532       protocol_factory =
00533         ACE_Dynamic_Service<TAO_Protocol_Factory>::instance ("SCIOP_Factory");
00534 
00535       if (protocol_factory == 0)
00536         {
00537           if (TAO_debug_level > 0)
00538             ACE_ERROR ((LM_WARNING,
00539                         ACE_TEXT("(%P|%t) WARNING - No %s found in Service Repository.")
00540                         ACE_TEXT("  Using default instance.\n"),
00541                         ACE_TEXT("SCIOP Protocol Factory")));
00542 
00543           ACE_NEW_RETURN (protocol_factory,
00544                           TAO_SCIOP_Protocol_Factory,
00545                           -1);
00546 
00547           ACE_AUTO_PTR_RESET (safe_protocol_factory,
00548                               protocol_factory,
00549                               TAO_Protocol_Factory);
00550 
00551           transfer_ownership = 1;
00552         }
00553       else
00554         {
00555           transfer_ownership = 0;
00556         }
00557 
00558       ACE_NEW_RETURN (item, TAO_Protocol_Item ("SCIOP_Factory"), -1);
00559       // If the TAO_Protocol_Item retains ownership of the
00560       // TAO_Protocol_Factory then we used an auto_ptr<> above, so
00561       // release the TAO_Protocol_Factory from it.  Otherwise, we
00562       // obtained the TAO_Protocol_Factory from the Service
00563       // Configurator so an auto_ptr<> wasn't used since the Service
00564       // Configurator retains ownership, hence there was no need to
00565       // use an auto_ptr<> in this method.
00566       item->factory ((transfer_ownership ?
00567                       safe_protocol_factory.release () :
00568                       protocol_factory),
00569                      transfer_ownership);
00570 
00571       if (this->protocol_factories_.insert (item) == -1)
00572         {
00573           ACE_ERROR ((LM_ERROR,
00574                       ACE_TEXT("TAO (%P|%t) Unable to add ")
00575                       ACE_TEXT("<%s> to protocol factory set.\n"),
00576                       ACE_TEXT_CHAR_TO_TCHAR(item->protocol_name ().c_str ())));
00577 
00578           delete item;
00579 
00580           if (transfer_ownership == 0)
00581             delete protocol_factory;
00582 
00583           return -1;
00584         }
00585 
00586       if (TAO_debug_level > 0)
00587         {
00588           ACE_DEBUG ((LM_DEBUG,
00589                       ACE_TEXT("TAO (%P|%t) Loaded default ")
00590                       ACE_TEXT("protocol <SCIOP_Factory>\n")));
00591         }
00592 #endif /* TAO_HAS_SCIOP && TAO_HAS_SCIOP != 0 */
00593 
00594       return 0;
00595 
00596     }
00597 
00598   for (; factory != end; factory++)
00599     {
00600       const ACE_CString &name = (*factory)->protocol_name ();
00601 
00602       (*factory)->factory (
00603         ACE_Dynamic_Service<TAO_Protocol_Factory>::instance (name.c_str ()));
00604       if ((*factory)->factory () == 0)
00605         {
00606           ACE_ERROR_RETURN ((LM_ERROR,
00607                              ACE_TEXT("TAO (%P|%t) Unable to load ")
00608                              ACE_TEXT("protocol <%s>, %m\n"),
00609                              ACE_TEXT_CHAR_TO_TCHAR(name.c_str ())),
00610                             -1);
00611         }
00612 
00613       if (TAO_debug_level > 0)
00614         {
00615           ACE_DEBUG ((LM_DEBUG,
00616                       ACE_TEXT("TAO (%P|%t) Loaded protocol <%s>\n"),
00617                       ACE_TEXT_CHAR_TO_TCHAR(name.c_str ())));
00618         }
00619     }
00620  return 0;
00621 }
00622 
00623 
00624 
00625 TAO_ProtocolFactorySet *
00626 TAO_Advanced_Resource_Factory::get_protocol_factories (void)
00627 {
00628   return &protocol_factories_;
00629 }
00630 
00631 ACE_Reactor_Impl *
00632 TAO_Advanced_Resource_Factory::allocate_reactor_impl (void) const
00633 {
00634   ACE_Reactor_Impl *impl = 0;
00635 
00636   /*
00637    * Hook for specializing the Reactor implementation in TAO.
00638    */
00639 //@@ TAO_ADVANCED_RESOURCE_REACTOR_SPL_COMMENT_HOOK_START
00640   switch (this->reactor_type_)
00641     {
00642     case TAO_REACTOR_SELECT_MT:
00643       ACE_NEW_RETURN (impl,
00644                       TAO_REACTOR ((ACE_Sig_Handler*)0,
00645                                    (ACE_Timer_Queue*)0,
00646                                    0,
00647                                    (ACE_Reactor_Notify*)0,
00648                                    this->reactor_mask_signals_),
00649                       0);
00650       break;
00651 
00652     case TAO_REACTOR_SELECT_ST:
00653       ACE_NEW_RETURN (impl,
00654                       TAO_NULL_LOCK_REACTOR ((ACE_Sig_Handler*)0,
00655                                              (ACE_Timer_Queue*)0,
00656                                              0,
00657                                              (ACE_Reactor_Notify*)0,
00658                                              this->reactor_mask_signals_),
00659                       0);
00660       break;
00661 
00662     case TAO_REACTOR_WFMO:
00663 #if defined(ACE_WIN32) && !defined (ACE_LACKS_MSG_WFMO)
00664       ACE_NEW_RETURN (impl, ACE_WFMO_Reactor, 0);
00665 #endif /* ACE_WIN32 && !ACE_LACKS_MSG_WFMO */
00666       break;
00667 
00668     case TAO_REACTOR_MSGWFMO:
00669 #if defined(ACE_WIN32) && !defined (ACE_HAS_WINCE) && !defined (ACE_HAS_PHARLAP)
00670       ACE_NEW_RETURN (impl, ACE_Msg_WFMO_Reactor, 0);
00671 #endif /* ACE_WIN32 && !ACE_HAS_WINCE */
00672       break;
00673 
00674     default:
00675     case TAO_REACTOR_TP:
00676       ACE_NEW_RETURN (impl, ACE_TP_Reactor ((ACE_Sig_Handler*)0,
00677                                             (ACE_Timer_Queue*)0,
00678                                             this->reactor_mask_signals_,
00679                                             this->threadqueue_type_ == TAO_THREAD_QUEUE_FIFO ?
00680                                               ACE_Select_Reactor_Token::FIFO :
00681                                               ACE_Select_Reactor_Token::LIFO),
00682                       0);
00683       break;
00684     }
00685 
00686 //@@ TAO_ADVANCED_RESOURCE_REACTOR_SPL_COMMENT_HOOK_END
00687 
00688   return impl;
00689 }
00690 
00691 typedef ACE_Malloc<ACE_LOCAL_MEMORY_POOL,ACE_Null_Mutex> NULL_LOCK_MALLOC;
00692 typedef ACE_Allocator_Adapter<NULL_LOCK_MALLOC> NULL_LOCK_ALLOCATOR;
00693 
00694 ACE_Allocator *
00695 TAO_Advanced_Resource_Factory::input_cdr_dblock_allocator (void)
00696 {
00697   ACE_Allocator *allocator = 0;
00698   switch (this->cdr_allocator_type_)
00699     {
00700     case TAO_ALLOCATOR_NULL_LOCK:
00701       ACE_NEW_RETURN (allocator,
00702                       NULL_LOCK_ALLOCATOR,
00703                       0);
00704       break;
00705     default:
00706       return
00707         this->TAO_Default_Resource_Factory::input_cdr_dblock_allocator();
00708     }
00709 
00710   return allocator;
00711 }
00712 
00713 ACE_Allocator *
00714 TAO_Advanced_Resource_Factory::input_cdr_buffer_allocator (void)
00715 {
00716   ACE_Allocator *allocator = 0;
00717   switch (this->cdr_allocator_type_)
00718     {
00719     case TAO_ALLOCATOR_NULL_LOCK:
00720       ACE_NEW_RETURN (allocator,
00721                       NULL_LOCK_ALLOCATOR,
00722                       0);
00723       break;
00724     default:
00725       return
00726         this->TAO_Default_Resource_Factory::input_cdr_buffer_allocator();
00727     }
00728   return allocator;
00729 }
00730 
00731 ACE_Allocator *
00732 TAO_Advanced_Resource_Factory::input_cdr_msgblock_allocator (void)
00733 {
00734   ACE_Allocator *allocator = 0;
00735   switch (this->cdr_allocator_type_)
00736     {
00737     case TAO_ALLOCATOR_NULL_LOCK:
00738       ACE_NEW_RETURN (allocator,
00739                       NULL_LOCK_ALLOCATOR,
00740                       0);
00741       break;
00742     default:
00743       return
00744         this->TAO_Default_Resource_Factory::input_cdr_msgblock_allocator();
00745     }
00746 
00747   return allocator;
00748 }
00749 
00750 ACE_Allocator *
00751 TAO_Advanced_Resource_Factory::amh_response_handler_allocator (void)
00752 {
00753   ACE_Allocator *allocator = 0;
00754   switch (this->amh_response_handler_allocator_lock_type_)
00755     {
00756     case TAO_ALLOCATOR_NULL_LOCK:
00757       ACE_NEW_RETURN (allocator,
00758                       NULL_LOCK_ALLOCATOR,
00759                       0);
00760       break;
00761     default:
00762       return
00763         this->TAO_Default_Resource_Factory::amh_response_handler_allocator();
00764     }
00765 
00766   return allocator;
00767 }
00768 
00769 ACE_Allocator *
00770 TAO_Advanced_Resource_Factory::ami_response_handler_allocator (void)
00771 {
00772   ACE_Allocator *allocator = 0;
00773   switch (this->ami_response_handler_allocator_lock_type_)
00774     {
00775     case TAO_ALLOCATOR_NULL_LOCK:
00776       ACE_NEW_RETURN (allocator,
00777                       NULL_LOCK_ALLOCATOR,
00778                       0);
00779       break;
00780     default:
00781       return
00782         this->TAO_Default_Resource_Factory::ami_response_handler_allocator();
00783     }
00784 
00785   return allocator;
00786 }
00787 
00788 int
00789 TAO_Advanced_Resource_Factory::input_cdr_allocator_type_locked (void)
00790 {
00791   return this->cdr_allocator_type_ == TAO_ALLOCATOR_NULL_LOCK ? 0 : 1;
00792 }
00793 
00794 TAO_Connection_Purging_Strategy *
00795 TAO_Advanced_Resource_Factory::create_purging_strategy (void)
00796 {
00797   TAO_Connection_Purging_Strategy *strategy = 0;
00798 
00799   switch(this->connection_purging_type_)
00800     {
00801     case TAO_Resource_Factory::LFU:
00802       ACE_NEW_RETURN (strategy,
00803                       TAO_LFU_Connection_Purging_Strategy (
00804                                                this->cache_maximum ()),
00805                       0);
00806       break;
00807     case TAO_Resource_Factory::FIFO:
00808       ACE_NEW_RETURN (strategy,
00809                       TAO_FIFO_Connection_Purging_Strategy (
00810                                                this->cache_maximum ()),
00811                       0);
00812       break;
00813     case TAO_Resource_Factory::NOOP:
00814       ACE_NEW_RETURN (strategy,
00815                       TAO_NULL_Connection_Purging_Strategy (
00816                                                this->cache_maximum ()),
00817                       0);
00818       break;
00819     case TAO_Resource_Factory::LRU:
00820       ACE_NEW_RETURN (strategy,
00821                       TAO_LRU_Connection_Purging_Strategy (
00822                                                this->cache_maximum ()),
00823                       0);
00824       break;
00825     default:
00826       ACE_ERROR ((LM_ERROR,
00827                   ACE_TEXT("TAO (%P|%t) - ")
00828                   ACE_TEXT("Unknown connection purging strategy ")
00829                   ACE_TEXT("type was found.\n")));
00830     }
00831 
00832   return strategy;
00833 }
00834 
00835 TAO_LF_Strategy *
00836 TAO_Advanced_Resource_Factory::create_lf_strategy (void)
00837 {
00838   TAO_LF_Strategy *strategy = 0;
00839 
00840   if (this->reactor_type_ == TAO_REACTOR_SELECT_ST)
00841     {
00842       ACE_NEW_RETURN (strategy,
00843                       TAO_LF_Strategy_Null,
00844                       0);
00845     }
00846   else
00847     {
00848       ACE_NEW_RETURN (strategy,
00849                       TAO_LF_Strategy_Complete,
00850                       0);
00851     }
00852   return strategy;
00853 }
00854 
00855 void
00856 TAO_Advanced_Resource_Factory::report_option_value_error (
00857                                  const ACE_TCHAR* option_name,
00858                                  const ACE_TCHAR* option_value)
00859 {
00860   ACE_DEBUG((LM_DEBUG,
00861              ACE_TEXT("Advanced_Resource_Factory - unknown argument")
00862              ACE_TEXT(" <%s> for <%s>\n"),
00863              option_value,
00864              option_name));
00865 }
00866 
00867 void
00868 TAO_Advanced_Resource_Factory::report_unsupported_error (
00869                                  const ACE_TCHAR* option_name)
00870 {
00871   ACE_DEBUG((LM_DEBUG,
00872              ACE_TEXT("Advanced_Resource_Factory - <%s>")
00873              ACE_TEXT(" not supported on this platform\n"),
00874              option_name));
00875 }
00876 
00877 TAO_END_VERSIONED_NAMESPACE_DECL
00878 
00879 // ****************************************************************
00880 
00881 ACE_STATIC_SVC_DEFINE (TAO_Advanced_Resource_Factory,
00882                        ACE_TEXT("Advanced_Resource_Factory"),
00883                        ACE_SVC_OBJ_T,
00884                        &ACE_SVC_NAME (TAO_Advanced_Resource_Factory),
00885                        ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
00886                        0)
00887 ACE_FACTORY_DEFINE (TAO_Strategies, TAO_Advanced_Resource_Factory)
00888 
00889 // ****************************************************************

Generated on Thu Nov 9 13:39:28 2006 for TAO_Strategies by doxygen 1.3.6