Transport_Queueing_Strategies.cpp

Go to the documentation of this file.
00001 // Transport_Queueing_Strategies.cpp,v 1.4 2006/03/10 07:19:07 jtc Exp
00002 
00003 #include "tao/Transport_Queueing_Strategies.h"
00004 #include "tao/Buffering_Constraint_Policy.h"
00005 #include "tao/Stub.h"
00006 #include "tao/debug.h"
00007 
00008 #include "ace/Log_Msg.h"
00009 #include "ace/OS_NS_sys_time.h"
00010 
00011 ACE_RCSID (tao,
00012            Transport_Queueing_Strategies,
00013            "Transport_Queueing_Strategies.cpp,v 1.4 2006/03/10 07:19:07 jtc Exp")
00014 
00015 
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017 
00018 namespace TAO
00019 {
00020   Transport_Queueing_Strategy::~Transport_Queueing_Strategy (void)
00021   {
00022   }
00023 
00024 // ****************************************************************
00025 
00026   bool
00027   Default_Transport_Queueing_Strategy::must_queue (bool) const
00028   {
00029     return false;
00030   }
00031 
00032   bool
00033   Default_Transport_Queueing_Strategy::buffering_constraints_reached (
00034     TAO_Stub *,
00035     size_t ,
00036     size_t ,
00037     bool &must_flush,
00038     const ACE_Time_Value &,
00039     bool &set_timer,
00040     ACE_Time_Value &) const
00041   {
00042     set_timer = false;
00043     must_flush = false;
00044     return true;
00045   }
00046 
00047 // ****************************************************************
00048 
00049   bool
00050   Flush_Transport_Queueing_Strategy::must_queue (bool) const
00051   {
00052     return false;
00053   }
00054 
00055   bool
00056   Flush_Transport_Queueing_Strategy::buffering_constraints_reached (
00057     TAO_Stub *,
00058     size_t ,
00059     size_t ,
00060     bool &must_flush,
00061     const ACE_Time_Value &,
00062     bool &set_timer,
00063     ACE_Time_Value &) const
00064   {
00065     set_timer = false;
00066     must_flush = true;
00067     return true;
00068   }
00069 
00070 // ****************************************************************
00071 
00072   #if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
00073 
00074   bool
00075   Eager_Transport_Queueing_Strategy::must_queue (bool) const
00076   {
00077     return true;
00078   }
00079 
00080   bool
00081   Eager_Transport_Queueing_Strategy::buffering_constraints_reached (
00082     TAO_Stub *stub,
00083     size_t msg_count,
00084     size_t total_bytes,
00085     bool &must_flush,
00086     const ACE_Time_Value &current_deadline,
00087     bool &set_timer,
00088     ACE_Time_Value &new_deadline) const
00089   {
00090     must_flush = false;
00091     set_timer = false;
00092 
00093     TAO_Buffering_Constraint_Policy *buffering_constraint_policy = 0;
00094 
00095     ACE_TRY_NEW_ENV
00096       {
00097         CORBA::Policy_var bcp_policy =
00098           stub->get_cached_policy (TAO_CACHED_POLICY_BUFFERING_CONSTRAINT
00099                                    ACE_ENV_ARG_PARAMETER);
00100         ACE_TRY_CHECK;
00101 
00102         TAO::BufferingConstraintPolicy_var bcp =
00103           TAO::BufferingConstraintPolicy::_narrow (bcp_policy.in ()
00104                                                    ACE_ENV_ARG_PARAMETER);
00105         ACE_TRY_CHECK;
00106 
00107         buffering_constraint_policy =
00108           dynamic_cast<TAO_Buffering_Constraint_Policy *> (bcp.in ());
00109 
00110         if (buffering_constraint_policy == 0)
00111           {
00112             return true;
00113           }
00114       }
00115     ACE_CATCHANY
00116       {
00117         return true;
00118       }
00119     ACE_ENDTRY;
00120 
00121     TAO::BufferingConstraint buffering_constraint;
00122     buffering_constraint_policy->get_buffering_constraint (buffering_constraint);
00123 
00124     if (buffering_constraint.mode == TAO::BUFFER_FLUSH)
00125       {
00126         must_flush = true;
00127         return true;
00128       }
00129 
00130     bool constraints_reached = false;
00131 
00132     if (ACE_BIT_ENABLED (buffering_constraint.mode,
00133                          TAO::BUFFER_MESSAGE_COUNT)
00134         && msg_count >= buffering_constraint.message_count)
00135       {
00136         constraints_reached = true;
00137       }
00138 
00139     if (ACE_BIT_ENABLED (buffering_constraint.mode,
00140                          TAO::BUFFER_MESSAGE_BYTES)
00141         && total_bytes >= buffering_constraint.message_bytes)
00142       {
00143         constraints_reached = true;
00144       }
00145 
00146     if (this->timer_check (buffering_constraint,
00147                            current_deadline,
00148                            set_timer,
00149                            new_deadline))
00150       {
00151         constraints_reached = true;
00152       }
00153 
00154     return constraints_reached;
00155   }
00156 
00157   bool
00158   Eager_Transport_Queueing_Strategy::timer_check (
00159     const TAO::BufferingConstraint &buffering_constraint,
00160     const ACE_Time_Value &current_deadline,
00161     bool &set_timer,
00162     ACE_Time_Value &new_deadline) const
00163   {
00164     set_timer = false;
00165 
00166     if (!ACE_BIT_ENABLED (buffering_constraint.mode,
00167                           TAO::BUFFER_TIMEOUT))
00168       {
00169         return false;
00170       }
00171 
00172     // Compute the next deadline...
00173     ACE_Time_Value now = ACE_OS::gettimeofday ();
00174     ACE_Time_Value timeout =
00175       this->time_conversion (buffering_constraint.timeout);
00176     new_deadline = now + timeout;
00177 
00178     // Check if the new deadline is more stringent, or if the deadline
00179     // has expired and thus must be reset anyway.
00180     if (current_deadline > new_deadline
00181         || current_deadline < now)
00182       {
00183         set_timer = true;
00184       }
00185 
00186     // ... if there is no deadline we don't want to schedule output (the
00187     // deadline will be set because set_timer is set to 1 in that case).
00188     // If there is a deadline but but it has not been reached, we
00189     // don't want to schedule any output either...
00190     if (current_deadline == ACE_Time_Value::zero
00191         || current_deadline >= now)
00192       {
00193         return false;
00194       }
00195 
00196     if (TAO_debug_level > 6)
00197       {
00198         ACE_DEBUG ((LM_DEBUG,
00199                     "TAO (%P|%t) - TAO_Eager_Buffering_Sync_Strategy::timer_check, "
00200                     "Now = %u, Current = %u, New = %u\n",
00201                     now.msec (), current_deadline.msec (),
00202                     new_deadline.msec ()));
00203       }
00204 
00205     return true;
00206   }
00207 
00208   ACE_Time_Value
00209   Eager_Transport_Queueing_Strategy::time_conversion (
00210     const TimeBase::TimeT &time) const
00211   {
00212     TimeBase::TimeT seconds = time / 10000000u;
00213     TimeBase::TimeT microseconds = (time % 10000000u) / 10;
00214     return ACE_Time_Value (ACE_U64_TO_U32 (seconds),
00215                            ACE_U64_TO_U32 (microseconds));
00216   }
00217 
00218 // ****************************************************************
00219 
00220   bool
00221   Delayed_Transport_Queueing_Strategy::must_queue (bool queue_empty) const
00222   {
00223     // If the queue is empty we want to send immediately
00224     return !queue_empty;
00225   }
00226 
00227   #endif /* TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1 */
00228 
00229 }
00230 
00231 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 11:54:27 2006 for TAO by doxygen 1.3.6