summaryrefslogtreecommitdiff
path: root/TAO/tao/Invocation_Retry_State.cpp
blob: 9ca1994e8b784eb689ae55f36fa9afa3ad6f8a6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// -*- C++ -*-
#include "tao/Invocation_Retry_State.h"
#include "tao/ORB_Core.h"
#include "tao/Client_Strategy_Factory.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace
{
  void retry_limit_calc (int ex,
                         TAO::Invocation_Retry_Params &command_line_params,
                         TAO::Invocation_Retry_Params &client_factory_params,
                         TAO::Invocation_Retry_Params &result)
  {
#define FOEL forward_on_exception_limit_
    if (command_line_params.FOEL[ex] != result.FOEL[ex])
      {
        result.FOEL[ex] = command_line_params.FOEL[ex];
      }
    else if (client_factory_params.FOEL[ex] != result.FOEL[ex])
      {
        result.FOEL[ex] = client_factory_params.FOEL[ex];
      }
#undef FOEL
  }

  /// Calculate the retry parameters by giving a command line parameter
  /// precedence over the corresponding client strategy factory parameter.
  /// result is assumed to be passed with default values
  void retry_params_calc (TAO::Invocation_Retry_Params &command_line_params,
                          TAO::Invocation_Retry_Params &client_factory_params,
                          TAO::Invocation_Retry_Params &result)
  {

  // Retry delay
  if (command_line_params.init_retry_delay_ !=
      result.init_retry_delay_)
    result.init_retry_delay_ = command_line_params.init_retry_delay_;
  else if (client_factory_params.init_retry_delay_ !=
      result.init_retry_delay_)
    result.init_retry_delay_ = client_factory_params.init_retry_delay_;

  // Retry on reply closed limit
  if (command_line_params.forward_on_reply_closed_limit_ !=
      result.forward_on_reply_closed_limit_)
    result.forward_on_reply_closed_limit_ =
      command_line_params.forward_on_reply_closed_limit_;
  else if (client_factory_params.forward_on_reply_closed_limit_ !=
           result.forward_on_reply_closed_limit_)
    result.forward_on_reply_closed_limit_ =
      client_factory_params.forward_on_reply_closed_limit_;

  // Forward on exception limits

  retry_limit_calc (TAO::FOE_OBJECT_NOT_EXIST,
                    command_line_params,
                    client_factory_params,
                    result);

  retry_limit_calc (TAO::FOE_COMM_FAILURE,
                    command_line_params,
                    client_factory_params,
                    result);

  retry_limit_calc (TAO::FOE_TRANSIENT,
                    command_line_params,
                    client_factory_params,
                    result);

  retry_limit_calc (TAO::FOE_INV_OBJREF,
                    command_line_params,
                    client_factory_params,
                    result);

  }

}

TAO::Invocation_Retry_State::Invocation_Retry_State (TAO_Stub &stub)
  : forward_on_reply_closed_count_ (0)
  , forward_on_exception_limit_used_ (false)
{
  this->ex_count_map_[FOE_OBJECT_NOT_EXIST] = 0;
  this->ex_count_map_[FOE_COMM_FAILURE] = 0;
  this->ex_count_map_[FOE_TRANSIENT] = 0;
  this->ex_count_map_[FOE_INV_OBJREF] = 0;

  // Cast away const to avoid tedious iterator operations on the ACE_Array_Map.
  TAO::Invocation_Retry_Params &command_line_params =
    const_cast<TAO::Invocation_Retry_Params &> (stub.orb_core ()
      ->orb_params ()->invocation_retry_params ());
  TAO::Invocation_Retry_Params &client_factory_params =
    const_cast<TAO::Invocation_Retry_Params &> (stub.orb_core ()
      ->client_factory ()->invocation_retry_params ());

  retry_params_calc(command_line_params,
                    client_factory_params,
                    this->retry_params_);

  for (Invocation_Retry_Params::exception_limit_map_type::const_iterator i =
         this->retry_params_.forward_on_exception_limit_.begin();
       i != this->retry_params_.forward_on_exception_limit_.end(); ++i)
    {
      if (i->second > 0)
        {
          forward_on_exception_limit_used_ = true;
          break;
        }
    }
}

TAO::Invocation_Retry_State::~Invocation_Retry_State ()
{
}

bool
TAO::Invocation_Retry_State::forward_on_exception_limit_used () const
{
  return forward_on_exception_limit_used_;
}

bool
TAO::Invocation_Retry_State::forward_on_exception_increment (const int ef)
{
  if (!this->forward_on_exception_limit_used_)
    return false;

  int count = this->ex_count_map_[ef];
  Invocation_Retry_Params::exception_limit_map_type::const_iterator i =
    this->retry_params_.forward_on_exception_limit_.find (ef);
  int limit = i->second;
  if (count < limit)
    {
      this->ex_count_map_[ef] = count + 1;
      return true;
    }

  return false;
}

bool
TAO::Invocation_Retry_State::forward_on_reply_closed_increment ()
{
  if (this->forward_on_reply_closed_count_ <
      this->retry_params_.forward_on_reply_closed_limit_)
    {
      ++this->forward_on_reply_closed_count_;
      return true;
    }

  return false;
}

void
TAO::Invocation_Retry_State::next_profile_retry (TAO_Stub &stub) const
{
  if (!stub.next_profile_retry ())
    {
      stub.reset_profiles ();
    }

  this->sleep_at_starting_profile (stub);
}

void
TAO::Invocation_Retry_State::sleep_at_starting_profile (TAO_Stub &stub) const
{
  if (stub.at_starting_profile ())
    this->sleep ();
}

void
TAO::Invocation_Retry_State::sleep () const
{
  ACE_OS::sleep (this->retry_params_.init_retry_delay_);
}


TAO_END_VERSIONED_NAMESPACE_DECL