diff options
-rw-r--r-- | ace/Cached_Connect_Strategy_T.cpp | 182 | ||||
-rw-r--r-- | ace/Cached_Connect_Strategy_T.h | 107 |
2 files changed, 16 insertions, 273 deletions
diff --git a/ace/Cached_Connect_Strategy_T.cpp b/ace/Cached_Connect_Strategy_T.cpp index 706f382ebfc..d0cc6e6d768 100644 --- a/ace/Cached_Connect_Strategy_T.cpp +++ b/ace/Cached_Connect_Strategy_T.cpp @@ -26,23 +26,23 @@ template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::ACE_Cached_Connect_Strategy_Ex (ACE_Creation_Strategy<SVC_HANDLER> *cre_s, ACE_Concurrency_Strategy<SVC_HANDLER> *con_s, - ACE_Recycling_Strategy<SVC_HANDLER> *rec_s) - : creation_strategy_ (0), - delete_creation_strategy_ (0), - concurrency_strategy_ (0), - delete_concurrency_strategy_ (0), - recycling_strategy_ (0), - delete_recycling_strategy_ (0) + ACE_Recycling_Strategy<SVC_HANDLER> *rec_s, + MUTEX *mutex = 0, + int delete_mutex = 0) + : ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX> (cre_s, + con_s, + rec_s, + mutex, + delete_mutex) { - if (this->open (cre_s, con_s, rec_s) == -1) - ACE_ERROR ((LM_ERROR, - ASYS_TEXT ("%p\n"), - ASYS_TEXT ("ACE_Cached_Connect_Strategy_Ex::ACE_Cached_Connect_Strategy_Ex"))); } template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::~ACE_Cached_Connect_Strategy_Ex (void) { + if (this->delete_lock_) + delete this->lock_; + if (this->delete_creation_strategy_) delete this->creation_strategy_; this->delete_creation_strategy_ = 0; @@ -83,11 +83,11 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE ACE_Concurrency_Strategy<SVC_HANDLER> *con_s, ACE_Recycling_Strategy<SVC_HANDLER> *rec_s) { - // Set up the cleanup strategy for the svc_handler and give it to // the caching_strategy for use. ACE_NEW_RETURN (this->svc_cleanup_strategy_, SVC_CLEANUP_STRATEGY, -1); + ACE_NEW_RETURN (this->caching_strategy_, CACHING_STRATEGY (this->svc_cleanup_strategy_, 0), @@ -359,108 +359,6 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE } -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::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) -{ - int found = 0; - - // This artificial scope is required since we need to let go of the - // lock *before* registering the newly created handler with the - // Reactor. - { - // Synchronization is required here as the setting of the - // recyclable state must be done atomically with the finding and - // binding of the service handler in the cache. - ACE_GUARD_RETURN (MUTEX, ace_mon, this->lock_, -1); - - int result = this->connect_svc_handler_i (sh, - remote_addr, - timeout, - local_addr, - reuse_addr, - flags, - perms, - found); - if (result != 0) - return result; - - } - - // If it is a new connection, activate it. - // - // Note: This activation is outside the scope of the lock of the - // cached connector. This is necessary to avoid subtle deadlock - // conditions with this lock and the Reactor lock. - // - // @@ If an error occurs on activation, we should try to remove this - // entry from the internal table. - - if (!found) - if (this->activate_svc_handler (sh)) - return -1; - - return 0; -} - -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::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) -{ - int found = 0; - - // This artificial scope is required since we need to let go of the - // lock *before* registering the newly created handler with the - // Reactor. - { - // Synchronization is required here as the setting of the - // recyclable state must be done atomically with the finding and - // binding of the service handler in the cache. - ACE_GUARD_RETURN (MUTEX, ace_mon, this->lock_, -1); - - int result = this->connect_svc_handler_i (sh, - remote_addr, - timeout, - local_addr, - reuse_addr, - flags, - perms, - found); - sh_copy = sh; - - if (result != 0) - return result; - - } - - // If it is a new connection, activate it. - // - // Note: This activation is outside the scope of the lock of the - // cached connector. This is necessary to avoid subtle deadlock - // conditions with this lock and the Reactor lock. - // - // @@ If an error occurs on activation, we should try to remove this - // entry from the internal table. - - if (!found) - if (this->activate_svc_handler (sh)) - return -1; - - return 0; -} template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::connect_svc_handler_i @@ -520,16 +418,6 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE return 0; } -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::cache (const void *recycling_act) -{ - // Synchronization is required here as the setting of the recyclable - // state must be done atomically with respect to other threads that - // are querying the cache. - ACE_GUARD_RETURN (MUTEX, ace_mon, this->lock_, -1); - - return this->cache_i (recycling_act); -} template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::cache_i (const void *recycling_act) @@ -544,15 +432,6 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE return 0; } -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::purge (const void *recycling_act) -{ - // Excluded other threads from changing cache while we take this - // entry out. - ACE_GUARD_RETURN (MUTEX, ace_mon, this->lock_, -1); - - return this->purge_i (recycling_act); -} template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::purge_i (const void *recycling_act) @@ -563,15 +442,6 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE return this->connection_cache_.unbind (entry); } -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::mark_as_closed (const void *recycling_act) -{ - // Excluded other threads from changing cache while we take this - // entry out. - ACE_GUARD_RETURN (MUTEX, ace_mon, this->lock_, -1); - - return this->mark_as_closed_i (recycling_act); -} template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::mark_as_closed_i (const void *recycling_act) @@ -586,16 +456,6 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE } template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::cleanup_hint (const void *recycling_act) -{ - // Excluded other threads from changing cache while we take this - // entry out. - ACE_GUARD_RETURN (MUTEX, ace_mon, this->lock_, -1); - - return this->cleanup_hint_i (recycling_act); -} - -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> int ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::cleanup_hint_i (const void *recycling_act) { // The wonders and perils of ACT @@ -617,24 +477,6 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE return 0; } -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> ACE_Creation_Strategy<SVC_HANDLER> * -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::creation_strategy (void) const -{ - return this->creation_strategy_; -} - -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> ACE_Recycling_Strategy<SVC_HANDLER> * -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::recycling_strategy (void) const -{ - return this->recycling_strategy_; -} - -template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> ACE_Concurrency_Strategy<SVC_HANDLER> * -ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, MUTEX>::concurrency_strategy (void) const -{ - return this->concurrency_strategy_; -} - ACE_ALLOC_HOOK_DEFINE(ACE_Cached_Connect_Strategy_Ex) #endif /* CACHED_CONNECT_STRATEGY_T_C */ diff --git a/ace/Cached_Connect_Strategy_T.h b/ace/Cached_Connect_Strategy_T.h index f6c76d3ce15..4a6263faed7 100644 --- a/ace/Cached_Connect_Strategy_T.h +++ b/ace/Cached_Connect_Strategy_T.h @@ -29,8 +29,7 @@ #include "ace/Synch.h" template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class MUTEX> -class ACE_Cached_Connect_Strategy_Ex : public ACE_Connection_Recycling_Strategy, - public ACE_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2> +class ACE_Cached_Connect_Strategy_Ex : public ACE_Cached_Connect_Strategy< SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX> { // = TITLE // A connection strategy which caches connections to peers @@ -47,7 +46,9 @@ public: ACE_Cached_Connect_Strategy_Ex (ACE_Creation_Strategy<SVC_HANDLER> *cre_s = 0, ACE_Concurrency_Strategy<SVC_HANDLER> *con_s = 0, - ACE_Recycling_Strategy<SVC_HANDLER> *rec_s = 0); + ACE_Recycling_Strategy<SVC_HANDLER> *rec_s = 0, + MUTEX *mutex = 0, + int delete_mutex = 0); // Constructor virtual ~ACE_Cached_Connect_Strategy_Ex (void); @@ -60,22 +61,6 @@ public: // This methods allow you to change the strategies used by the // cached connector. - virtual int make_svc_handler (SVC_HANDLER *&sh); - // Template method for making a new <svc_handler> - - virtual int activate_svc_handler (SVC_HANDLER *svc_handler); - // Template method for activating a new <svc_handler> - - virtual int assign_recycler (SVC_HANDLER *svc_handler, - ACE_Connection_Recycling_Strategy *recycler, - const void *recycling_act); - // Template method for setting the recycler information of the - // svc_handler. - - - virtual int prepare_for_recycling (SVC_HANDLER *svc_handler); - // Template method for preparing the svc_handler for recycling. - virtual int connect (SVC_HANDLER *&sh, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, @@ -91,58 +76,6 @@ public: // the descriptors which get used in the connect process and hence // the connect operation can succeed. - 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); - // Checks to see if there is already a <SVC_HANDLER> in the cache - // connected to the <remote_addr>. If so, we return this pointer. - // Otherwise we establish the connection, put it into the cache, and - // return the <SVC_HANDLER> pointer. <[NOTE]>: the <{reuse_addr}> - // argument does NOT control re-use of addresses in the cache. - // Rather, if the underlying protocol requires a "dead time" prior - // to re-use of its addresses (TCP is a classic example of this), - // <{and}> the protocol provides a means by which to defeat the dead - // time, setting this argument to non-zero will defeat the dead-time - // requirement. - - virtual int purge (const void *recycling_act); - // Remove from cache. - - virtual int cache (const void *recycling_act); - // Add to cache. - - virtual int mark_as_closed (const void *recycling_act); - // Mark as closed. - - virtual int cleanup_hint (const void *recycling_act); - - // Cleanup hint. - - // = 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; @@ -162,11 +95,6 @@ public: typedef ACE_Svc_Cleanup_Strategy<ACE_Hash_Map_Manager_Ex<REFCOUNTED_HASH_RECYCLABLE_ADDRESS, ACE_Pair<SVC_HANDLER *, ATTRIBUTES>, ACE_Hash<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, ACE_Equal_To<REFCOUNTED_HASH_RECYCLABLE_ADDRESS>, MUTEX> > SVC_CLEANUP_STRATEGY; - // = 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; - protected: virtual int purge_i (const void *recycling_act); @@ -198,7 +126,6 @@ protected: const ACE_PEER_CONNECTOR_ADDR &local_addr, int reuse_addr, int flags, - int perms, int &found); @@ -215,32 +142,6 @@ protected: CONNECTION_CACHE connection_cache_; // Table that maintains the cache of connected <SVC_HANDLER>s. - MUTEX lock_; - // Mutual exclusion for this object. - - // = Strategy objects. - - CREATION_STRATEGY *creation_strategy_; - // Creation strategy for an <Connector>. - - int delete_creation_strategy_; - // 1 if <Connector> created the creation strategy and thus should - // delete it, else 0. - - CONCURRENCY_STRATEGY *concurrency_strategy_; - // Concurrency strategy for an <Connector>. - - int delete_concurrency_strategy_; - // 1 if <Connector> created the concurrency strategy and thus should - // delete it, else 0. - - RECYCLING_STRATEGY *recycling_strategy_; - // Recycling strategy for an <Connector>. - - int delete_recycling_strategy_; - // 1 if <Connector> created the recycling strategy and thus should - // delete it, else 0. - SVC_CLEANUP_STRATEGY *svc_cleanup_strategy_; // The strategy which controls the destruction and closing of the // svc_handler. |