Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tao / Invocation_Retry_State.cpp
blob3c2564db0ebac550ffdd7b105beec81eb424b027
1 // -*- C++ -*-
2 #include "tao/Invocation_Retry_State.h"
3 #include "tao/ORB_Core.h"
4 #include "tao/Client_Strategy_Factory.h"
6 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
8 namespace
10 void retry_limit_calc (int ex,
11 TAO::Invocation_Retry_Params &command_line_params,
12 TAO::Invocation_Retry_Params &client_factory_params,
13 TAO::Invocation_Retry_Params &result)
15 #define FOEL forward_on_exception_limit_
16 if (command_line_params.FOEL[ex] != result.FOEL[ex])
18 result.FOEL[ex] = command_line_params.FOEL[ex];
20 else if (client_factory_params.FOEL[ex] != result.FOEL[ex])
22 result.FOEL[ex] = client_factory_params.FOEL[ex];
24 #undef FOEL
27 /// Calculate the retry parameters by giving a command line parameter
28 /// precedence over the corresponding client strategy factory parameter.
29 /// result is assumed to be passed with default values
30 void retry_params_calc (TAO::Invocation_Retry_Params &command_line_params,
31 TAO::Invocation_Retry_Params &client_factory_params,
32 TAO::Invocation_Retry_Params &result)
34 // Retry delay
35 if (command_line_params.init_retry_delay_ !=
36 result.init_retry_delay_)
37 result.init_retry_delay_ = command_line_params.init_retry_delay_;
38 else if (client_factory_params.init_retry_delay_ !=
39 result.init_retry_delay_)
40 result.init_retry_delay_ = client_factory_params.init_retry_delay_;
42 // Retry on reply closed limit
43 if (command_line_params.forward_on_reply_closed_limit_ !=
44 result.forward_on_reply_closed_limit_)
45 result.forward_on_reply_closed_limit_ =
46 command_line_params.forward_on_reply_closed_limit_;
47 else if (client_factory_params.forward_on_reply_closed_limit_ !=
48 result.forward_on_reply_closed_limit_)
49 result.forward_on_reply_closed_limit_ =
50 client_factory_params.forward_on_reply_closed_limit_;
52 // Forward on exception limits
53 retry_limit_calc (TAO::FOE_OBJECT_NOT_EXIST,
54 command_line_params,
55 client_factory_params,
56 result);
58 retry_limit_calc (TAO::FOE_COMM_FAILURE,
59 command_line_params,
60 client_factory_params,
61 result);
63 retry_limit_calc (TAO::FOE_TRANSIENT,
64 command_line_params,
65 client_factory_params,
66 result);
68 retry_limit_calc (TAO::FOE_INV_OBJREF,
69 command_line_params,
70 client_factory_params,
71 result);
75 TAO::Invocation_Retry_State::Invocation_Retry_State (TAO_Stub &stub)
76 : forward_on_reply_closed_count_ (0)
77 , forward_on_exception_limit_used_ (false)
79 this->ex_count_map_[FOE_OBJECT_NOT_EXIST] = 0;
80 this->ex_count_map_[FOE_COMM_FAILURE] = 0;
81 this->ex_count_map_[FOE_TRANSIENT] = 0;
82 this->ex_count_map_[FOE_INV_OBJREF] = 0;
84 // Cast away const to avoid tedious iterator operations on the ACE_Array_Map.
85 TAO::Invocation_Retry_Params &command_line_params =
86 const_cast<TAO::Invocation_Retry_Params &> (stub.orb_core ()
87 ->orb_params ()->invocation_retry_params ());
88 TAO::Invocation_Retry_Params &client_factory_params =
89 const_cast<TAO::Invocation_Retry_Params &> (stub.orb_core ()
90 ->client_factory ()->invocation_retry_params ());
92 retry_params_calc(command_line_params,
93 client_factory_params,
94 this->retry_params_);
96 for (Invocation_Retry_Params::exception_limit_map_type::const_iterator i =
97 this->retry_params_.forward_on_exception_limit_.begin();
98 i != this->retry_params_.forward_on_exception_limit_.end(); ++i)
100 if (i->second > 0)
102 forward_on_exception_limit_used_ = true;
103 break;
108 TAO::Invocation_Retry_State::~Invocation_Retry_State ()
112 bool
113 TAO::Invocation_Retry_State::forward_on_exception_limit_used () const
115 return forward_on_exception_limit_used_;
118 bool
119 TAO::Invocation_Retry_State::forward_on_exception_increment (const int ef)
121 if (!this->forward_on_exception_limit_used_)
122 return false;
124 int count = this->ex_count_map_[ef];
125 Invocation_Retry_Params::exception_limit_map_type::const_iterator i =
126 this->retry_params_.forward_on_exception_limit_.find (ef);
127 int limit = i->second;
128 if (count < limit)
130 this->ex_count_map_[ef] = count + 1;
131 return true;
134 return false;
137 bool
138 TAO::Invocation_Retry_State::forward_on_reply_closed_increment ()
140 if (this->forward_on_reply_closed_count_ <
141 this->retry_params_.forward_on_reply_closed_limit_)
143 ++this->forward_on_reply_closed_count_;
144 return true;
147 return false;
150 void
151 TAO::Invocation_Retry_State::next_profile_retry (TAO_Stub &stub) const
153 if (!stub.next_profile_retry ())
155 stub.reset_profiles ();
158 this->sleep_at_starting_profile (stub);
161 void
162 TAO::Invocation_Retry_State::sleep_at_starting_profile (TAO_Stub &stub) const
164 if (stub.at_starting_profile ())
165 this->sleep ();
168 void
169 TAO::Invocation_Retry_State::sleep () const
171 ACE_OS::sleep (this->retry_params_.init_retry_delay_);
174 TAO_END_VERSIONED_NAMESPACE_DECL