1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
// $Id$
#include "tao/Connection_Purging_Strategy.h"
#include "tao/Resource_Factory.h"
#include "tao/Transport.h"
#if !defined (__ACE_INLINE__)
# include "tao/Connection_Purging_Strategy.inl"
#endif /* __ACE_INLINE__ */
ACE_RCSID(tao, Connection_Purging_Strategy, "$Id$")
TAO_Connection_Purging_Strategy::TAO_Connection_Purging_Strategy (
TAO_Resource_Factory* rf)
: cache_maximum_ (rf->cache_maximum ()),
percent_(rf->purge_percentage ()),
lock_(rf->create_cached_connection_lock ()),
cache_manager_ ()
{
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ")
ACE_TEXT ("TAO_Connection_Purging_Strategy::")
ACE_TEXT ("TAO_Connection_Purging_Strategy\n")));
}
}
TAO_Connection_Purging_Strategy::~TAO_Connection_Purging_Strategy (void)
{
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ")
ACE_TEXT ("TAO_Connection_Purging_Strategy::")
ACE_TEXT ("~TAO_Connection_Purging_Strategy\n")));
}
delete lock_;
}
void
TAO_Connection_Purging_Strategy::close_entries(DESCRIPTOR_SET& sorted_set)
{
const int sorted_size = sorted_set.size ();
const int amount = (sorted_size * this->percent ()) / 100;
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ")
ACE_TEXT ("Purging %d of %d cache entries\n"),
amount,
sorted_size));
}
for(int i = 0; i < sorted_size; i++)
{
TAO_DESCRIPTOR_INTERFACE* prop = sorted_set[i];
if (i < amount)
{
TAO_PURGING_CACHE_ITEM* item = 0;
if (this->cache_manager ().find_transport (prop, item) == 0)
{
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ")
ACE_TEXT ("Idle item found in ")
ACE_TEXT ("cache: 0x%x\n"),
item));
}
// Eventually calls purge_from_cache() on the cache
// which will call remove_item_i() on us.
item->close_connection ();
}
}
delete prop;
}
}
// ======================================================================
TAO_ULong_Connection_Purging_Strategy::TAO_ULong_Connection_Purging_Strategy (
TAO_Resource_Factory* rf)
: TAO_Connection_Purging_Strategy (rf)
{
}
TAO_ULong_Connection_Purging_Strategy::~TAO_ULong_Connection_Purging_Strategy ()
{
}
int
TAO_ULong_Connection_Purging_Strategy::fill_set_i (DESCRIPTOR_SET& sorted_set)
{
int current_size = this->tracking_map_.current_size ();
int amount = current_size - this->cache_maximum ();
if (TAO_debug_level > 0)
{
ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) - ")
ACE_TEXT ("TAO_ULong_Connection_Purging_Strategy")
ACE_TEXT ("::fill_set_i - %d %d\n"),
current_size,
this->cache_maximum ()));
}
if (amount >= 0)
{
// I could not use ACE_Array_Base<HASH_MAP_ENTRY*> because
// the compiler kept complaining about HASH_MAP_ENTRY not having
// a default construtor.
HASH_MAP_ENTRY** entries;
ACE_NEW_RETURN(entries, HASH_MAP_ENTRY*[current_size], 0);
sorted_set.size (current_size);
int i;
HASH_MAP_ITER iter = this->tracking_map_.begin ();
for (i = 0; i < current_size; i++)
{
entries[i] = &(*iter);
iter++;
}
this->sort_set (entries, current_size);
for(i = 0; i < current_size; i++)
{
// The owner of the sorted_set array accepts responsibility
// for deleting the memory allocated here.
sorted_set[i] = entries[i]->ext_id_.property ()->duplicate ();
}
delete [] entries;
}
return (amount >= 0);
}
void
TAO_ULong_Connection_Purging_Strategy::remove_item_i (
TAO_DESCRIPTOR_INTERFACE* prop)
{
TAO_Cache_ExtId ext_id (prop);
this->tracking_map_.unbind (ext_id);
}
void
TAO_ULong_Connection_Purging_Strategy::remove_all_i ()
{
this->tracking_map_.unbind_all ();
}
#if !defined (ACE_LACKS_QSORT)
int
TAO_ULong_Connection_Purging_Strategy::cpscmp(const void* a, const void* b)
{
const HASH_MAP_ENTRY** left = (const HASH_MAP_ENTRY**)a;
const HASH_MAP_ENTRY** right = (const HASH_MAP_ENTRY**)b;
if ((*left)->int_id_ > (*right)->int_id_)
return 1;
if ((*left)->int_id_ < (*right)->int_id_)
return -1;
return 0;
}
#endif /* ACE_LACKS_QSORT */
void
TAO_ULong_Connection_Purging_Strategy::sort_set (HASH_MAP_ENTRY**& entries,
int current_size)
{
#if defined (ACE_LACKS_QSORT)
// Use insertion sort if we don't have qsort
for(int i = 1; i < current_size; i++)
{
if (entries[i]->int_id_ <
entries[i - 1]->int_id_)
{
HASH_MAP_ENTRY* entry = entries[i];
for(int j = i; j > 0 &&
entries[j - 1]->int_id_ >
entry->int_id_; j--)
{
HASH_MAP_ENTRY* holder = entries[j];
entries[j] = entries[j - 1];
entries[j - 1] = holder;
}
}
}
#else
ACE_OS::qsort (entries, current_size,
sizeof (HASH_MAP_ENTRY*), (ACE_COMPARE_FUNC)cpscmp);
#endif /* ACE_LACKS_QSORT */
}
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Array_Base<TAO_Transport_Descriptor_Interface*>;
template class ACE_Hash_Map_Entry<TAO_Cache_ExtId, unsigned long>;
template class ACE_Hash_Map_Manager<TAO_Cache_ExtId, unsigned long, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator<TAO_Cache_ExtId, unsigned long, ACE_Null_Mutex>;
template class ACE_Hash_Map_Manager_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Base_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Iterator_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>;
template class ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Array_Base<TAO_Transport_Descriptor_Interface*>
#pragma instantiate ACE_Hash_Map_Entry<TAO_Cache_ExtId, unsigned long>
#pragma instantiate ACE_Hash_Map_Manager<TAO_Cache_ExtId, unsigned long, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator<TAO_Cache_ExtId, unsigned long, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Manager_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Iterator_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Cache_ExtId, unsigned long, ACE_Hash<TAO_Cache_ExtId>, ACE_Equal_To<TAO_Cache_ExtId>, ACE_Null_Mutex>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
|