active_object_map.cpp
来自「这是广泛使用的通信开源项目,对于大容量,高并发的通讯要求完全能够胜任,他广泛可用」· C++ 代码 · 共 1,161 行 · 第 1/3 页
CPP
1,161 行
// Active_Object_Map.cpp,v 1.6 2002/04/16 18:59:10 ossama Exp
#include "Active_Object_Map.h"
#if !defined (__ACE_INLINE__)
# include "Active_Object_Map.i"
#endif /* __ACE_INLINE__ */
#include "ace/Auto_Ptr.h"
ACE_RCSID(tao, Active_Object_Map, "Active_Object_Map.cpp,v 1.6 2002/04/16 18:59:10 ossama Exp")
TAO_Active_Object_Map::Map_Entry::Map_Entry (void)
: user_id_ (),
system_id_ (),
servant_ (0),
reference_count_ (1),
deactivated_ (0),
priority_ (-1)
{
}
/* static */
size_t TAO_Active_Object_Map::system_id_size_ = 0;
void
TAO_Active_Object_Map::set_system_id_size
(const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters)
{
if (TAO_Active_Object_Map::system_id_size_ == 0)
{
if (creation_parameters.allow_reactivation_of_system_ids_)
{
switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
{
#if (TAO_HAS_MINIMUM_POA_MAPS == 0)
case TAO_LINEAR:
TAO_Active_Object_Map::system_id_size_ =
sizeof (CORBA::ULong);
break;
#endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
case TAO_DYNAMIC_HASH:
default:
TAO_Active_Object_Map::system_id_size_ = sizeof (CORBA::ULong);
break;
}
size_t hint_size = 0;
if (creation_parameters.use_active_hint_in_ids_)
hint_size = ACE_Active_Map_Manager_Key::size ();
TAO_Active_Object_Map::system_id_size_ += hint_size;
}
else
{
switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
{
#if (TAO_HAS_MINIMUM_POA_MAPS == 0)
case TAO_LINEAR:
TAO_Active_Object_Map::system_id_size_ =
sizeof (CORBA::ULong);
break;
case TAO_DYNAMIC_HASH:
TAO_Active_Object_Map::system_id_size_ =
sizeof (CORBA::ULong);
break;
#endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
case TAO_ACTIVE_DEMUX:
default:
TAO_Active_Object_Map::system_id_size_ =
ACE_Active_Map_Manager_Key::size ();
break;
}
}
}
}
TAO_Active_Object_Map::TAO_Active_Object_Map (int user_id_policy,
int unique_id_policy,
int persistent_id_policy,
const TAO_Server_Strategy_Factory::Active_Object_Map_Creation_Parameters &creation_parameters
ACE_ENV_ARG_DECL)
: user_id_map_ (0),
servant_map_ (0),
id_uniqueness_strategy_ (0),
lifespan_strategy_ (0),
id_assignment_strategy_ (0),
id_hint_strategy_ (0),
using_active_maps_ (0)
{
TAO_Active_Object_Map::set_system_id_size (creation_parameters);
TAO_Id_Uniqueness_Strategy *id_uniqueness_strategy = 0;
if (unique_id_policy)
{
ACE_NEW_THROW_EX (id_uniqueness_strategy,
TAO_Unique_Id_Strategy,
CORBA::NO_MEMORY ());
ACE_CHECK;
}
else
{
ACE_NEW_THROW_EX (id_uniqueness_strategy,
TAO_Multiple_Id_Strategy,
CORBA::NO_MEMORY ());
ACE_CHECK;
}
// Give ownership to the auto pointer.
auto_ptr<TAO_Id_Uniqueness_Strategy> new_id_uniqueness_strategy (id_uniqueness_strategy);
TAO_Lifespan_Strategy *lifespan_strategy = 0;
if (persistent_id_policy)
{
ACE_NEW_THROW_EX (lifespan_strategy,
TAO_Persistent_Strategy,
CORBA::NO_MEMORY ());
ACE_CHECK;
}
else
{
ACE_NEW_THROW_EX (lifespan_strategy,
TAO_Transient_Strategy,
CORBA::NO_MEMORY ());
ACE_CHECK;
}
// Give ownership to the auto pointer.
auto_ptr<TAO_Lifespan_Strategy> new_lifespan_strategy (lifespan_strategy);
TAO_Id_Assignment_Strategy *id_assignment_strategy = 0;
if (user_id_policy)
{
ACE_NEW_THROW_EX (id_assignment_strategy,
TAO_User_Id_Strategy,
CORBA::NO_MEMORY ());
ACE_CHECK;
}
else if (unique_id_policy)
{
ACE_NEW_THROW_EX (id_assignment_strategy,
TAO_System_Id_With_Unique_Id_Strategy,
CORBA::NO_MEMORY ());
ACE_CHECK;
}
else
{
ACE_NEW_THROW_EX (id_assignment_strategy,
TAO_System_Id_With_Multiple_Id_Strategy,
CORBA::NO_MEMORY ());
ACE_CHECK;
}
// Give ownership to the auto pointer.
auto_ptr<TAO_Id_Assignment_Strategy> new_id_assignment_strategy (id_assignment_strategy);
TAO_Id_Hint_Strategy *id_hint_strategy = 0;
if ((user_id_policy
|| creation_parameters.allow_reactivation_of_system_ids_)
&& creation_parameters.use_active_hint_in_ids_)
{
this->using_active_maps_ = 1;
ACE_NEW_THROW_EX (id_hint_strategy,
TAO_Active_Hint_Strategy (creation_parameters.active_object_map_size_),
CORBA::NO_MEMORY ());
ACE_CHECK;
}
else
{
ACE_NEW_THROW_EX (id_hint_strategy,
TAO_No_Hint_Strategy,
CORBA::NO_MEMORY ());
ACE_CHECK;
}
// Give ownership to the auto pointer.
auto_ptr<TAO_Id_Hint_Strategy> new_id_hint_strategy (id_hint_strategy);
servant_map *sm = 0;
if (unique_id_policy)
{
switch (creation_parameters.reverse_object_lookup_strategy_for_unique_id_policy_)
{
case TAO_LINEAR:
#if (TAO_HAS_MINIMUM_POA_MAPS == 0)
ACE_NEW_THROW_EX (sm,
servant_linear_map (creation_parameters.active_object_map_size_),
CORBA::NO_MEMORY ());
ACE_CHECK;
break;
#else
ACE_ERROR ((LM_ERROR,
"linear option for -ORBUniqueidPolicyReverseDemuxStrategy "
"not supported with minimum POA maps. "
"Ingoring option to use default... \n"));
/* FALL THROUGH */
#endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
case TAO_DYNAMIC_HASH:
default:
ACE_NEW_THROW_EX (sm,
servant_hash_map (creation_parameters.active_object_map_size_),
CORBA::NO_MEMORY ());
ACE_CHECK;
break;
}
}
// Give ownership to the auto pointer.
auto_ptr<servant_map> new_servant_map (sm);
user_id_map *uim = 0;
if (user_id_policy
|| creation_parameters.allow_reactivation_of_system_ids_)
{
switch (creation_parameters.object_lookup_strategy_for_user_id_policy_)
{
case TAO_LINEAR:
#if (TAO_HAS_MINIMUM_POA_MAPS == 0)
ACE_NEW_THROW_EX (uim,
user_id_linear_map (creation_parameters.active_object_map_size_),
CORBA::NO_MEMORY ());
ACE_CHECK;
break;
#else
ACE_ERROR ((LM_ERROR,
"linear option for -ORBUseridPolicyDemuxStrategy "
"not supported with minimum POA maps. "
"Ingoring option to use default... \n"));
/* FALL THROUGH */
#endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
case TAO_DYNAMIC_HASH:
default:
ACE_NEW_THROW_EX (uim,
user_id_hash_map (creation_parameters.active_object_map_size_),
CORBA::NO_MEMORY ());
ACE_CHECK;
break;
}
}
else
{
switch (creation_parameters.object_lookup_strategy_for_system_id_policy_)
{
#if (TAO_HAS_MINIMUM_POA_MAPS == 0)
case TAO_LINEAR:
ACE_NEW_THROW_EX (uim,
user_id_linear_map (creation_parameters.active_object_map_size_),
CORBA::NO_MEMORY ());
ACE_CHECK;
break;
case TAO_DYNAMIC_HASH:
ACE_NEW_THROW_EX (uim,
user_id_hash_map (creation_parameters.active_object_map_size_),
CORBA::NO_MEMORY ());
ACE_CHECK;
break;
#else
case TAO_LINEAR:
case TAO_DYNAMIC_HASH:
ACE_ERROR ((LM_ERROR,
"linear and dynamic options for -ORBSystemidPolicyDemuxStrategy "
"are not supported with minimum POA maps. "
"Ingoring option to use default... \n"));
/* FALL THROUGH */
#endif /* TAO_HAS_MINIMUM_POA_MAPS == 0 */
case TAO_ACTIVE_DEMUX:
default:
this->using_active_maps_ = 1;
ACE_NEW_THROW_EX (uim,
user_id_active_map (creation_parameters.active_object_map_size_),
CORBA::NO_MEMORY ());
ACE_CHECK;
break;
}
}
// Give ownership to the auto pointer.
auto_ptr<user_id_map> new_user_id_map (uim);
id_uniqueness_strategy->set_active_object_map (this);
lifespan_strategy->set_active_object_map (this);
id_assignment_strategy->set_active_object_map (this);
// Finally everything is fine. Make sure to take ownership away
// from the auto pointer.
this->id_uniqueness_strategy_ = new_id_uniqueness_strategy.release ();
this->lifespan_strategy_ = new_lifespan_strategy.release ();
this->id_assignment_strategy_ = new_id_assignment_strategy.release ();
this->id_hint_strategy_ = new_id_hint_strategy.release ();
this->servant_map_ = new_servant_map.release ();
this->user_id_map_ = new_user_id_map.release ();
}
TAO_Active_Object_Map::~TAO_Active_Object_Map (void)
{
user_id_map::iterator iterator = this->user_id_map_->begin ();
user_id_map::iterator end = this->user_id_map_->end ();
for (;
iterator != end;
++iterator)
{
user_id_map::value_type map_entry = *iterator;
delete map_entry.second ();
}
delete this->id_uniqueness_strategy_;
delete this->lifespan_strategy_;
delete this->id_assignment_strategy_;
delete this->id_hint_strategy_;
delete this->servant_map_;
delete this->user_id_map_;
}
int
TAO_Active_Object_Map::is_user_id_in_map (const PortableServer::ObjectId &user_id,
CORBA::Short priority,
int &priorities_match,
int &deactivated)
{
Map_Entry *entry = 0;
int result = this->user_id_map_->find (user_id,
entry);
if (result == 0)
{
if (entry->servant_ == 0)
{
result = 0;
if (entry->priority_ != priority)
priorities_match = 0;
}
else
{
result = 1;
if (entry->deactivated_)
{
deactivated = 1;
}
}
}
else
{
result = 0;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
TAO_Id_Uniqueness_Strategy::~TAO_Id_Uniqueness_Strategy (void)
{
}
void
TAO_Id_Uniqueness_Strategy::set_active_object_map (TAO_Active_Object_Map *active_object_map)
{
this->active_object_map_ = active_object_map;
}
int
TAO_Unique_Id_Strategy::is_servant_in_map (PortableServer::Servant servant,
int &deactivated)
{
TAO_Active_Object_Map::Map_Entry *entry = 0;
int result = this->active_object_map_->servant_map_->find (servant,
entry);
if (result == 0)
{
result = 1;
if (entry->deactivated_)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?