Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Transport_Cache_Manager.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Transport_Cache_Manager.h
00006  *
00007  *  $Id: Transport_Cache_Manager.h,v 1.1.1.2 2003/02/21 18:36:45 chad Exp $
00008  *
00009  *  @author Balachandran Natarajan <bala@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 
00014 #ifndef TAO_CONNECTION_CACHE_MANAGER_H
00015 #define TAO_CONNECTION_CACHE_MANAGER_H
00016 #include "ace/pre.h"
00017 
00018 #include "tao/Cache_Entries.h"
00019 
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 #define  ACE_LACKS_PRAGMA_ONCE
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 #include "ace/Hash_Map_Manager_T.h"
00025 #include "ace/Synch_T.h"
00026 
00027 // #include "tao/TAO_Export.h"
00028 // #include "tao/Cache_Entries.h"
00029 // #include "tao/Connection_Purging_Strategy.h"
00030 
00031 
00032 class ACE_Handle_Set;
00033 class ACE_Event_Handler;
00034 class TAO_ORB_Core;
00035 class TAO_Resource_Factory;
00036 class TAO_Connection_Purging_Strategy;
00037 
00038 template <class ACE_COND_MUTEX> class TAO_Condition;
00039 template <class T> class ACE_Unbounded_Set;
00040 template <class T> class ACE_Unbounded_Set_Iterator;
00041 
00042 typedef ACE_Unbounded_Set<ACE_Event_Handler*> TAO_EventHandlerSet;
00043 typedef ACE_Unbounded_Set_Iterator<ACE_Event_Handler*>
00044         TAO_EventHandlerSetIterator;
00045 
00046 /**
00047  * @class TAO_Transport_Cache_Manager
00048  *
00049  * @brief The Transport Cache Manager for TAO
00050  *
00051  * This class provides interfaces associating a TAO_Cache_ExtId
00052  * & TAO_Cache_IntId. This class is wrapper around the
00053  * ACE_Hash_Map_Manager  class which is used as a container to Cache
00054  * the connections. This class protects the entries with a lock. The
00055  * map is updated only by holding the lock. The more compelling reason
00056  * to have the lock in this class and not in the Hash_Map is that, we
00057  * do quite a bit of work in this class for which we need a lock.
00058  *
00059  */
00060 class TAO_Export TAO_Transport_Cache_Manager
00061 {
00062 public:
00063 
00064   // Some useful typedef's
00065   typedef ACE_Hash_Map_Manager_Ex <TAO_Cache_ExtId,
00066                                    TAO_Cache_IntId,
00067                                    ACE_Hash<TAO_Cache_ExtId>,
00068                                    ACE_Equal_To<TAO_Cache_ExtId>,
00069                                    ACE_Null_Mutex> HASH_MAP;
00070 
00071   typedef HASH_MAP::iterator HASH_MAP_ITER;
00072 
00073   typedef ACE_Hash_Map_Entry <TAO_Cache_ExtId,
00074                               TAO_Cache_IntId> HASH_MAP_ENTRY;
00075 
00076   typedef TAO_Condition<TAO_SYNCH_MUTEX> CONDITION;
00077 
00078   // == Public methods
00079   /// Constructor
00080   TAO_Transport_Cache_Manager (TAO_ORB_Core &orb_core);
00081 
00082   /// Destructor
00083   virtual ~TAO_Transport_Cache_Manager (void);
00084 
00085   /// Add the transport to the cache.
00086 
00087   /**
00088    * The transport has the property definition based on which caching
00089    * can be done. This method marks the transport
00090    * <CODE>ACE_RECYCLABLE_BUSY </CODE> which helps the threads
00091    * opening up connections to use the  transport immediately.
00092    */
00093   int cache_transport (TAO_Transport_Descriptor_Interface *prop,
00094                        TAO_Transport *transport);
00095 
00096   /// Similar to the one above, but the transport is left in <CODE>
00097   /// ACE_RECYCLABLE_IDLE_AND_PURGABLE</CODE> state.
00098   int cache_idle_transport (TAO_Transport_Descriptor_Interface *prop,
00099                             TAO_Transport *transport);
00100 
00101   /// Check the Transport Cache to check whether the connection exists
00102   /// in the Cache and return the connection
00103   int find_transport (TAO_Transport_Descriptor_Interface *prop,
00104                       TAO_Transport *&transport);
00105 
00106   /// Remove entries from the cache depending upon the strategy.
00107   int purge (void);
00108 
00109   /// Purge the entry from the Cache Map
00110   int purge_entry (HASH_MAP_ENTRY *&);
00111 
00112   /// Mark the entry as invalid for use but keep it in cache.
00113   void mark_invalid (HASH_MAP_ENTRY *&);
00114 
00115   /// Make the entry idle and ready for use.
00116   int make_idle (HASH_MAP_ENTRY *&entry);
00117 
00118   /// Mark the entry as touched. This call updates the purging
00119   /// strategy policy information.
00120   int update_entry (HASH_MAP_ENTRY *&entry);
00121 
00122   /// Close the underlying hash map manager and return the handle set
00123   /// that have been registered with the reactor
00124   int close (ACE_Handle_Set &reactor_registered,
00125              TAO_EventHandlerSet &unregistered);
00126 
00127   /// Return the current size of the cache.
00128   size_t current_size (void) const;
00129 
00130   /// Return the total size of the cache.
00131   size_t total_size (void) const;
00132 
00133   /// Return the underlying cache map
00134   HASH_MAP &map (void);
00135 
00136 private:
00137 
00138   /// Associate <ext_id> with <int_id>. Grabs the lock and calls the
00139   /// implementation function bind_i.
00140   int bind (TAO_Cache_ExtId &ext_id,
00141             TAO_Cache_IntId &int_id);
00142 
00143   /// Lookup entry<key,value> in the cache. Grabs the lock and calls the
00144   /// implementation function find_i.
00145   int find (const TAO_Cache_ExtId &key,
00146             TAO_Cache_IntId &value);
00147 
00148   /**
00149    * Non-Locking version and actual implementation of bind ()
00150    * call. Calls bind on the Hash_Map_Manager that it holds. If the
00151    * bind succeeds, it adds the Hash_Map_Entry in to the
00152    * Transport for its reference. If the bind fails because
00153    * of an exiting entry, this method calls the get_last_index_bind
00154    * ().
00155    */
00156   int bind_i (TAO_Cache_ExtId &ext_id,
00157               TAO_Cache_IntId &int_id);
00158 
00159   /**
00160    * Non-locking version and actual implementation of find ()
00161    * call. This calls the find () on the underlying
00162    * Hash_Map_Manager. If the find succeeds, it calls the
00163    * get_idle_transport ().
00164    */
00165   int find_i (const TAO_Cache_ExtId &key,
00166               TAO_Cache_IntId &value);
00167 
00168   /// Non-locking version and actual implementation of make_idle ().
00169   int make_idle_i (HASH_MAP_ENTRY *&entry);
00170 
00171   /// Non-locking version and actual implementation of close ()
00172   int close_i (ACE_Handle_Set &reactor_registered,
00173                TAO_EventHandlerSet &unregistered);
00174 
00175   /// Purge the entry from the Cache Map
00176   int purge_entry_i (HASH_MAP_ENTRY *&entry);
00177 
00178   /// Mark the entry as invalid for use but keep it in cache.
00179   void mark_invalid_i (HASH_MAP_ENTRY *&);
00180 
00181 private:
00182 
00183   /**
00184    * This is called by the bind () call when a bind fails with a
00185    * available entry. When a new connection is created in TAO with an
00186    * already existing endpoint, in addition to an exisitng one, we
00187    * mark the connections with an index. This method, finds out the
00188    * last highest index and binds the entry with an index = (last
00189    * highest index + 1).
00190    */
00191   int get_last_index_bind (TAO_Cache_ExtId &key,
00192                            TAO_Cache_IntId &val,
00193                            HASH_MAP_ENTRY *&entry);
00194 
00195   /**
00196    * Tries to find if the <int_id_> in entry is idle for use. If it is
00197    * idle it is immediately markes as busy and returns a value of
00198    * 1, else it returns a value of 0
00199    */
00200   int is_entry_idle (HASH_MAP_ENTRY *&entry);
00201 
00202 #if !defined(ACE_LACKS_QSORT)
00203   /// Used by qsort
00204   static int cpscmp(const void* a, const void* b);
00205 #endif
00206 
00207   typedef HASH_MAP_ENTRY** DESCRIPTOR_SET;
00208 
00209   /// Sort the list of entries
00210   void sort_set (DESCRIPTOR_SET& entries, int size);
00211 
00212   /// Fill sorted_set in with the TAO_Transport_Descriptor_Interface's in
00213   /// a sorted order.
00214   int fill_set_i (DESCRIPTOR_SET& sorted_set);
00215 
00216   /// Wait for connections if we have reached the limit on the number
00217   /// of muxed connections. If not (ie. if we dont use a muxed
00218   /// connection or if we have not reached the limit) this just
00219   /// behaves as a no-op. <extid> has all the information about the
00220   /// connection that is being searched.
00221   int wait_for_connection (TAO_Cache_ExtId &extid);
00222 
00223   /// Is the wakeup useful todo some work?
00224   int is_wakeup_useful (TAO_Cache_ExtId &extid);
00225 private:
00226 
00227   /// The percentage of the cache to purge at one time
00228   int percent_;
00229 
00230   /// The underlying connection purging strategy
00231   TAO_Connection_Purging_Strategy *purging_strategy_;
00232 
00233   /// The hash map that has the connections
00234   HASH_MAP cache_map_;
00235 
00236   /// The condition variable
00237   CONDITION *condition_;
00238 
00239   /// The lock that is used by the cache map
00240   ACE_Lock *cache_lock_;
00241 
00242   /// Number of allowed muxed connections
00243   CORBA::ULong muxed_number_;
00244 
00245   /// Number of threads waiting for connections
00246   int no_waiting_threads_;
00247 
00248   /// This is for optimization purposes. In a situation where number
00249   /// of threads are waiting for connections, the last connection that
00250   /// is put back is cached here. This should prevent all th threads
00251   /// trying to search for their required entry.
00252   TAO_Cache_ExtId *last_entry_returned_;
00253 };
00254 
00255 #if defined (__ACE_INLINE__)
00256 # include "tao/Transport_Cache_Manager.inl"
00257 #endif /* __ACE_INLINE__ */
00258 
00259 #include "ace/post.h"
00260 #endif /*TAO_CONNECTION_CACHE_MANAGER_H*/

Generated on Mon Jun 16 13:50:06 2003 for TAO by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002