00001 // -*- C++ -*- 00002 00003 // Routing_Slip_Queue.h,v 1.6 2006/03/14 06:14:34 jtc Exp 00004 00005 #ifndef TAO_NOTIFY_ROUTING_SLIP_QUEUE_H 00006 #define TAO_NOTIFY_ROUTING_SLIP_QUEUE_H 00007 #include /**/ "ace/pre.h" 00008 00009 #include "orbsvcs/Notify/Routing_Slip.h" 00010 00011 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00012 # pragma once 00013 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00014 00015 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00016 00017 namespace TAO_Notify 00018 { 00019 /** 00020 * \brief A queue of Routing_Slips waiting to be persisted. 00021 * 00022 * The Routing_Slip_Queue keeps a queue of Routing_Slips waiting 00023 * to be written to persistent storage. The "allowed" parameter 00024 * determines how many Routing_Slips can be handled simultaneously 00025 * by the persistent storage. Until this threshold is reached, 00026 * Routing_Slips are not held in the queue, but pass straight through. 00027 * 00028 * Once the allowe number of Routing_Slips are being handled, any 00029 * additional requests are held in the queue until persistence is 00030 * complete for another Routing_Slips. 00031 * 00032 * Having Routing_Slips waiting in the queue is "a good thing" [TM] 00033 * because it allows delivery completions to be applied to the 00034 * routing slip before it is written -- thereby reducing or completely 00035 * eliminating the number of actual writes to persistent storage. 00036 * 00037 * Experimentation indicates that a good value for "allowed" is 1. 00038 * 00039 * Allowed == 0 is treated as a special case meaning pass all Routing_Slips 00040 * through the queue immediately. Setting it a good way to test how well 00041 * your storage device withstands continuous beating. 00042 */ 00043 class TAO_Notify_Serv_Export Routing_Slip_Queue 00044 { 00045 typedef ACE_Unbounded_Queue <Routing_Slip_Ptr> Queue; 00046 typedef ACE_Guard< TAO_SYNCH_MUTEX > Guard; 00047 public: 00048 /** 00049 * \brief Construct setting "allowed". 00050 * \param allowed the number of Routing_Slips that can be handled 00051 * simultaneously by the persistent store. 00052 */ 00053 Routing_Slip_Queue (size_t allowed = 1); 00054 /// Destructor. 00055 ~Routing_Slip_Queue (); 00056 00057 /** 00058 * \brief Add a routing slip to the tail of the queue and dispatch if necessary. 00059 */ 00060 void add (const Routing_Slip_Ptr & routing_slip); 00061 /** 00062 * \brief A call back to indicate that processing is complete for a previously-queued 00063 * Routing_Slip. 00064 */ 00065 void complete (); 00066 00067 /** 00068 * /brief Adjust the "allowed" value on-the-fly (not recommended, but it works.) 00069 */ 00070 void set_allowed (size_t allowed); 00071 00072 private: 00073 void dispatch (Guard & guard); 00074 bool dispatch_one (Guard & guard); 00075 00076 private: 00077 Routing_Slip_Queue (const Routing_Slip_Queue & rhs); 00078 Routing_Slip_Queue & operator = (const Routing_Slip_Queue & rhs); 00079 private: 00080 // configuration setting 00081 size_t allowed_; 00082 /// Protection for internal information 00083 TAO_SYNCH_MUTEX internals_; 00084 size_t active_; 00085 Queue queue_; 00086 00087 }; 00088 } // namespace 00089 00090 TAO_END_VERSIONED_NAMESPACE_DECL 00091 00092 #include /**/ "ace/post.h" 00093 #endif /* TAO_NOTIFY_ROUTING_SLIP_QUEUE_H */