Go to the documentation of this file.00001
00002
00003 #include "tao/Messaging/Messaging_Queueing_Strategies.h"
00004 #include "tao/Messaging/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 (Messaging,
00012 Messaging_Queueing_Strategies,
00013 "$Id: Messaging_Queueing_Strategies.cpp 85406 2009-05-20 09:07:56Z johnnyw $")
00014
00015
00016 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00017
00018 namespace TAO
00019 {
00020
00021
00022 #if (TAO_HAS_BUFFERING_CONSTRAINT_POLICY == 1)
00023
00024 bool
00025 Eager_Transport_Queueing_Strategy::must_queue (bool) const
00026 {
00027 return true;
00028 }
00029
00030 bool
00031 Eager_Transport_Queueing_Strategy::buffering_constraints_reached (
00032 TAO_Stub *stub,
00033 size_t msg_count,
00034 size_t total_bytes,
00035 bool &must_flush,
00036 const ACE_Time_Value ¤t_deadline,
00037 bool &set_timer,
00038 ACE_Time_Value &new_deadline) const
00039 {
00040 must_flush = false;
00041 set_timer = false;
00042
00043 TAO::BufferingConstraint buffering_constraint;
00044
00045 try
00046 {
00047 CORBA::Policy_var bcp_policy =
00048 stub->get_cached_policy (TAO_CACHED_POLICY_BUFFERING_CONSTRAINT);
00049
00050 TAO::BufferingConstraintPolicy_var bcpv =
00051 TAO::BufferingConstraintPolicy::_narrow (bcp_policy.in ());
00052
00053 TAO_Buffering_Constraint_Policy* bcp =
00054 dynamic_cast<TAO_Buffering_Constraint_Policy *> (bcpv.in ());
00055 if (bcp == 0)
00056 {
00057 return true;
00058 }
00059 bcp->get_buffering_constraint (buffering_constraint);
00060 }
00061 catch (const ::CORBA::Exception&)
00062 {
00063 return true;
00064 }
00065
00066
00067 if (buffering_constraint.mode == TAO::BUFFER_FLUSH)
00068 {
00069 must_flush = true;
00070 return true;
00071 }
00072
00073 bool constraints_reached = false;
00074
00075 if (ACE_BIT_ENABLED (buffering_constraint.mode,
00076 TAO::BUFFER_MESSAGE_COUNT)
00077 && msg_count >= buffering_constraint.message_count)
00078 {
00079 constraints_reached = true;
00080 }
00081
00082 if (ACE_BIT_ENABLED (buffering_constraint.mode,
00083 TAO::BUFFER_MESSAGE_BYTES)
00084 && total_bytes >= buffering_constraint.message_bytes)
00085 {
00086 constraints_reached = true;
00087 }
00088
00089 if (this->timer_check (buffering_constraint,
00090 current_deadline,
00091 set_timer,
00092 new_deadline))
00093 {
00094 constraints_reached = true;
00095 }
00096
00097 return constraints_reached;
00098 }
00099
00100 bool
00101 Eager_Transport_Queueing_Strategy::timer_check (
00102 const TAO::BufferingConstraint &buffering_constraint,
00103 const ACE_Time_Value ¤t_deadline,
00104 bool &set_timer,
00105 ACE_Time_Value &new_deadline) const
00106 {
00107 set_timer = false;
00108
00109 if (!ACE_BIT_ENABLED (buffering_constraint.mode,
00110 TAO::BUFFER_TIMEOUT))
00111 {
00112 return false;
00113 }
00114
00115
00116 ACE_Time_Value const now = ACE_OS::gettimeofday ();
00117 ACE_Time_Value timeout =
00118 this->time_conversion (buffering_constraint.timeout);
00119 new_deadline = now + timeout;
00120
00121
00122
00123 if (current_deadline > new_deadline
00124 || current_deadline < now)
00125 {
00126 set_timer = true;
00127 }
00128
00129
00130
00131
00132
00133 if (current_deadline == ACE_Time_Value::zero
00134 || current_deadline >= now)
00135 {
00136 return false;
00137 }
00138
00139 if (TAO_debug_level > 6)
00140 {
00141 ACE_DEBUG ((LM_DEBUG,
00142 "TAO (%P|%t) - TAO_Eager_Buffering_Sync_Strategy::timer_check, "
00143 "Now = %u, Current = %u, New = %u\n",
00144 now.msec (), current_deadline.msec (),
00145 new_deadline.msec ()));
00146 }
00147
00148 return true;
00149 }
00150
00151 ACE_Time_Value
00152 Eager_Transport_Queueing_Strategy::time_conversion (
00153 const TimeBase::TimeT &time) const
00154 {
00155 TimeBase::TimeT seconds = time / 10000000u;
00156 TimeBase::TimeT microseconds = (time % 10000000u) / 10;
00157 return ACE_Time_Value (ACE_U64_TO_U32 (seconds),
00158 ACE_U64_TO_U32 (microseconds));
00159 }
00160
00161
00162
00163 bool
00164 Delayed_Transport_Queueing_Strategy::must_queue (bool queue_empty) const
00165 {
00166
00167 return !queue_empty;
00168 }
00169
00170 #endif
00171
00172 }
00173
00174 TAO_END_VERSIONED_NAMESPACE_DECL