Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef TAO_CONNECTION_CACHE_MANAGER_T_H
00014 #define TAO_CONNECTION_CACHE_MANAGER_T_H
00015
00016 #include "ace/pre.h"
00017 #include "ace/Null_Mutex.h"
00018 #include "ace/Thread_Mutex.h"
00019
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 #define ACE_LACKS_PRAGMA_ONCE
00022 #endif
00023
00024 #include "ace/Hash_Map_Manager_T.h"
00025
00026 #include "tao/Cache_Entries_T.h"
00027 #include "tao/orbconf.h"
00028
00029 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00030 #include "ace/Monitor_Size.h"
00031 #endif
00032
00033 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00034 class ACE_Handle_Set;
00035 template <class T> class ACE_Unbounded_Set;
00036 template <class T> class ACE_Unbounded_Set_Iterator;
00037 ACE_END_VERSIONED_NAMESPACE_DECL
00038
00039 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00040
00041 class TAO_Connection_Handler;
00042 class TAO_Resource_Factory;
00043
00044 template <class ACE_COND_MUTEX> class TAO_Condition;
00045
00046 namespace TAO
00047 {
00048 typedef ACE_Unbounded_Set<TAO_Connection_Handler*> Connection_Handler_Set;
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 template <typename TT, typename TRDT, typename PSTRAT>
00062 class Transport_Cache_Manager_T
00063 {
00064 public:
00065 typedef TT transport_type;
00066 typedef TRDT transport_descriptor_type;
00067 typedef PSTRAT purging_strategy;
00068
00069
00070 enum Find_Result
00071 {
00072 CACHE_FOUND_NONE,
00073 CACHE_FOUND_CONNECTING,
00074 CACHE_FOUND_BUSY,
00075 CACHE_FOUND_AVAILABLE
00076 };
00077
00078 typedef Cache_ExtId_T <transport_descriptor_type> Cache_ExtId;
00079 typedef Cache_IntId_T <transport_type> Cache_IntId;
00080
00081
00082 typedef ACE_Hash_Map_Manager_Ex <Cache_ExtId,
00083 Cache_IntId,
00084 ACE_Hash<Cache_ExtId>,
00085 ACE_Equal_To<Cache_ExtId>,
00086 ACE_Null_Mutex>
00087 HASH_MAP;
00088
00089 typedef typename HASH_MAP::iterator HASH_MAP_ITER;
00090
00091 typedef ACE_Hash_Map_Entry <Cache_ExtId,
00092 Cache_IntId>
00093 HASH_MAP_ENTRY;
00094
00095 typedef TAO_Condition<TAO_SYNCH_MUTEX> CONDITION;
00096
00097
00098
00099 Transport_Cache_Manager_T (
00100 int percent,
00101 purging_strategy* purging_strategy,
00102 size_t cache_maximum,
00103 bool locked,
00104 const char *orbid);
00105
00106
00107 ~Transport_Cache_Manager_T (void);
00108
00109
00110
00111
00112
00113
00114
00115 int cache_transport (transport_descriptor_type *prop,
00116 transport_type *transport,
00117 Cache_Entries_State state =
00118 ENTRY_IDLE_AND_PURGABLE);
00119
00120
00121
00122 Find_Result find_transport (
00123 transport_descriptor_type *prop,
00124 transport_type *&transport,
00125 size_t & busy_count);
00126
00127
00128 int purge (void);
00129
00130
00131 int purge_entry (HASH_MAP_ENTRY *& entry);
00132
00133
00134 void mark_invalid (HASH_MAP_ENTRY * entry);
00135
00136
00137 void mark_connected (HASH_MAP_ENTRY * entry, bool state);
00138
00139
00140 int make_idle (HASH_MAP_ENTRY *entry);
00141
00142
00143 void set_entry_state (HASH_MAP_ENTRY *entry,
00144 TAO::Cache_Entries_State state);
00145
00146
00147
00148 int update_entry (HASH_MAP_ENTRY *&entry);
00149
00150
00151
00152 int close (Connection_Handler_Set &handlers);
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 bool blockable_client_transports (Connection_Handler_Set &handlers);
00165
00166
00167 size_t current_size (void) const;
00168
00169
00170 size_t total_size (void) const;
00171
00172
00173 HASH_MAP &map (void);
00174
00175 private:
00176
00177
00178 Find_Result find (
00179 transport_descriptor_type *prop,
00180 transport_type *&transport,
00181 size_t & busy_count);
00182
00183
00184
00185
00186
00187
00188
00189 int bind_i (Cache_ExtId &ext_id, Cache_IntId &int_id);
00190
00191
00192
00193
00194
00195
00196
00197 Find_Result find_i (
00198 transport_descriptor_type *prop,
00199 transport_type *&transport,
00200 size_t & busy_count);
00201
00202
00203 int make_idle_i (HASH_MAP_ENTRY *entry);
00204
00205
00206 int close_i (Connection_Handler_Set &handlers);
00207
00208
00209 int purge_entry_i (HASH_MAP_ENTRY *&entry);
00210
00211
00212 void mark_invalid_i (HASH_MAP_ENTRY *entry);
00213
00214 private:
00215
00216
00217
00218 bool is_entry_available_i (const HASH_MAP_ENTRY &entry);
00219
00220
00221
00222
00223 bool is_entry_connecting_i (const HASH_MAP_ENTRY &entry);
00224
00225
00226
00227
00228 bool is_entry_purgable_i (HASH_MAP_ENTRY &entry);
00229
00230 #if !defined(ACE_LACKS_QSORT)
00231
00232 static int cpscmp(const void* a, const void* b);
00233 #endif
00234
00235 typedef HASH_MAP_ENTRY** DESCRIPTOR_SET;
00236
00237
00238 void sort_set (DESCRIPTOR_SET& entries, int size);
00239
00240
00241
00242 int fill_set_i (DESCRIPTOR_SET& sorted_set);
00243
00244
00245 bool blockable_client_transports_i (Connection_Handler_Set &handlers);
00246
00247 private:
00248
00249 int percent_;
00250
00251
00252 purging_strategy *purging_strategy_;
00253
00254
00255 HASH_MAP cache_map_;
00256
00257 TAO_SYNCH_MUTEX cache_map_mutex_;
00258
00259
00260 ACE_Lock *cache_lock_;
00261
00262
00263 size_t cache_maximum_;
00264
00265 #if defined (TAO_HAS_MONITOR_POINTS) && (TAO_HAS_MONITOR_POINTS == 1)
00266
00267 ACE::Monitor_Control::Size_Monitor *purge_monitor_;
00268
00269
00270 ACE::Monitor_Control::Size_Monitor *size_monitor_;
00271 #endif
00272 };
00273 }
00274
00275 TAO_END_VERSIONED_NAMESPACE_DECL
00276
00277 #if defined (__ACE_INLINE__)
00278 # include "tao/Transport_Cache_Manager_T.inl"
00279 #endif
00280
00281 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00282 #include "tao/Transport_Cache_Manager_T.cpp"
00283 #endif
00284
00285 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00286 #pragma implementation ("tao/Transport_Cache_Manager_T.cpp")
00287 #endif
00288
00289 #include "ace/post.h"
00290
00291 #endif