Routing_Slip.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  *  @file Routing_Slip.h
00005  *
00006  *  Routing_Slip.h,v 1.8 2006/03/14 06:14:34 jtc Exp
00007  *
00008  *  @author Dale Wilson <wilson_d@ociweb.com>
00009  */
00010 
00011 #ifndef TAO_NOTIFY_ROUTING_SLIP_H
00012 #define TAO_NOTIFY_ROUTING_SLIP_H
00013 #include /**/ "ace/pre.h"
00014 
00015 #include "orbsvcs/Notify/notify_serv_export.h"
00016 #include "orbsvcs/Notify/Event.h"
00017 #include "orbsvcs/Notify/Delivery_Request.h"
00018 #include "orbsvcs/Notify/Event_Persistence_Factory.h"
00019 
00020 #include "orbsvcs/Notify/Persistent_File_Allocator.h"  // for Persistent_Callback
00021 
00022 #include <ace/Vector_T.h>
00023 #include <ace/Malloc_Base.h>  // necessary?
00024 
00025 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00026 # pragma once
00027 #endif /* ACE_LACKS_PRAGMA_ONCE */
00028 
00029 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00030 
00031 // Forward declarations of classes/pointers/collections
00032 // referenced from this header
00033 class TAO_Notify_EventChannelFactory;
00034 class TAO_Notify_Method_Request;
00035 class TAO_Notify_ProxyConsumer;
00036 class TAO_Notify_ProxySupplier;
00037 class TAO_Notify_Method_Request_Queueable;
00038 
00039 namespace TAO_Notify
00040 {
00041 
00042 class Routing_Slip_Persistence_Manager;
00043 
00044 // Forward declarations of TAO_Notify classes/pointers/collections
00045 // referenced from this header
00046 
00047 /// A vector of Delivery Requests.  The body of a Routing_Slip.
00048 typedef ACE_Vector <Delivery_Request_Ptr> Delivery_Request_Vec;
00049 
00050 /// A vector of Methods_.  Used during recovery.
00051 typedef ACE_Vector <TAO_Notify_Method_Request_Queueable *> Delivery_Method_Vec;
00052 
00053 class Routing_Slip;
00054 /// A reference-counted smart pointer to a Routing_Slip
00055 typedef ACE_Strong_Bound_Ptr<Routing_Slip, TAO_SYNCH_MUTEX> Routing_Slip_Ptr;
00056 
00057 class Routing_Slip_Persistence_Manager;
00058 
00059 class Routing_Slip_Queue;
00060 
00061 /**
00062  * \brief Class which manages the delivery of events to destination.
00063  *
00064  * Interacts with persistent storage to provide reliable delivery.
00065  */
00066 class TAO_Notify_Serv_Export Routing_Slip : public Persistent_Callback
00067 {
00068   typedef ACE_Guard< TAO_SYNCH_MUTEX > Routing_Slip_Guard;
00069 public:
00070   /// "Factory" method for normal use.
00071   static Routing_Slip_Ptr create (const TAO_Notify_Event::Ptr& event
00072     ACE_ENV_ARG_DECL);
00073 
00074   /// "Factory" method for use during reload from persistent storage.
00075   static Routing_Slip_Ptr create (
00076     TAO_Notify_EventChannelFactory & ecf,
00077     Routing_Slip_Persistence_Manager * rspm);
00078 
00079   void set_rspm (Routing_Slip_Persistence_Manager * rspm);
00080 
00081   void reconnect (ACE_ENV_SINGLE_ARG_DECL);
00082 
00083   /// destructor (should be private but that inspires compiler wars)
00084   virtual ~Routing_Slip ();
00085 
00086   //////////////////
00087   // Action requests
00088 
00089   /// Route this event to destinations
00090   /// must be the Action request after
00091   /// the routing slip is created.
00092   void route (TAO_Notify_ProxyConsumer* pc, bool reliable_channel ACE_ENV_ARG_DECL);
00093 
00094   /// \brief Schedule delivery to a consumer via a proxy supplier
00095   /// \param proxy_supplier the proxy supplier that will deliver the event
00096   /// \param filter should consumer-based filtering be applied?
00097   void dispatch (TAO_Notify_ProxySupplier * proxy_supplier, bool filter ACE_ENV_ARG_DECL);
00098 
00099 
00100   /////////////////////////////////////////
00101   /// \brief Wait until the event/routing_slip has
00102   /// been saved at least once.
00103   void wait_persist ();
00104 
00105   /////////////////////////////////////
00106   // signals from the rest of the world
00107 
00108   /// \brief A delivery request has been satisfied.
00109   void delivery_request_complete (size_t request_id);
00110 
00111   /// \brief This Routing_Slip reached the front of the persistence queue
00112   void at_front_of_persist_queue ();
00113 
00114   /// \brief The persistent storage has completed the last request.
00115   virtual void persist_complete ();
00116 
00117   /////////////////////////////////////////////////////
00118   // \brief Access the event associated with this routing slip
00119   const TAO_Notify_Event::Ptr & event () const;
00120 
00121   /// \brief Provide an identifying number for this Routing Slip
00122   /// to use in debug messages.
00123   int sequence() const;
00124 
00125   /// \brief Should delivery of this event be retried if it fails?
00126   bool should_retry () const;
00127 
00128 private:
00129   ////////////////////
00130   // state transitions
00131   void enter_state_transient (Routing_Slip_Guard & guard);
00132   void continue_state_transient (Routing_Slip_Guard & guard);
00133   void enter_state_reloaded (Routing_Slip_Guard & guard);
00134   void enter_state_new (Routing_Slip_Guard & guard);
00135   void continue_state_new (Routing_Slip_Guard & guard);
00136   void enter_state_complete_while_new (Routing_Slip_Guard & guard);
00137   void enter_state_saving (Routing_Slip_Guard & guard);
00138   void enter_state_saved (Routing_Slip_Guard & guard);
00139   void enter_state_updating (Routing_Slip_Guard & guard);
00140   void enter_state_changed_while_saving (Routing_Slip_Guard & guard);
00141   void continue_state_changed_while_saving (Routing_Slip_Guard & guard);
00142   void enter_state_changed (Routing_Slip_Guard & guard);
00143   void continue_state_changed (Routing_Slip_Guard & guard);
00144   void enter_state_complete (Routing_Slip_Guard & guard);
00145   void enter_state_deleting (Routing_Slip_Guard & guard);
00146   void enter_state_terminal (Routing_Slip_Guard & guard);
00147 
00148 private:
00149   bool create_persistence_manager();
00150 
00151   /// Private constructor for use by create method
00152   Routing_Slip(const TAO_Notify_Event::Ptr& event);
00153 
00154   /// Test to see if all deliveries are complete.
00155   bool all_deliveries_complete () const;
00156 
00157   /// This routing_slip needs to be saved.
00158   void add_to_persist_queue(Routing_Slip_Guard & guard);
00159 
00160   /// Marshal into a CDR
00161   void marshal (TAO_OutputCDR & cdr);
00162 
00163   /// Marshal from CDR
00164   bool unmarshal (TAO_Notify_EventChannelFactory &ecf, TAO_InputCDR & rscdr);
00165 
00166 private:
00167   /// Protection for internal information
00168   TAO_SYNCH_MUTEX internals_;
00169   /// true when event persistence qos is guaranteed
00170   bool is_safe_;
00171   /// signalled when is_safe_ goes true
00172   ACE_SYNCH_CONDITION until_safe_;
00173 
00174   /// Smart pointer to this object
00175   /// Provides continuity between smart pointers and "Routing_Slip::this"
00176   /// Also lets the Routing_Slip manage its own minimum lifetime.
00177   Routing_Slip_Ptr this_ptr_;
00178 
00179   // The event being delivered.
00180   TAO_Notify_Event::Ptr event_;
00181 
00182   /// A  mini-state machine to control persistence
00183   /// See external doc for circles and arrows.
00184   enum State
00185   {
00186     rssCREATING,
00187     rssTRANSIENT,
00188     rssRELOADED,
00189     rssNEW,
00190     rssCOMPLETE_WHILE_NEW,
00191     rssSAVING,
00192     rssSAVED,
00193     rssUPDATING,
00194     rssCHANGED_WHILE_SAVING,
00195     rssCHANGED,
00196     rssCOMPLETE,
00197     rssDELETING,
00198     rssTERMINAL
00199   } state_;
00200 
00201   /// A collection of delivery requests
00202   Delivery_Request_Vec delivery_requests_;
00203 
00204   /// Methods that should be restarted during event recovery
00205   Delivery_Method_Vec delivery_methods_;
00206 
00207   /// How many delivery requests are complete
00208   size_t complete_requests_;
00209 
00210   /// Pointer to a Routing_Slip_Persistence_Manager
00211   Routing_Slip_Persistence_Manager * rspm_;
00212 
00213   int sequence_;
00214 
00215   static TAO_SYNCH_MUTEX sequence_lock_;
00216   static int routing_slip_sequence_;
00217   static size_t count_enter_transient_;
00218   static size_t count_continue_transient_;
00219   static size_t count_enter_reloaded_;
00220   static size_t count_enter_new_;
00221   static size_t count_continue_new_;
00222   static size_t count_enter_complete_while_new_;
00223   static size_t count_enter_saving_;
00224   static size_t count_enter_saved_;
00225   static size_t count_enter_updating_;
00226   static size_t count_enter_changed_while_saving_;
00227   static size_t count_continue_changed_while_saving_;
00228   static size_t count_enter_changed_;
00229   static size_t count_continue_changed_;
00230   static size_t count_enter_complete_;
00231   static size_t count_enter_deleting_;
00232   static size_t count_enter_terminal_;
00233 
00234   static Routing_Slip_Queue persistent_queue_;
00235 };
00236 
00237 } // namespace
00238 
00239 TAO_END_VERSIONED_NAMESPACE_DECL
00240 
00241 #include /**/ "ace/post.h"
00242 #endif /* TAO_NOTIFY_ROUTING_SLIP_H */

Generated on Thu Nov 9 13:24:15 2006 for TAO_CosNotification by doxygen 1.3.6