summaryrefslogtreecommitdiff
path: root/ace/Cached_Connect_Strategy_T.cpp
diff options
context:
space:
mode:
authorkirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-07-02 17:20:24 +0000
committerkirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-07-02 17:20:24 +0000
commit3fefa0e139238711b1c79dbc84394fa2ed4e97c1 (patch)
treed93a85f880c78150a820e01617b816d5f87ba32f /ace/Cached_Connect_Strategy_T.cpp
parent72ee41f6e1ad213df16e63a13652f7ed312dec85 (diff)
downloadATCD-3fefa0e139238711b1c79dbc84394fa2ed4e97c1.tar.gz
Added purge_connections() for purging explicitly
Diffstat (limited to 'ace/Cached_Connect_Strategy_T.cpp')
-rw-r--r--ace/Cached_Connect_Strategy_T.cpp147
1 files changed, 47 insertions, 100 deletions
diff --git a/ace/Cached_Connect_Strategy_T.cpp b/ace/Cached_Connect_Strategy_T.cpp
index 548cbe846b8..7b9294a2377 100644
--- a/ace/Cached_Connect_Strategy_T.cpp
+++ b/ace/Cached_Connect_Strategy_T.cpp
@@ -3,12 +3,15 @@
#ifndef CACHED_CONNECT_STRATEGY_T_C
#define CACHED_CONNECT_STRATEGY_T_C
+#define ACE_BUILD_DLL
+
+#include "ace/Cached_Connect_Strategy_T.h"
+
#if !defined (ACE_LACKS_PRAGMA_ONCE)
#define ACE_LACKS_PRAGMA_ONCE
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "ace/ACE.h"
-#include "ace/Cached_Connect_Strategy_T.h"
#include "ace/Service_Repository.h"
#include "ace/Synch.h"
#include "ace/Service_Types.h"
@@ -22,42 +25,24 @@
ACE_RCSID(ace, Cached_Connect_Strategy_T, "$Id$")
-template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX>
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX>
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, 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,
- MUTEX *mutex,
- int delete_mutex)
- : ACE_Cached_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2, MUTEX> (cre_s,
- con_s,
- rec_s,
- mutex,
- delete_mutex)
+ MUTEX *lock,
+ int delete_lock)
+ : CCSBASE (cre_s, con_s, rec_s, lock, delete_lock)
{
+ 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<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>\n")));
}
-template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX>
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX>
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, 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;
- this->creation_strategy_ = 0;
-
- if (this->delete_concurrency_strategy_)
- delete this->concurrency_strategy_;
- this->delete_concurrency_strategy_ = 0;
- this->concurrency_strategy_ = 0;
-
- if (this->delete_recycling_strategy_)
- delete this->recycling_strategy_;
- this->delete_recycling_strategy_ = 0;
- this->recycling_strategy_ = 0;
-
delete this->svc_cleanup_strategy_;
this->svc_cleanup_strategy_ = 0;
@@ -77,12 +62,18 @@ 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 ATTRIBUTES, class MUTEX> int
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::open
(ACE_Creation_Strategy<SVC_HANDLER> *cre_s,
ACE_Concurrency_Strategy<SVC_HANDLER> *con_s,
ACE_Recycling_Strategy<SVC_HANDLER> *rec_s)
{
+ int result = this->CCSBASE::open (cre_s, con_s, rec_s);
+ if (result == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ ASYS_TEXT ("%p\n"),
+ ASYS_TEXT ("Base initialisation failed\n")),
+ -1);
// 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_,
@@ -99,69 +90,10 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE
0) == -1)
return -1;
- // Initialize the creation strategy.
- // First we decide if we need to clean up.
- if (this->creation_strategy_ != 0 &&
- this->delete_creation_strategy_ != 0 &&
- cre_s != 0)
- {
- delete this->creation_strategy_;
- this->creation_strategy_ = 0;
- this->delete_creation_strategy_ = 0;
- }
-
- if (cre_s != 0)
- this->creation_strategy_ = cre_s;
- else if (this->creation_strategy_ == 0)
- {
- ACE_NEW_RETURN (this->creation_strategy_,
- CREATION_STRATEGY, -1);
- this->delete_creation_strategy_ = 1;
- }
-
- // Initialize the concurrency strategy.
- if (this->concurrency_strategy_ != 0 &&
- this->delete_concurrency_strategy_ != 0 &&
- con_s != 0)
- {
- delete this->concurrency_strategy_;
- this->concurrency_strategy_ = 0;
- this->delete_concurrency_strategy_ = 0;
- }
-
- if (con_s != 0)
- this->concurrency_strategy_ = con_s;
- else if (this->concurrency_strategy_ == 0)
- {
- ACE_NEW_RETURN (this->concurrency_strategy_,
- CONCURRENCY_STRATEGY, -1);
- this->delete_concurrency_strategy_ = 1;
- }
-
- // Initialize the recycling strategy.
-
- if (this->recycling_strategy_ != 0 &&
- this->delete_recycling_strategy_ != 0 &&
- rec_s != 0)
- {
- delete this->recycling_strategy_;
- this->recycling_strategy_ = 0;
- this->delete_recycling_strategy_ = 0;
- }
-
- if (rec_s != 0)
- this->recycling_strategy_ = rec_s;
- else if (this->recycling_strategy_ == 0)
- {
- ACE_NEW_RETURN (this->recycling_strategy_,
- RECYCLING_STRATEGY, -1);
- this->delete_recycling_strategy_ = 1;
- }
-
- return 0;
+ return 0;
}
-template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::check_hint_i
(SVC_HANDLER *&sh,
const ACE_PEER_CONNECTOR_ADDR &remote_addr,
@@ -234,7 +166,7 @@ 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 ATTRIBUTES, class MUTEX> int
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::find_or_create_svc_handler_i
(SVC_HANDLER *&sh,
const ACE_PEER_CONNECTOR_ADDR &remote_addr,
@@ -260,7 +192,7 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE
return -1;
// Connect using the svc_handler.
- if (this->connect (sh,
+ if (this->cached_connect (sh,
remote_addr,
timeout,
local_addr,
@@ -299,8 +231,8 @@ 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 ATTRIBUTES, class MUTEX> int
-ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::connect (SVC_HANDLER *&sh,
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
+ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::cached_connect (SVC_HANDLER *&sh,
const ACE_PEER_CONNECTOR_ADDR &remote_addr,
ACE_Time_Value *timeout,
const ACE_PEER_CONNECTOR_ADDR &local_addr,
@@ -323,6 +255,7 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE
// there is no way for the non-blocking connects to complete and
// for the <Connector> to notify the cache of the completion of
// connect().
+
if (errno == EWOULDBLOCK)
errno = ENOTSUP;
else if (errno == EMFILE)
@@ -332,7 +265,7 @@ ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATE
// are done from the CONNECTION_CACHE. This frees the
// descriptors which get used in the connect process and
// hence the same method is called again!
- if (this->connection_cache_.purge () == -1)
+ if (this->purge_connections (this->caching_strategy_->purge_percent ()) == -1)
return -1;
// Try connecting again.
@@ -360,7 +293,7 @@ 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 ATTRIBUTES, class MUTEX> int
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::connect_svc_handler_i
(SVC_HANDLER *&sh,
const ACE_PEER_CONNECTOR_ADDR &remote_addr,
@@ -419,7 +352,7 @@ 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 ATTRIBUTES, class MUTEX> int
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::cache_i (const void *recycling_act)
{
// The wonders and perils of ACT
@@ -433,7 +366,7 @@ 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 ATTRIBUTES, class MUTEX> int
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::purge_i (const void *recycling_act)
{
// The wonders and perils of ACT
@@ -443,7 +376,7 @@ 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 ATTRIBUTES, class MUTEX> int
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::mark_as_closed_i (const void *recycling_act)
{
// The wonders and perils of ACT
@@ -455,7 +388,7 @@ 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 ATTRIBUTES, class MUTEX> int
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> int
ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::cleanup_hint_i (const void *recycling_act)
{
// The wonders and perils of ACT
@@ -477,6 +410,20 @@ 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 ATTRIBUTES, class MUTEX> int
+ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::purge_connections (double percentage)
+{
+ // Set the percentage of entries to remove and then call purge on the cache.
+ this->caching_strategy_->purge_percent (percentage);
+ return this->connection_cache_.purge ();
+}
+
+template <class SVC_HANDLER, ACE_PEER_CONNECTOR_1, class CACHING_STRATEGY, class ATTRIBUTES, class MUTEX> CACHING_STRATEGY &
+ACE_Cached_Connect_Strategy_Ex<SVC_HANDLER, ACE_PEER_CONNECTOR_2, CACHING_STRATEGY, ATTRIBUTES, MUTEX>::caching_strategy (void)
+{
+ return *this->caching_strategy_;
+}
+
ACE_ALLOC_HOOK_DEFINE(ACE_Cached_Connect_Strategy_Ex)
#endif /* CACHED_CONNECT_STRATEGY_T_C */