SVC_HANDLER instances), thereby allowing
subsequent re-use of unused, but available, connections.
#include <ace/ACE_Strategies_T.h>
template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class MUTEX> class ACE_Cached_Connect_Strategy : public ACE_Connection_Recycling_Strategy, public ACE_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2> {
public:ACE_Cached_Connect_Strategy ( ACE_Creation_Strategy<SVC_HANDLER> *cre_s = 0, ACE_Concurrency_Strategy<SVC_HANDLER> *con_s = 0, ACE_Recycling_Strategy<SVC_HANDLER> *rec_s = 0 );virtual ~ACE_Cached_Connect_Strategy (void);virtual int open ( ACE_Creation_Strategy<SVC_HANDLER> *cre_s, ACE_Concurrency_Strategy<SVC_HANDLER> *con_s, ACE_Recycling_Strategy<SVC_HANDLER> *rec_s );virtual int make_svc_handler (SVC_HANDLER *&sh);virtual int activate_svc_handler (SVC_HANDLER *svc_handler);virtual int assign_recycler ( SVC_HANDLER *svc_handler, ACE_Connection_Recycling_Strategy *recycler, const void *recycling_act );virtual int prepare_for_recycling (SVC_HANDLER *svc_handler);virtual int connect_svc_handler ( SVC_HANDLER *&sh, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, const ACE_PEER_CONNECTOR_ADDR &local_addr, int reuse_addr, int flags, int perms );virtual int connect_svc_handler ( SVC_HANDLER *&sh, SVC_HANDLER *&sh_copy, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, const ACE_PEER_CONNECTOR_ADDR &local_addr, int reuse_addr, int flags, int perms );virtual int purge (const void *recycling_act);virtual int cache (const void *recycling_act);virtual int mark_as_closed (const void *recycling_act);virtual int cleanup_hint (const void *recycling_act);typedef ACE_Creation_Strategy<SVC_HANDLER> CREATION_STRATEGY;typedef ACE_Concurrency_Strategy<SVC_HANDLER> CONCURRENCY_STRATEGY;typedef ACE_Recycling_Strategy<SVC_HANDLER> RECYCLING_STRATEGY;typedef ACE_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2> CONNECT_STRATEGY; typedef ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR> REFCOUNTED_HASH_RECYCLABLE_ADDRESS; typedef ACE_Hash_Map_Manager <REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *, ACE_Null_Mutex> CONNECTION_MAP; typedef ACE_Hash_Map_Iterator <REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *, ACE_Null_Mutex> CONNECTION_MAP_ITERATOR; typedef ACE_Hash_Map_Entry<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *> CONNECTION_MAP_ENTRY;virtual ACE_Creation_Strategy<SVC_HANDLER> *creation_strategy ( void ) const;virtual ACE_Recycling_Strategy<SVC_HANDLER> *recycling_strategy ( void ) const;virtual ACE_Concurrency_Strategy<SVC_HANDLER> *concurrency_strategy ( void ) const;protected:virtual int purge_i (const void *recycling_act);virtual int cache_i (const void *recycling_act);virtual int mark_as_closed_i (const void *recycling_act);virtual int cleanup_hint_i (const void *recycling_act);int check_hint_i ( SVC_HANDLER *&sh, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, const ACE_PEER_CONNECTOR_ADDR &local_addr, int reuse_addr, int flags, int perms, ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry, int &found );int connect_svc_handler_i ( SVC_HANDLER *&sh, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, const ACE_PEER_CONNECTOR_ADDR &local_addr, int reuse_addr, int flags, int perms, int &found );int find_or_create_svc_handler_i ( SVC_HANDLER *&sh, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, const ACE_PEER_CONNECTOR_ADDR &local_addr, int reuse_addr, int flags, int perms, ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry, int &found );CONNECTION_MAP connection_cache_;MUTEX lock_;CREATION_STRATEGY *creation_strategy_;int delete_creation_strategy_;CONCURRENCY_STRATEGY *concurrency_strategy_;int delete_concurrency_strategy_;RECYCLING_STRATEGY *recycling_strategy_;int delete_recycling_strategy_;};
ACE_Cached_Connect_Strategy is intended to be used as a
plug-in connection strategy for ACE_Strategy_Connector.
It's added value is re-use of established connections.
typedef ACE_Creation_Strategy<SVC_HANDLER> CREATION_STRATEGY;
typedef ACE_Concurrency_Strategy<SVC_HANDLER> CONCURRENCY_STRATEGY;
typedef ACE_Recycling_Strategy<SVC_HANDLER> RECYCLING_STRATEGY;
typedef ACE_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2> CONNECT_STRATEGY;
typedef ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR> REFCOUNTED_HASH_RECYCLABLE_ADDRESS;
typedef ACE_Hash_Map_Manager <REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *, ACE_Null_Mutex> CONNECTION_MAP;
typedef ACE_Hash_Map_Iterator <REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *, ACE_Null_Mutex> CONNECTION_MAP_ITERATOR;
typedef ACE_Hash_Map_Entry<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, SVC_HANDLER *> CONNECTION_MAP_ENTRY;
virtual ACE_Creation_Strategy<SVC_HANDLER> *creation_strategy (
void
) const;
virtual ACE_Recycling_Strategy<SVC_HANDLER> *recycling_strategy (
void
) const;
virtual ACE_Concurrency_Strategy<SVC_HANDLER> *concurrency_strategy (
void
) const;
int check_hint_i (
SVC_HANDLER *&sh,
const ACE_PEER_CONNECTOR_ADDR &remote_addr,
ACE_Time_Value *timeout,
const ACE_PEER_CONNECTOR_ADDR &local_addr,
int reuse_addr,
int flags,
int perms,
ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry,
int &found
);
int connect_svc_handler_i (
SVC_HANDLER *&sh,
const ACE_PEER_CONNECTOR_ADDR &remote_addr,
ACE_Time_Value *timeout,
const ACE_PEER_CONNECTOR_ADDR &local_addr,
int reuse_addr,
int flags,
int perms,
int &found
);
int find_or_create_svc_handler_i (
SVC_HANDLER *&sh,
const ACE_PEER_CONNECTOR_ADDR &remote_addr,
ACE_Time_Value *timeout,
const ACE_PEER_CONNECTOR_ADDR &local_addr,
int reuse_addr,
int flags,
int perms,
ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry,
int &found
);
CONNECTION_MAP connection_cache_;
SVC_HANDLERs.
MUTEX lock_;
CREATION_STRATEGY *creation_strategy_;
Connector.
int delete_creation_strategy_;
Connector created the creation strategy and thus should
delete it, else 0.
CONCURRENCY_STRATEGY *concurrency_strategy_;
Connector.
int delete_concurrency_strategy_;
Connector created the concurrency strategy and thus should
delete it, else 0.
RECYCLING_STRATEGY *recycling_strategy_;
Connector.
int delete_recycling_strategy_;
Connector created the recycling strategy and thus should
delete it, else 0.
ACE_Hash_Addr::compare_i() and
ACE_Hash_Addr::hash_i() based on the address type and the
service handler type. For example, a specialization using
ACE_INET_Addr and My_Service_Handler might be:
size_t
ACE_Hash_Addr<ACE_INET_Addr, My_Service_Handler>::hash_i(const ACE_INET_Addr &a)
{
return ...;
}
ACE_Hash_Addr.