summaryrefslogtreecommitdiff
path: root/examples/Web_Crawler/Optimal_Cache_Map_Manager_T.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/Web_Crawler/Optimal_Cache_Map_Manager_T.cpp')
-rw-r--r--examples/Web_Crawler/Optimal_Cache_Map_Manager_T.cpp282
1 files changed, 128 insertions, 154 deletions
diff --git a/examples/Web_Crawler/Optimal_Cache_Map_Manager_T.cpp b/examples/Web_Crawler/Optimal_Cache_Map_Manager_T.cpp
index e0ca775f066..e8b1dfa3d59 100644
--- a/examples/Web_Crawler/Optimal_Cache_Map_Manager_T.cpp
+++ b/examples/Web_Crawler/Optimal_Cache_Map_Manager_T.cpp
@@ -12,6 +12,7 @@
#endif /* ACE_LACKS_PRAGMA_ONCE */
#include "ace/Malloc.h"
+#include "ace/Service_Config.h"
#if !defined (__ACE_INLINE__)
#include "Optimal_Cache_Map_Manager_T.i"
@@ -19,34 +20,36 @@
ACE_RCSID(Web_Crawler, Optimal_Cache_Map_Manager_T, "$Id$")
+ACE_ALLOC_HOOK_DEFINE(ACE_Pair)
+
+ACE_ALLOC_HOOK_DEFINE(ACE_Reference_Pair)
+
ACE_ALLOC_HOOK_DEFINE(ACE_Optimal_Cache_Map_Manager)
ACE_ALLOC_HOOK_DEFINE(ACE_Optimal_Cache_Map_Iterator)
ACE_ALLOC_HOOK_DEFINE(ACE_Optimal_Cache_Map_Reverse_Iterator)
-
+
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::bind (const KEY &key,
const VALUE &value)
{
- // Insert an entry which has the <key> and the <cache_value> which
- // is the combination of the <value> and the attributes of the
- // caching strategy.
- CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
-
- int bind_result = this->map_.bind (key,
- cache_value);
+ // Insert a entry which has the <key> and the <cache_value> which is
+ // the combination of the <value> and the attributes of the caching strategy.
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value (value,
+ this->caching_strategy_.attributes ());
+
+ int bind_result =this->map_.bind (key,
+ cache_value);
if (bind_result != -1)
{
- int result = this->caching_strategy_.notify_bind (bind_result,
+ int result = this->caching_strategy_.notify_bind (bind_result,
cache_value.second ());
if (result == -1)
{
- this->map_.unbind (key);
-
- // Unless the notification goes thru the bind operation is
- // not complete.
+ this->map_.unbind (key,
+ cache_value);
+ // Unless the notification goes thru the bind operation is not complete.
bind_result = -1;
}
}
@@ -59,25 +62,23 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::CACHE_ENTRY *&entry)
{
// Insert a entry which has the <key> and the <cache_value> which is
- // the combination of the <value> and the attributes of the caching
- // strategy.
- CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
-
- int bind_result = this->map_.bind (key,
- cache_value,
- entry);
+ // the combination of the <value> and the attributes of the caching strategy.
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value (value,
+ this->caching_strategy_.attributes ());
+
+ int bind_result =this->map_.bind (key,
+ cache_value,
+ entry);
if (bind_result != -1)
{
- int result = this->caching_strategy_.notify_bind (bind_result,
+ int result = this->caching_strategy_.notify_bind (bind_result,
cache_value.second ());
if (result == -1)
{
- this->map_.unbind (key);
-
- // Unless the notification goes thru the bind operation is
- // not complete.
+ this->map_.unbind (key,
+ cache_value);
+ // Unless the notification goes thru the bind operation is not complete.
bind_result = -1;
}
}
@@ -88,26 +89,23 @@ template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACH
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::rebind (const KEY &key,
const VALUE &value)
{
- CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
-
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value (value,
+ this->caching_strategy_.attributes ());
int rebind_result = this->map_.rebind (key,
cache_value);
if (rebind_result != -1)
{
- int result = this->caching_strategy_.notify_rebind (rebind_result,
+ int result = this->caching_strategy_.notify_rebind (rebind_result,
cache_value.second ());
if (result == -1)
{
- this->map_.unbind (key);
-
- // Unless the notification goes thru the rebind operation is
- // not complete.
+ this->map_.unbind (key,
+ cache_value);
+ // Unless the notification goes thru the rebind operation is not complete.
rebind_result = -1;
}
}
-
- return rebind_result;
+ return rebind_result;
}
@@ -116,34 +114,29 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
const VALUE &value,
VALUE &old_value)
{
- CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
-
- CACHE_VALUE old_cache_value (old_value,
- this->caching_strategy_.attributes ());
-
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value (value,
+ this->caching_strategy_.attributes ());
+ ACE_Pair<VALUE, ATTRIBUTES> old_cache_value (old_value,
+ this->caching_strategy_.attributes ());
int rebind_result = this->map_.rebind (key,
cache_value,
old_cache_value);
if (rebind_result != -1)
{
- int result = this->caching_strategy_.notify_rebind (rebind_result,
+ int result = this->caching_strategy_.notify_rebind (rebind_result,
cache_value.second ());
-
+
if (result == -1)
{
- this->map_.unbind (key);
-
- // Unless the notification goes thru the rebind operation is
- // not complete.
+ this->map_.unbind (key,
+ cache_value);
+ // Unless the notification goes thru the rebind operation is not complete.
rebind_result = -1;
}
else
- {
- old_value = old_cache_value.first ();
- }
+ old_value = old_cache_value.first ();
}
- return rebind_result;
+ return rebind_result;
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
@@ -152,35 +145,30 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
KEY &old_key,
VALUE &old_value)
{
- CACHE_VALUE cache_value (value,
- this->caching_strategy_.attributes ());
-
- CACHE_VALUE old_cache_value (old_value,
- this->caching_strategy_.attributes ());
-
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value (value,
+ this->caching_strategy_.attributes ());
+ ACE_Pair<VALUE, ATTRIBUTES> old_cache_value (old_value,
+ this->caching_strategy_.attributes ());
int rebind_result = this->map_.rebind (key,
cache_value,
old_key,
old_cache_value);
if (rebind_result != -1)
{
- int result = this->caching_strategy_.notify_rebind (rebind_result,
+ int result = this->caching_strategy_.notify_rebind (rebind_result,
cache_value.second ());
-
+
if (result == -1)
{
- this->map_.unbind (key);
-
- // Unless the notification goes thru the rebind operation is
- // not complete.
+ this->map_.unbind (key,
+ cache_value);
+ // Unless the notification goes thru the rebind operation is not complete.
rebind_result = -1;
}
else
- {
- old_value = old_cache_value.first ();
- }
+ old_value = old_cache_value.first ();
}
- return rebind_result;
+ return rebind_result;
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
@@ -188,38 +176,34 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
const VALUE &value,
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::CACHE_ENTRY *&entry)
{
- CACHE_VALUE cache_value (value,
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value (value,
this->caching_strategy_.attributes ());
-
int rebind_result = this->map_.rebind (key,
cache_value,
entry);
if (rebind_result != -1)
{
- int result = this->caching_strategy_.notify_rebind (rebind_result,
+ int result = this->caching_strategy_.notify_rebind (rebind_result,
cache_value.second ());
if (result == -1)
{
- this->map_.unbind (key);
-
- // Unless the notification goes thru the rebind operation is
- // not complete.
+ this->map_.unbind (key,
+ cache_value);
+ // Unless the notification goes thru the rebind operation is not complete.
rebind_result = -1;
}
}
- return rebind_result;
+ return rebind_result;
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::trybind (const KEY &key,
VALUE &value)
{
- CACHE_VALUE cache_value (value,
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value (value,
this->caching_strategy_.attributes ());
-
int trybind_result = this->map_.trybind (key,
cache_value);
-
if (trybind_result != -1)
{
int result = this->caching_strategy_.notify_trybind (trybind_result,
@@ -229,8 +213,8 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
// If the entry has got inserted into the map, it is removed
// due to failure.
if (trybind_result == 0)
- this->map_.unbind (key);
-
+ this->map_.unbind (key,
+ cache_value);
trybind_result = -1;
}
else
@@ -239,9 +223,9 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
// is overwritten with the value from the map.
if (trybind_result == 1)
value = cache_value.first ();
- }
+ }
+
}
-
return trybind_result;
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
@@ -249,13 +233,11 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
VALUE &value,
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::CACHE_ENTRY *&entry)
{
- CACHE_VALUE cache_value (value,
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value (value,
this->caching_strategy_.attributes ());
-
int trybind_result = this->map_.trybind (key,
cache_value,
entry);
-
if (trybind_result != -1)
{
int result = this->caching_strategy_.notify_trybind (trybind_result,
@@ -265,8 +247,8 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
// If the entry has got inserted into the map, it is removed
// due to failure.
if (trybind_result == 0)
- this->map_.unbind (key);
-
+ this->map_.unbind (key,
+ cache_value);
trybind_result = -1;
}
else
@@ -275,53 +257,50 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
// is overwritten with the value from the map.
if (trybind_result == 1)
value = cache_value.first ();
- }
+ }
+
}
-
return trybind_result;
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::find (const KEY& key,
- VALUE &value)
+ VALUE& value)
{
// Lookup the key and populate the <value>.
- CACHE_VALUE cache_value;
-
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value;
+
int find_result = this->map_.find (key,
cache_value);
-
if (find_result != -1)
- {
- int result = this->caching_strategy_.notify_find (find_result,
- cache_value.second ());
- // Unless the find and notification operations go thru, this
- // method is not successful.
-
- if (result == -1)
- find_result = -1;
- else
- {
- // Since the <cache_value> has now changed after the
- // notification, we need to bind to the map again.
- int rebind_result = this->map_.rebind (key,
- cache_value);
- if (rebind_result == -1)
- find_result = -1;
- else
- value = cache_value.first ();
- }
- }
-
+ {
+ int result = this->caching_strategy_.notify_find (find_result,
+ cache_value.second ());
+ // Unless the find and notification operations go thru, this
+ // method is not successful.
+ if (result == -1)
+ find_result = -1;
+ else
+ {
+ // Since the <cache_value> has now changed after the
+ // notification, we need to bind to the map again.
+ int rebind_result = this->map_.rebind (key,
+ cache_value);
+ if (rebind_result == -1)
+ find_result = -1;
+ else
+ value = cache_value.first ();
+ }
+ }
return find_result;
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
-ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::find (const KEY &key)
+ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::find (const KEY& key)
{
// Lookup the key and populate the <value>.
- CACHE_VALUE cache_value;
-
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value;
+
int find_result = this->map_.find (key,
cache_value);
if (find_result != -1)
@@ -346,44 +325,41 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
-ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::find (const KEY &key,
+ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::find (const KEY& key,
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::CACHE_ENTRY *&entry)
{
- // @@ No rebind in this case!
-
// Lookup the key and populate the <value>.
int find_result = this->map_.find (key,
entry);
if (find_result != -1)
- {
- int result = this->caching_strategy_.notify_find (find_result,
- entry->int_id_.second ());
- // Unless the find and notification operations go thru, this
- // method is not successful.
- if (result == -1)
- find_result = -1;
- else
- {
- // Since the <cache_value> has now changed after the
- // notification, we need to bind to the map again.
- int rebind_result = this->map_.rebind (key,
- entry->int_id_);
- if (rebind_result == -1)
- find_result = -1;
- }
- }
+ {
+ int result = this->caching_strategy_.notify_find (find_result,
+ entry->int_id_.second ());
+ // Unless the find and notification operations go thru, this
+ // method is not successful.
+ if (result == -1)
+ find_result = -1;
+ else
+ {
+ // Since the <cache_value> has now changed after the
+ // notification, we need to bind to the map again.
+ int rebind_result = this->map_.rebind (key,
+ entry->int_id_);
+ if (rebind_result == -1)
+ find_result = -1;
+ }
+ }
return find_result;
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
-ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::unbind (const KEY &key)
+ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::unbind (const KEY& key)
{
- // Remove the entry from the cache.
- CACHE_VALUE cache_value;
-
+ // Remove the entry from the cache.
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value;
int unbind_result = this->map_.unbind (key,
cache_value);
-
+
if (unbind_result != -1)
{
int result = this->caching_strategy_.notify_unbind (unbind_result,
@@ -392,20 +368,19 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
if (result == -1)
unbind_result = -1;
}
-
- return unbind_result;
+ return unbind_result;
}
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> int
-ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::unbind (const KEY &key,
- VALUE &value)
+ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::unbind (const KEY& key,
+ VALUE& value)
{
// Remove the entry from the cache.
- CACHE_VALUE cache_value;
+ ACE_Pair<VALUE, ATTRIBUTES> cache_value;
int unbind_result = this->map_.unbind (key,
cache_value);
-
+
if (unbind_result != -1)
{
int result = this->caching_strategy_.notify_unbind (unbind_result,
@@ -415,7 +390,6 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
else
value = cache_value.first ();
}
-
return unbind_result;
}
@@ -424,7 +398,8 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
{
// Remove the entry from the cache.
int unbind_result = this->map_.unbind (entry);
-
+
+
if (unbind_result != -1)
{
int result = this->caching_strategy_.notify_unbind (unbind_result,
@@ -432,10 +407,9 @@ ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATE
if (result == -1)
unbind_result = -1;
}
-
return unbind_result;
}
-
+
template <class KEY, class VALUE, class HASH_KEY, class COMPARE_KEYS, class CACHING_STRATEGY> void
ACE_Optimal_Cache_Map_Manager<KEY, VALUE, HASH_KEY, COMPARE_KEYS, CACHING_STRATEGY>::dump (void) const
{