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: 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 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 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_; };

DESCRIPTION

This class provides a strategy that suspends and resumes all the Event_Handlers in a Reactor in one fell swoop.

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;
    

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

CONNECTION_MAP connection_cache_;

MUTEX 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

Initialization and termination methods.

Scheduling methods

USAGE

In order to use this appropriately, the user must provide a template specialization for 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:

SEE ALSO

ACE_Hash_Addr.

LIBRARY

ace