Routing_Slip.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 /**
00004  *  @file Routing_Slip.h
00005  *
00006  *  $Id: Routing_Slip.h 76589 2007-01-25 18:04:11Z elliott_c $
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 
00073   /// "Factory" method for use during reload from persistent storage.
00074   static Routing_Slip_Ptr create (
00075     TAO_Notify_EventChannelFactory & ecf,
00076     Routing_Slip_Persistence_Manager * rspm);
00077 
00078   void set_rspm (Routing_Slip_Persistence_Manager * rspm);
00079 
00080   void reconnect (void);
00081 
00082   /// destructor (should be private but that inspires compiler wars)
00083   virtual ~Routing_Slip ();
00084 
00085   //////////////////
00086   // Action requests
00087 
00088   /// Route this event to destinations
00089   /// must be the Action request after
00090   /// the routing slip is created.
00091   void route (TAO_Notify_ProxyConsumer* pc, bool reliable_channel);
00092 
00093   /// \brief Schedule delivery to a consumer via a proxy supplier
00094   /// \param proxy_supplier the proxy supplier that will deliver the event
00095   /// \param filter should consumer-based filtering be applied?
00096   void dispatch (TAO_Notify_ProxySupplier * proxy_supplier, bool filter);
00097 
00098 
00099   /////////////////////////////////////////
00100   /// \brief Wait until the event/routing_slip has
00101   /// been saved at least once.
00102   void wait_persist ();
00103 
00104   /////////////////////////////////////
00105   // signals from the rest of the world
00106 
00107   /// \brief A delivery request has been satisfied.
00108   void delivery_request_complete (size_t request_id);
00109 
00110   /// \brief This Routing_Slip reached the front of the persistence queue
00111   void at_front_of_persist_queue ();
00112 
00113   /// \brief The persistent storage has completed the last request.
00114   virtual void persist_complete ();
00115 
00116   /////////////////////////////////////////////////////
00117   // \brief Access the event associated with this routing slip
00118   const TAO_Notify_Event::Ptr & event () const;
00119 
00120   /// \brief Provide an identifying number for this Routing Slip
00121   /// to use in debug messages.
00122   int sequence() const;
00123 
00124   /// \brief Should delivery of this event be retried if it fails?
00125   bool should_retry () const;
00126 
00127 private:
00128   ////////////////////
00129   // state transitions
00130   void enter_state_transient (Routing_Slip_Guard & guard);
00131   void continue_state_transient (Routing_Slip_Guard & guard);
00132   void enter_state_reloaded (Routing_Slip_Guard & guard);
00133   void enter_state_new (Routing_Slip_Guard & guard);
00134   void continue_state_new (Routing_Slip_Guard & guard);
00135   void enter_state_complete_while_new (Routing_Slip_Guard & guard);
00136   void enter_state_saving (Routing_Slip_Guard & guard);
00137   void enter_state_saved (Routing_Slip_Guard & guard);
00138   void enter_state_updating (Routing_Slip_Guard & guard);
00139   void enter_state_changed_while_saving (Routing_Slip_Guard & guard);
00140   void continue_state_changed_while_saving (Routing_Slip_Guard & guard);
00141   void enter_state_changed (Routing_Slip_Guard & guard);
00142   void continue_state_changed (Routing_Slip_Guard & guard);
00143   void enter_state_complete (Routing_Slip_Guard & guard);
00144   void enter_state_deleting (Routing_Slip_Guard & guard);
00145   void enter_state_terminal (Routing_Slip_Guard & guard);
00146 
00147 private:
00148   bool create_persistence_manager();
00149 
00150   /// Private constructor for use by create method
00151   Routing_Slip(const TAO_Notify_Event::Ptr& event);
00152 
00153   /// Test to see if all deliveries are complete.
00154   bool all_deliveries_complete () const;
00155 
00156   /// This routing_slip needs to be saved.
00157   void add_to_persist_queue(Routing_Slip_Guard & guard);
00158 
00159   /// Marshal into a CDR
00160   void marshal (TAO_OutputCDR & cdr);
00161 
00162   /// Marshal from CDR
00163   bool unmarshal (TAO_Notify_EventChannelFactory &ecf, TAO_InputCDR & rscdr);
00164 
00165 private:
00166   /// Protection for internal information
00167   TAO_SYNCH_MUTEX internals_;
00168   /// true when event persistence qos is guaranteed
00169   bool is_safe_;
00170   /// signalled when is_safe_ goes true
00171   ACE_SYNCH_CONDITION until_safe_;
00172 
00173   /// Smart pointer to this object
00174   /// Provides continuity between smart pointers and "Routing_Slip::this"
00175   /// Also lets the Routing_Slip manage its own minimum lifetime.
00176   Routing_Slip_Ptr this_ptr_;
00177 
00178   // The event being delivered.
00179   TAO_Notify_Event::Ptr event_;
00180 
00181   /// A  mini-state machine to control persistence
00182   /// See external doc for circles and arrows.
00183   enum State
00184   {
00185     rssCREATING,
00186     rssTRANSIENT,
00187     rssRELOADED,
00188     rssNEW,
00189     rssCOMPLETE_WHILE_NEW,
00190     rssSAVING,
00191     rssSAVED,
00192     rssUPDATING,
00193     rssCHANGED_WHILE_SAVING,
00194     rssCHANGED,
00195     rssCOMPLETE,
00196     rssDELETING,
00197     rssTERMINAL
00198   } state_;
00199 
00200   /// A collection of delivery requests
00201   Delivery_Request_Vec delivery_requests_;
00202 
00203   /// Methods that should be restarted during event recovery
00204   Delivery_Method_Vec delivery_methods_;
00205 
00206   /// How many delivery requests are complete
00207   size_t complete_requests_;
00208 
00209   /// Pointer to a Routing_Slip_Persistence_Manager
00210   Routing_Slip_Persistence_Manager * rspm_;
00211 
00212   int sequence_;
00213 
00214   static TAO_SYNCH_MUTEX sequence_lock_;
00215   static int routing_slip_sequence_;
00216   static size_t count_enter_transient_;
00217   static size_t count_continue_transient_;
00218   static size_t count_enter_reloaded_;
00219   static size_t count_enter_new_;
00220   static size_t count_continue_new_;
00221   static size_t count_enter_complete_while_new_;
00222   static size_t count_enter_saving_;
00223   static size_t count_enter_saved_;
00224   static size_t count_enter_updating_;
00225   static size_t count_enter_changed_while_saving_;
00226   static size_t count_continue_changed_while_saving_;
00227   static size_t count_enter_changed_;
00228   static size_t count_continue_changed_;
00229   static size_t count_enter_complete_;
00230   static size_t count_enter_deleting_;
00231   static size_t count_enter_terminal_;
00232 
00233   static Routing_Slip_Queue persistent_queue_;
00234 };
00235 
00236 } // namespace
00237 
00238 TAO_END_VERSIONED_NAMESPACE_DECL
00239 
00240 #include /**/ "ace/post.h"
00241 #endif /* TAO_NOTIFY_ROUTING_SLIP_H */

Generated on Tue Feb 2 17:45:29 2010 for TAO_CosNotification by  doxygen 1.4.7