advanced_resource.cpp
字号:
// advanced_resource.cpp,v 1.33 2003/11/04 05:21:38 dhinton Exp
#include "advanced_resource.h"
#if !defined (__ACE_INLINE__)
# include "advanced_resource.i"
#endif /* ! __ACE_INLINE__ */
#include "UIOP_Factory.h"
#include "SHMIOP_Factory.h"
#include "DIOP_Factory.h"
#include "SCIOP_Factory.h"
#include "LFU_Connection_Purging_Strategy.h"
#include "FIFO_Connection_Purging_Strategy.h"
#include "NULL_Connection_Purging_Strategy.h"
#include "LF_Strategy_Null.h"
#include "tao/debug.h"
#include "tao/LRU_Connection_Purging_Strategy.h"
#include "tao/LF_Strategy_Complete.h"
#include "tao/LF_Follower.h"
#include "tao/Leader_Follower.h"
#include "tao/StringSeqC.h"
#include "ace/Arg_Shifter.h"
#include "ace/Auto_Ptr.h"
#include "ace/Dynamic_Service.h"
#include "ace/Service_Config.h"
#include "ace/Select_Reactor.h"
#include "ace/FlReactor.h"
#include "ace/TkReactor.h"
#include "ace/WFMO_Reactor.h"
#include "ace/Msg_WFMO_Reactor.h"
#include "ace/TP_Reactor.h"
#include "ace/Memory_Pool.h"
#include "ace/Null_Mutex.h"
#include "ace/Malloc.h"
#include "ace/OS_NS_strings.h"
ACE_RCSID(Strategies, advanced_resource, "advanced_resource.cpp,v 1.33 2003/11/04 05:21:38 dhinton Exp")
TAO_Resource_Factory_Changer::TAO_Resource_Factory_Changer (void)
{
TAO_ORB_Core::set_resource_factory ("Advanced_Resource_Factory");
ACE_Service_Config::process_directive (ace_svc_desc_TAO_Advanced_Resource_Factory);
#if TAO_HAS_UIOP == 1
ACE_Service_Config::process_directive (ace_svc_desc_TAO_UIOP_Protocol_Factory);
#endif /* TAO_HAS_UIOP == 1 */
#if TAO_HAS_SHMIOP == 1
ACE_Service_Config::process_directive (ace_svc_desc_TAO_SHMIOP_Protocol_Factory);
#endif /* TAO_HAS_SHMIOP == 1 */
#if TAO_HAS_DIOP == 1
ACE_Service_Config::process_directive (ace_svc_desc_TAO_DIOP_Protocol_Factory);
#endif /* TAO_HAS_DIOP == 1 */
#if TAO_HAS_SCIOP == 1
ACE_Service_Config::process_directive (ace_svc_desc_TAO_SCIOP_Protocol_Factory);
#endif /* TAO_HAS_SCIOP == 1 */
}
TAO_Advanced_Resource_Factory::TAO_Advanced_Resource_Factory (void)
: reactor_type_ (TAO_REACTOR_TP),
threadqueue_type_ (TAO_THREAD_QUEUE_NOT_SET),
cdr_allocator_type_ (TAO_ALLOCATOR_THREAD_LOCK)
{
// Constructor
}
TAO_Advanced_Resource_Factory::~TAO_Advanced_Resource_Factory (void)
{
// Destructor
TAO_ProtocolFactorySetItor end = this->protocol_factories_.end ();
for (TAO_ProtocolFactorySetItor iterator =
this->protocol_factories_.begin ();
iterator != end;
++iterator)
delete *iterator;
this->protocol_factories_.reset ();
}
int
TAO_Advanced_Resource_Factory::init (int argc, ACE_TCHAR** argv)
{
ACE_TRACE ("TAO_Advanced_Resource_Factory::init");
// If this factory has already been disabled then
// print a warning and exit because any options
// are useless
if (this->factory_disabled_) {
ACE_DEBUG ((LM_DEBUG,
ACE_LIB_TEXT("TAO (%P|%t) Warning: Resource_Factory options ignored\n")
ACE_LIB_TEXT("Default Resource Factory is disabled\n")));
return 0;
}
this->options_processed_ = 1;
// If the default resource factory exists, then disable it.
// This causes any directives for the "Resource_Factory" to
// report warnings.
// Note: this is also being done in init_protocol_factories()
// to cover the case where init() is not called.
TAO_Resource_Factory *default_resource_factory =
ACE_Dynamic_Service<TAO_Resource_Factory>::instance ("Resource_Factory");
if (default_resource_factory != 0)
{
default_resource_factory->disable_factory();
}
ACE_Arg_Shifter arg_shifter (argc, argv);
//for (int curarg = 0; curarg < argc; ++curarg)
const ACE_TCHAR *current_arg = 0;
while (arg_shifter.is_anything_left ())
{
if (arg_shifter.cur_arg_strncasecmp (ACE_LIB_TEXT("-ORBReactorRegistry")) == 0)
{
ACE_ERROR_RETURN ((LM_ERROR,
ACE_LIB_TEXT("TAO_Advanced_Resource_Factory::init - ")
ACE_LIB_TEXT("-ORBReactorRegistry no longer supported\n")),
-1);
}
else if ((current_arg = arg_shifter.get_the_parameter
(ACE_LIB_TEXT("-ORBReactorLock"))))
{
ACE_DEBUG ((LM_DEBUG,
ACE_LIB_TEXT("TAO_Advanced_Resource_Factory - obsolete -ORBReactorLock ")
ACE_LIB_TEXT("option, please use -ORBReactorType\n")));
if (ACE_OS::strcasecmp (current_arg, ACE_LIB_TEXT("null")) == 0)
this->reactor_type_ = TAO_REACTOR_SELECT_ST;
else if (ACE_OS::strcasecmp (current_arg, ACE_LIB_TEXT("token")) == 0)
this->reactor_type_= TAO_REACTOR_SELECT_MT;
arg_shifter.consume_arg ();
}
else if ((current_arg = arg_shifter.get_the_parameter
(ACE_LIB_TEXT("-ORBReactorType"))))
{
if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT("select_mt")) == 0)
this->reactor_type_ = TAO_REACTOR_SELECT_MT;
else if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT("select_st")) == 0)
this->reactor_type_ = TAO_REACTOR_SELECT_ST;
else if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT("fl")) == 0)
#if defined(ACE_HAS_FL)
this->reactor_type_ = TAO_REACTOR_FL;
#else
this->report_unsupported_error (ACE_LIB_TEXT("FlReactor"));
#endif /* ACE_HAS_FL */
else if (ACE_OS::strcasecmp (current_arg, ACE_LIB_TEXT("tk_reactor")) == 0)
#if defined(ACE_HAS_TK)
this->reactor_type_ = TAO_REACTOR_TK;
#else
this->report_unsupported_error (ACE_LIB_TEXT("TkReactor"));
#endif /* ACE_HAS_TK */
else if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT("wfmo")) == 0)
#if defined(ACE_WIN32)
this->reactor_type_ = TAO_REACTOR_WFMO;
#else
this->report_unsupported_error (ACE_LIB_TEXT("WFMO Reactor"));
#endif /* ACE_WIN32 */
else if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT("msg_wfmo")) == 0)
#if defined(ACE_WIN32)
this->reactor_type_ = TAO_REACTOR_MSGWFMO;
#else
this->report_unsupported_error (ACE_LIB_TEXT("MsgWFMO Reactor"));
#endif /* ACE_WIN32 */
else if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT("tp")) == 0)
this->reactor_type_ = TAO_REACTOR_TP;
else
this->report_option_value_error (ACE_LIB_TEXT("-ORBReactorType"), current_arg);
arg_shifter.consume_arg ();
}
else if ((current_arg = arg_shifter.get_the_parameter
(ACE_LIB_TEXT("-ORBInputCDRAllocator"))))
{
if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT("null")) == 0)
{
this->cdr_allocator_type_ = TAO_ALLOCATOR_NULL_LOCK;
this->use_locked_data_blocks_ = 0;
}
else if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT("thread")) == 0)
{
this->cdr_allocator_type_ = TAO_ALLOCATOR_THREAD_LOCK;
this->use_locked_data_blocks_ = 1;
}
else
{
this->report_option_value_error (ACE_LIB_TEXT("-ORBInputCDRAllocator"), current_arg);
}
arg_shifter.consume_arg ();
}
else if ((current_arg = arg_shifter.get_the_parameter
(ACE_LIB_TEXT("-ORBReactorThreadQueue"))))
{
if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT ("LIFO")) == 0)
this->threadqueue_type_ = TAO_THREAD_QUEUE_LIFO;
else if (ACE_OS::strcasecmp (current_arg,
ACE_LIB_TEXT ("FIFO")) == 0)
this->threadqueue_type_ = TAO_THREAD_QUEUE_FIFO;
else
this->report_option_value_error (ACE_LIB_TEXT ("-ORBReactorThreadQueue"),
current_arg);
arg_shifter.consume_arg ();
}
else
// Any arguments that don't match are ignored so that they can
// be passed to the TAO_Default_Resource_Factory.
arg_shifter.ignore_arg ();
}
// If -ORBReactorThreadQueue was passed, make sure it matches the
// correct reactor type. Currently, only the tp reactor can take
// advantage of the LIFO strategy, select_mt hangs.
if (this->threadqueue_type_ != TAO_THREAD_QUEUE_NOT_SET &&
this->reactor_type_ != TAO_REACTOR_TP)
ACE_DEBUG ((LM_DEBUG,
ACE_LIB_TEXT ("TAO_Advanced_Resource_Factory: -ORBReactorThreadQueue ")
ACE_LIB_TEXT ("option can only be used with -ORBReactorType ")
ACE_LIB_TEXT ("tp (default).\n")));
// Explicitely set the default only if not set.
else if (this->threadqueue_type_ == TAO_THREAD_QUEUE_NOT_SET)
this->threadqueue_type_ = TAO_THREAD_QUEUE_LIFO;
return this->TAO_Default_Resource_Factory::init (argc, argv);
}
int
TAO_Advanced_Resource_Factory::load_default_protocols (void)
{
int r = this->TAO_Default_Resource_Factory::load_default_protocols ();
this->protocol_factories_ =
this->TAO_Default_Resource_Factory::protocol_factories_;
this->TAO_Default_Resource_Factory::protocol_factories_.reset ();
if (r == -1)
return -1;
// Load the UIOP and SHMIOP protocols...
return 0;
}
int
TAO_Advanced_Resource_Factory::init_protocol_factories (void)
{
// If the default resource factory exists, then disable it.
// This causes any directives for the "Resource_Factory" to
// report warnings.
// This is needed to ensure warnings when no static directive
// for this factory is used (and init() is not called).
TAO_Resource_Factory *default_resource_factory =
ACE_Dynamic_Service<TAO_Resource_Factory>::instance ("Resource_Factory");
if (default_resource_factory != 0)
{
default_resource_factory->disable_factory();
}
TAO_ProtocolFactorySetItor end = protocol_factories_.end ();
TAO_ProtocolFactorySetItor factory = protocol_factories_.begin ();
if (factory == end)
{
TAO_Protocol_Factory *protocol_factory = 0;
auto_ptr<TAO_Protocol_Factory> safe_protocol_factory;
TAO_Protocol_Item *item = 0;
// If a protocol factory is obtained from the Service
// Configurator then do not transfer ownership to the
// TAO_Protocol_Item.
int transfer_ownership = 0;
int r = this->load_default_protocols ();
if (r == -1)
return -1;
#if TAO_HAS_UIOP == 1
protocol_factory =
ACE_Dynamic_Service<TAO_Protocol_Factory>::instance ("UIOP_Factory");
if (protocol_factory == 0)
{
if (TAO_debug_level > 0)
ACE_ERROR ((LM_WARNING,
ACE_LIB_TEXT("(%P|%t) WARNING - No %s found in Service Repository.")
ACE_LIB_TEXT(" Using default instance.\n"),
ACE_LIB_TEXT("UIOP Protocol Factory")));
ACE_NEW_RETURN (protocol_factory,
TAO_UIOP_Protocol_Factory,
-1);
ACE_AUTO_PTR_RESET (safe_protocol_factory,
protocol_factory,
TAO_Protocol_Factory);
transfer_ownership = 1;
}
else
{
transfer_ownership = 0;
}
ACE_NEW_RETURN (item, TAO_Protocol_Item ("UIOP_Factory"), -1);
// If the TAO_Protocol_Item retains ownership of the
// TAO_Protocol_Factory then we used an auto_ptr<> above, so
// release the TAO_Protocol_Factory from it. Otherwise, we
// obtained the TAO_Protocol_Factory from the Service
// Configurator so an auto_ptr<> wasn't used since the Service
// Configurator retains ownership, hence there was no need to
// use an auto_ptr<> in this method.
item->factory ((transfer_ownership ?
safe_protocol_factory.release () :
protocol_factory),
transfer_ownership);
if (this->protocol_factories_.insert (item) == -1)
{
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT("TAO (%P|%t) Unable to add ")
ACE_LIB_TEXT("<%s> to protocol factory set.\n"),
ACE_TEXT_CHAR_TO_TCHAR(item->protocol_name ().c_str ())));
delete item;
if (transfer_ownership == 0)
delete protocol_factory;
return -1;
}
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG,
ACE_LIB_TEXT("TAO (%P|%t) Loaded default ")
ACE_LIB_TEXT("protocol <UIOP_Factory>\n")));
}
#endif /* TAO_HAS_UIOP == 1 */
#if defined (TAO_HAS_SHMIOP) && (TAO_HAS_SHMIOP != 0)
protocol_factory =
ACE_Dynamic_Service<TAO_Protocol_Factory>::instance ("SHMIOP_Factory");
if (protocol_factory == 0)
{
if (TAO_debug_level > 0)
ACE_ERROR ((LM_WARNING,
ACE_LIB_TEXT("(%P|%t) WARNING - No %s found in Service Repository.")
ACE_LIB_TEXT(" Using default instance.\n"),
ACE_LIB_TEXT("SHMIOP Protocol Factory")));
ACE_NEW_RETURN (protocol_factory,
TAO_SHMIOP_Protocol_Factory,
-1);
ACE_AUTO_PTR_RESET (safe_protocol_factory,
protocol_factory,
TAO_Protocol_Factory);
transfer_ownership = 1;
}
else
{
transfer_ownership = 0;
}
ACE_NEW_RETURN (item, TAO_Protocol_Item ("SHMIOP_Factory"), -1);
// If the TAO_Protocol_Item retains ownership of the
// TAO_Protocol_Factory then we used an auto_ptr<> above, so
// release the TAO_Protocol_Factory from it. Otherwise, we
// obtained the TAO_Protocol_Factory from the Service
// Configurator so an auto_ptr<> wasn't used since the Service
// Configurator retains ownership, hence there was no need to
// use an auto_ptr<> in this method.
item->factory ((transfer_ownership ?
safe_protocol_factory.release () :
protocol_factory),
transfer_ownership);
if (this->protocol_factories_.insert (item) == -1)
{
ACE_ERROR ((LM_ERROR,
ACE_LIB_TEXT("TAO (%P|%t) Unable to add ")
ACE_LIB_TEXT("<%s> to protocol factory set.\n"),
ACE_TEXT_CHAR_TO_TCHAR(item->protocol_name ().c_str ())));
delete item;
if (transfer_ownership == 0)
delete protocol_factory;
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -