NAME

ACE_Cached_Connect_Strategy - A connection strategy which caches connections to peers (represented by SVC_HANDLER instances), thereby allowing subsequent re-use of unused, but available, connections.

SYNOPSIS

#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: typedef ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX> SELF; 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, MUTEX *mutex = 0, int delete_mutex = 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 recycle_state ( const void *recycling_act, ACE_Recyclable_State new_state ); virtual ACE_Recyclable_State recycle_state ( const void *recycling_act ) const; virtual int mark_as_closed (const void *recycling_act); virtual int mark_as_closed_i (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; typedef ACE_Reverse_Lock<MUTEX> REVERSE_MUTEX; 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 new_connection ( 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 find ( ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR> &search_addr, ACE_Hash_Map_Entry<ACE_Refcounted_Hash_Recyclable<ACE_PEER_CONNECTOR_ADDR>, SVC_HANDLER *> *&entry ); virtual int purge_i (const void *recycling_act); virtual int cache_i (const void *recycling_act); virtual int recycle_state_i ( const void *recycling_act, ACE_Recyclable_State new_state ); virtual ACE_Recyclable_State recycle_state_i ( const void *recycling_act ) const; 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 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 ); virtual 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 ); CONNECTION_MAP connection_map_; MUTEX *lock_; int delete_lock_; REVERSE_MUTEX *reverse_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_; };

DESCRIPTION

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.

Define some useful typedefs.

typedef ACE_Creation_Strategy<SVC_HANDLER> CREATION_STRATEGY;

typedef ACE_Concurrency_Strategy<SVC_HANDLER> CONCURRENCY_STRATEGY;

typedef ACE_Recycling_Strategy<SVC_HANDLER> RECYCLING_STRATEGY;

Super class

    typedef ACE_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2> CONNECT_STRATEGY;
    

Typedefs for managing the map

    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;
    

typedef ACE_Reverse_Lock<MUTEX> REVERSE_MUTEX;

Strategy accessors

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;

Helpers

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 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
    );

virtual 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
    );

CONNECTION_MAP connection_map_;

MUTEX *lock_;

int delete_lock_;

REVERSE_MUTEX *reverse_lock_;

Strategy objects.

CREATION_STRATEGY *creation_strategy_;

int delete_creation_strategy_;

CONCURRENCY_STRATEGY *concurrency_strategy_;

int delete_concurrency_strategy_;

RECYCLING_STRATEGY *recycling_strategy_;

int delete_recycling_strategy_;

AUTHOR

Doug Schmidt

LIBRARY

ace