Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tao / Transport_Cache_Manager_T.cpp
blobdbcdc66ed156a9658f9083b93b05b9404095a092
1 #include "tao/Transport_Cache_Manager_T.h"
2 #include "tao/debug.h"
3 #include "tao/Connection_Purging_Strategy.h"
4 #include "tao/Client_Strategy_Factory.h"
5 #include "tao/Condition.h"
6 #include "tao/Wait_Strategy.h"
7 #include "ace/ACE.h"
8 #include "ace/Reactor.h"
9 #include "ace/Lock_Adapter_T.h"
11 #if !defined (__ACE_INLINE__)
12 # include "tao/Transport_Cache_Manager_T.inl"
13 #endif /* __ACE_INLINE__ */
15 // notes on debug level and LM_xxxx codes for transport cache
16 // TAO_debug_level > 0: recoverable error condition (LM_ERROR)
17 // TAO_debug_level > 4: normal transport cache operations (LM_INFO)
18 // TAO_debug_level > 6: detailed cache operations (LM_DEBUG)
19 // TAO_debug_level > 8: for debugging the cache itself (LM_DEBUG)
21 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
23 namespace TAO
25 template <typename TT, typename TRDT, typename PSTRAT>
26 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::Transport_Cache_Manager_T (
27 int percent,
28 purging_strategy* purging_strategy,
29 size_t cache_maximum,
30 bool locked,
31 const char *orbid)
32 : percent_ (percent)
33 , purging_strategy_ (purging_strategy)
34 , cache_map_ (cache_maximum)
35 , cache_lock_ (0)
36 , cache_maximum_ (cache_maximum)
37 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
38 , purge_monitor_ (0)
39 , size_monitor_ (0)
40 #endif /* TAO_HAS_MONITOR_POINTS==1 */
42 if (locked)
44 ACE_NEW (this->cache_lock_,
45 ACE_Lock_Adapter <TAO_SYNCH_MUTEX> (this->cache_map_mutex_));
47 else
49 ACE_NEW (this->cache_lock_,
50 ACE_Lock_Adapter<ACE_SYNCH_NULL_MUTEX>);
53 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
54 ACE_NEW (this->purge_monitor_,
55 ACE::Monitor_Control::Size_Monitor);
56 ACE_NEW (this->size_monitor_,
57 ACE::Monitor_Control::Size_Monitor);
59 ACE_CString purge_name ("Connection_Cache_Purge_");
60 ACE_CString size_name ("Connection_Cache_Size_");
62 purge_name += orbid;
63 size_name += orbid;
65 this->purge_monitor_->name (purge_name.c_str ());
66 this->size_monitor_->name (size_name.c_str ());
68 this->purge_monitor_->add_to_registry ();
69 this->size_monitor_->add_to_registry ();
70 #else
71 ACE_UNUSED_ARG (orbid);
72 #endif /* TAO_HAS_MONITOR_POINTS==1 */
75 template <typename TT, typename TRDT, typename PSTRAT>
76 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::~Transport_Cache_Manager_T ()
78 delete this->cache_lock_;
79 this->cache_lock_ = 0;
81 delete this->purging_strategy_;
82 this->purging_strategy_ = 0;
84 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
85 this->purge_monitor_->remove_from_registry ();
86 this->size_monitor_->remove_from_registry ();
87 this->purge_monitor_->remove_ref ();
88 this->size_monitor_->remove_ref ();
89 #endif /* TAO_HAS_MONITOR_POINTS==1 */
92 template <typename TT, typename TRDT, typename PSTRAT>
93 void
94 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::set_entry_state (HASH_MAP_ENTRY *&entry,
95 TAO::Cache_Entries_State state)
97 ACE_MT (ACE_GUARD (ACE_Lock, guard, *this->cache_lock_));
98 if (entry != 0)
100 entry->item ().recycle_state (state);
101 if (state != ENTRY_UNKNOWN && state != ENTRY_CONNECTING
102 && entry->item ().transport ())
103 entry->item ().is_connected (
104 entry->item ().transport ()->is_connected ());
108 template <typename TT, typename TRDT, typename PSTRAT>
110 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::bind_i (
111 Cache_ExtId &ext_id,
112 Cache_IntId &int_id)
114 if (TAO_debug_level > 4)
116 TAOLIB_DEBUG ((LM_INFO,
117 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i, ")
118 ACE_TEXT ("Transport[%d] @ hash:index{%d:%d}\n"),
119 int_id.transport ()->id (),
120 ext_id.hash (),
121 ext_id.index ()));
124 // Get the entry too
125 HASH_MAP_ENTRY *entry = 0;
127 // Update the purging strategy information while we
128 // are holding our lock
129 this->purging_strategy_->update_item (*(int_id.transport ()));
130 int retval = 0;
131 bool more_to_do = true;
132 while (more_to_do)
134 if (this->cache_map_.current_size () >= cache_maximum_)
136 retval = -1;
137 if (TAO_debug_level > 0)
139 TAOLIB_ERROR ((LM_ERROR,
140 ACE_TEXT("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i, ")
141 ACE_TEXT("ERROR: unable to bind transport, cache is full\n")));
143 more_to_do = false;
145 else
147 retval = this->cache_map_.bind (ext_id, int_id, entry);
148 if (retval == 0)
150 // The entry has been added to cache successfully
151 // Add the cache_map_entry to the transport
152 int_id.transport ()->cache_map_entry (entry);
153 more_to_do = false;
155 else if (retval == 1)
157 if (entry->item ().transport () == int_id.transport ())
159 // update the cache status
160 // we are already holding the lock, do not call set_entry_state
161 entry->item ().recycle_state (int_id.recycle_state ());
162 if (TAO_debug_level > 9 &&
163 entry->item ().is_connected () != int_id.is_connected ())
164 TAOLIB_DEBUG ((LM_DEBUG,
165 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_")
166 ACE_TEXT ("Manager::bind_i, Updating existing ")
167 ACE_TEXT ("entry sets is_connected to %C\n"),
168 (int_id.is_connected () ? "true" : "false")));
170 entry->item ().is_connected (int_id.is_connected ());
171 retval = 0;
172 more_to_do = false;
174 else
176 ext_id.index (ext_id.index () + 1);
177 if (TAO_debug_level > 8)
179 TAOLIB_DEBUG ((LM_DEBUG,
180 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i, ")
181 ACE_TEXT ("Unable to bind Transport[%d] @ hash:index{%d:%d}. ")
182 ACE_TEXT ("Trying with a new index\n"),
183 int_id.transport ()->id (),
184 ext_id.hash (),
185 ext_id.index ()));
189 else
191 if (TAO_debug_level > 0)
193 TAOLIB_ERROR ((LM_ERROR,
194 ACE_TEXT("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i, ")
195 ACE_TEXT("ERROR: unable to bind transport\n")));
197 more_to_do = false;
201 if (retval == 0)
203 if (TAO_debug_level > 4)
205 TAOLIB_DEBUG ((LM_INFO,
206 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::bind_i: ")
207 ACE_TEXT ("Success Transport[%d] @ hash:index{%d:%d}. ")
208 ACE_TEXT ("Cache size is [%d]\n"),
209 int_id.transport ()->id (),
210 ext_id.hash (),
211 ext_id.index (),
212 this->current_size ()));
216 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
217 this->size_monitor_->receive (this->current_size ());
218 #endif /* TAO_HAS_MONITOR_POINTS==1 */
220 return retval;
223 template <typename TT, typename TRDT, typename PSTRAT>
224 typename Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::Find_Result
225 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::find_transport (
226 transport_descriptor_type *prop,
227 transport_type *&transport,
228 size_t &busy_count)
230 if (prop == 0)
232 transport = 0;
233 return CACHE_FOUND_NONE;
236 Find_Result const find_result = this->find (prop, transport, busy_count);
237 if (find_result != CACHE_FOUND_NONE)
239 if (find_result == CACHE_FOUND_AVAILABLE)
241 if (transport->wait_strategy ()->non_blocking () == 0 &&
242 transport->orb_core ()->client_factory ()->use_cleanup_options ())
244 ACE_Event_Handler * const eh =
245 transport->event_handler_i ();
247 ACE_Reactor * const r =
248 transport->orb_core ()->reactor ();
250 if (eh &&
251 r->remove_handler (eh,
252 ACE_Event_Handler::READ_MASK |
253 ACE_Event_Handler::DONT_CALL) == -1)
255 if (TAO_debug_level > 0)
256 TAOLIB_ERROR ((LM_ERROR,
257 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T[%d]")
258 ACE_TEXT ("::find_transport, remove_handler failed\n"),
259 transport->id ()));
261 else
263 transport->wait_strategy ()->is_registered (false);
268 return find_result;
271 template <typename TT, typename TRDT, typename PSTRAT>
272 typename Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::Find_Result
273 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::find_i (
274 transport_descriptor_type *prop,
275 transport_type *&transport,
276 size_t &busy_count)
278 // Get the entry from the Hash Map
279 Find_Result found = CACHE_FOUND_NONE;
281 // Make a temporary object. It does not do a copy.
282 Cache_ExtId key (prop);
283 HASH_MAP_ENTRY *entry = 0;
284 busy_count = 0;
285 int cache_status = 0;
286 HASH_MAP_ENTRY *found_entry = 0;
288 // loop until we find a usable transport, or until we've checked
289 // all cached entries for this endpoint
290 while (found != CACHE_FOUND_AVAILABLE && cache_status == 0)
292 entry = 0;
293 cache_status = this->cache_map_.find (key, entry);
294 if (cache_status == 0 && entry)
296 if (this->is_entry_available_i (*entry))
298 // Successfully found a transport_type.
299 found = CACHE_FOUND_AVAILABLE;
300 found_entry = entry;
301 entry->item ().recycle_state (ENTRY_BUSY);
303 if (TAO_debug_level > 6)
305 TAOLIB_DEBUG ((LM_DEBUG,
306 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::find_i, ")
307 ACE_TEXT ("found available Transport[%d] @hash:index {%d:%d}\n"),
308 entry->item ().transport ()->id (),
309 entry->ext_id_.hash (),
310 entry->ext_id_.index ()));
313 else if (this->is_entry_connecting_i (*entry))
315 if (TAO_debug_level > 6)
317 TAOLIB_DEBUG ((LM_DEBUG,
318 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::find_i, ")
319 ACE_TEXT ("found connecting Transport[%d] @hash:index {%d:%d}\n"),
320 entry->item ().transport ()->id (),
321 entry->ext_id_.hash (),
322 entry->ext_id_.index ()));
324 // if this is the first interesting entry
325 if (found != CACHE_FOUND_CONNECTING)
327 found_entry = entry;
328 found = CACHE_FOUND_CONNECTING;
331 else
333 // if this is the first busy entry
334 if (found == CACHE_FOUND_NONE && busy_count == 0)
336 found_entry = entry;
337 found = CACHE_FOUND_BUSY;
339 ++busy_count;
340 if (TAO_debug_level > 6)
342 TAOLIB_DEBUG ((LM_DEBUG,
343 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::find_i, ")
344 ACE_TEXT ("found busy Transport[%d] @hash:index {%d:%d}\n"),
345 entry->item ().transport ()->id (),
346 entry->ext_id_.hash (),
347 entry->ext_id_.index ()
353 // Bump the index up
354 key.incr_index ();
356 if (found_entry != 0)
358 transport = found_entry->item ().transport ();
359 transport->add_reference ();
360 if (found == CACHE_FOUND_AVAILABLE)
362 // Update the purging strategy information while we
363 // are holding our lock
364 this->purging_strategy_->update_item (*transport);
367 return found;
370 template <typename TT, typename TRDT, typename PSTRAT>
372 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::make_idle_i (HASH_MAP_ENTRY *entry)
374 entry->item ().recycle_state (ENTRY_IDLE_AND_PURGABLE);
376 return 0;
379 template <typename TT, typename TRDT, typename PSTRAT>
381 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::update_entry (HASH_MAP_ENTRY *&entry)
383 ACE_MT (ACE_GUARD_RETURN (ACE_Lock,
384 guard,
385 *this->cache_lock_, -1));
387 if (entry == 0)
388 return -1;
390 purging_strategy *st = this->purging_strategy_;
391 (void) st->update_item (*(entry->item ().transport ()));
393 return 0;
396 template <typename TT, typename TRDT, typename PSTRAT>
398 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::close_i (Connection_Handler_Set &handlers)
400 HASH_MAP_ITER end_iter = this->cache_map_.end ();
402 for (HASH_MAP_ITER iter = this->cache_map_.begin ();
403 iter != end_iter;
404 ++iter)
406 // Get the transport to fill its associated connection's handler.
407 (*iter).int_id_.transport ()->provide_handler (handlers);
409 // Inform the transport that has a reference to the entry in the
410 // map that we are *gone* now. So, the transport should not use
411 // the reference to the entry that he has, to access us *at any
412 // time*.
413 (*iter).int_id_.transport ()->cache_map_entry (0);
416 // Unbind all the entries in the map
417 this->cache_map_.unbind_all ();
419 return 0;
422 template <typename TT, typename TRDT, typename PSTRAT>
423 bool
424 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::blockable_client_transports_i (
425 Connection_Handler_Set &h)
427 HASH_MAP_ITER end_iter = this->cache_map_.end ();
429 for (HASH_MAP_ITER iter = this->cache_map_.begin ();
430 iter != end_iter;
431 ++iter)
433 // Get the transport to fill its associated connection's
434 // handler.
435 bool const retval =
436 (*iter).int_id_.transport ()->provide_blockable_handler (h);
438 // Do not mark the entry as closed if we don't have a
439 // blockable handler added
440 if (retval)
441 (*iter).int_id_.recycle_state (ENTRY_CLOSED);
444 return true;
447 template <typename TT, typename TRDT, typename PSTRAT>
449 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::purge_entry_i (HASH_MAP_ENTRY *entry)
451 // Remove the entry from the Map
452 int const retval = this->cache_map_.unbind (entry);
454 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
455 this->size_monitor_->receive (this->current_size ());
456 #endif /* TAO_HAS_MONITOR_POINTS==1 */
458 return retval;
461 template <typename TT, typename TRDT, typename PSTRAT>
462 bool
463 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::is_entry_available_i (const HASH_MAP_ENTRY &entry)
465 Cache_Entries_State entry_state = entry.int_id_.recycle_state ();
466 bool result = (entry_state == ENTRY_IDLE_AND_PURGABLE);
468 if (result && entry.int_id_.transport () != 0)
470 // if it's not connected, it's not available
471 result = entry.int_id_.is_connected ();
474 if (TAO_debug_level > 8)
476 TAOLIB_DEBUG ((LM_DEBUG,
477 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::")
478 ACE_TEXT ("is_entry_available_i[%d], %C, state is %C\n"),
479 entry.int_id_.transport () ? entry.int_id_.transport ()->id () : 0,
480 (result ? "true" : "false"),
481 Cache_IntId::state_name (entry_state)));
484 return result;
487 template <typename TT, typename TRDT, typename PSTRAT>
488 bool
489 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::is_entry_purgable_i (HASH_MAP_ENTRY &entry)
491 Cache_Entries_State const entry_state = entry.int_id_.recycle_state ();
492 transport_type* transport = entry.int_id_.transport ();
493 bool const result = (entry_state == ENTRY_IDLE_AND_PURGABLE ||
494 entry_state == ENTRY_PURGABLE_BUT_NOT_IDLE)
495 && transport->can_be_purged ();
497 if (TAO_debug_level > 8)
499 TAOLIB_DEBUG ((LM_DEBUG,
500 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::")
501 ACE_TEXT ("is_entry_purgable_i[%d], %C, state is %C\n"),
502 entry.int_id_.transport ()->id (),
503 (result ? "true" : "false"),
504 Cache_IntId::state_name (entry_state)));
507 return result;
510 template <typename TT, typename TRDT, typename PSTRAT>
511 bool
512 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::
513 is_entry_connecting_i (const HASH_MAP_ENTRY &entry)
515 Cache_Entries_State entry_state = entry.int_id_.recycle_state ();
516 bool result = (entry_state == ENTRY_CONNECTING);
518 if (!result && entry.int_id_.transport () != 0)
520 // if we're not connected, that counts, too.
521 // Can this happen? Not sure <wilsond@ociweb.com>
522 result = !entry.int_id_.is_connected ();
525 if (TAO_debug_level > 8)
527 TAOLIB_DEBUG ((LM_DEBUG,
528 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::")
529 ACE_TEXT ("is_entry_connecting_i[%d], %C, state is %C\n"),
530 entry.int_id_.transport () ? entry.int_id_.transport ()->id () : 0,
531 (result ? "true" : "false"),
532 Cache_IntId::state_name (entry_state)));
535 return result;
538 #if !defined (ACE_LACKS_QSORT)
539 template <typename TT, typename TRDT, typename PSTRAT>
541 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::
542 cpscmp(const void* a, const void* b)
544 const HASH_MAP_ENTRY** left = (const HASH_MAP_ENTRY**)a;
545 const HASH_MAP_ENTRY** right = (const HASH_MAP_ENTRY**)b;
547 if ((*left)->int_id_.transport ()->purging_order () <
548 (*right)->int_id_.transport ()->purging_order ())
549 return -1;
551 if ((*left)->int_id_.transport ()->purging_order () >
552 (*right)->int_id_.transport ()->purging_order ())
553 return 1;
555 return 0;
557 #endif /* ACE_LACKS_QSORT */
559 template <typename TT, typename TRDT, typename PSTRAT>
561 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::purge ()
563 typedef ACE_Unbounded_Set<transport_type*> transport_set_type;
564 transport_set_type transports_to_be_closed;
567 ACE_MT (ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->cache_lock_, 0));
569 DESCRIPTOR_SET sorted_set = 0;
570 int const sorted_size = this->fill_set_i (sorted_set);
572 // Only call close_entries () if sorted_set != 0. It takes
573 // control of sorted_set and cleans up any allocated memory. If
574 // sorted_set == 0, then there is nothing to de-allocate.
575 if (sorted_set != 0)
577 // BEGIN FORMER close_entries
578 // Calculate the number of entries to purge, when we have
579 // to purge try to at least to purge minimal of 1 entry
580 // which is needed if we have a very small cache maximum
581 int const amount = (sorted_size * this->percent_) / 100;
583 if (TAO_debug_level > 4)
585 TAOLIB_DEBUG ((LM_INFO,
586 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::purge, ")
587 ACE_TEXT ("Trying to purge %d of %d cache entries\n"),
588 amount,
589 sorted_size));
592 int count = 0;
594 for (int i = 0; count < amount && i < sorted_size; ++i)
596 if (this->is_entry_purgable_i (*sorted_set[i]))
598 transport_type* transport =
599 sorted_set[i]->int_id_.transport ();
600 sorted_set[i]->int_id_.recycle_state (ENTRY_BUSY);
601 transport->add_reference ();
603 if (TAO_debug_level > 4)
605 TAOLIB_DEBUG ((LM_INFO,
606 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::purge, ")
607 ACE_TEXT ("Purgable Transport[%d] found in ")
608 ACE_TEXT ("cache\n"),
609 transport->id ()));
612 if (transports_to_be_closed.insert_tail (transport) != 0)
614 if (TAO_debug_level > 0)
616 TAOLIB_ERROR ((LM_ERROR,
617 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T")
618 ACE_TEXT ("::purge, Unable to add transport[%d] ")
619 ACE_TEXT ("on the to-be-closed set, so ")
620 ACE_TEXT ("it will not be purged\n"),
621 transport->id ()));
623 transport->remove_reference ();
626 // Count this as a successful purged entry
627 ++count;
631 delete [] sorted_set;
632 sorted_set = 0;
633 // END FORMER close_entries
637 // Now, without the lock held, lets go through and close all the transports.
638 if (! transports_to_be_closed.is_empty ())
640 typename transport_set_type::iterator it (transports_to_be_closed);
641 while (! it.done ())
643 transport_type *transport = *it;
645 it.advance ();
647 if (transport)
649 transport->close_connection ();
650 transport->remove_reference ();
655 if (TAO_debug_level > 4)
657 TAOLIB_DEBUG ((LM_INFO,
658 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::purge, ")
659 ACE_TEXT ("Cache size after purging is [%d]\n"),
660 this->current_size ()));
663 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
664 /// The value doesn't matter, all we need is the timestamp,
665 /// which is added automatically.
666 this->purge_monitor_->receive (static_cast<size_t> (0UL));
667 /// And update the size monitor as well.
668 this->size_monitor_->receive (this->current_size ());
669 #endif /* TAO_HAS_MONITOR_POINTS==1 */
671 return 0;
674 template <typename TT, typename TRDT, typename PSTRAT>
675 void
676 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::
677 sort_set (DESCRIPTOR_SET& entries, int current_size)
679 #if defined (ACE_LACKS_QSORT)
680 // Use insertion sort if we don't have qsort
681 for(int i = 1; i < current_size; ++i)
683 if (entries[i]->int_id_.transport ()->purging_order () <
684 entries[i - 1]->int_id_.transport ()->purging_order ())
686 HASH_MAP_ENTRY* entry = entries[i];
688 for(int j = i; j > 0 &&
689 entries[j - 1]->int_id_.transport ()->purging_order () >
690 entry->item ().transport ()->purging_order (); --j)
692 HASH_MAP_ENTRY* holder = entries[j];
693 entries[j] = entries[j - 1];
694 entries[j - 1] = holder;
698 #else
699 ACE_OS::qsort (entries, current_size,
700 sizeof (HASH_MAP_ENTRY*), (ACE_COMPARE_FUNC)cpscmp);
701 #endif /* ACE_LACKS_QSORT */
704 template <typename TT, typename TRDT, typename PSTRAT>
706 Transport_Cache_Manager_T<TT, TRDT, PSTRAT>::
707 fill_set_i (DESCRIPTOR_SET& sorted_set)
709 int current_size = 0;
710 int const cache_maximum = this->purging_strategy_->cache_maximum ();
712 // set sorted_set to 0. This signifies nothing to purge.
713 sorted_set = 0;
715 // Do we need to worry about cache purging?
716 if (cache_maximum >= 0)
718 current_size = static_cast<int> (this->current_size ());
720 if (TAO_debug_level > 6)
722 TAOLIB_DEBUG ((LM_DEBUG,
723 ACE_TEXT ("TAO (%P|%t) - Transport_Cache_Manager_T::fill_set_i, ")
724 ACE_TEXT ("current_size [%d], cache_maximum [%d]\n"),
725 current_size, cache_maximum));
728 if (current_size >= cache_maximum)
730 ACE_NEW_RETURN (sorted_set, HASH_MAP_ENTRY*[current_size], 0);
732 HASH_MAP_ITER iter = this->cache_map_.begin ();
734 for (int i = 0; i < current_size; ++i)
736 sorted_set[i] = &(*iter);
737 ++iter;
740 this->sort_set (sorted_set, current_size);
744 return current_size;
748 TAO_END_VERSIONED_NAMESPACE_DECL