summaryrefslogtreecommitdiff
path: root/TAO/tao/Profile_Transport_Resolver.cpp
blob: 98fd6be0558ad22c28bb41149492347fe1d01457 (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// -*- C++ -*-
#include "tao/Profile_Transport_Resolver.h"
#include "tao/Profile.h"
#include "tao/Stub.h"
#include "tao/Transport.h"
#include "tao/Invocation_Endpoint_Selectors.h"
#include "tao/ORB_Core.h"
#include "tao/Thread_Lane_Resources.h"
#include "tao/Transport_Cache_Manager.h"
#include "tao/Transport_Descriptor_Interface.h"
#include "tao/Endpoint_Selector_Factory.h"
#include "tao/Codeset_Manager.h"
#include "tao/Connector_Registry.h"
#include "tao/Transport_Connector.h"
#include "tao/Endpoint.h"
#include "tao/SystemException.h"
#include "tao/Client_Strategy_Factory.h"

#include "tao/ORB_Time_Policy.h"
#include "ace/CORBA_macros.h"

#if !defined (__ACE_INLINE__)
# include "tao/Profile_Transport_Resolver.inl"
#endif /* __ACE_INLINE__ */

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

namespace TAO
{
  Profile_Transport_Resolver::~Profile_Transport_Resolver ()
  {
    if (this->profile_)
      {
        this->profile_->_decr_refcnt ();
      }

    if (this->transport_.get ())
      {
        if (this->is_released_ == false)
          {
            this->transport_->make_idle ();
          }

        this->transport_->remove_reference ();
      }

    delete this->inconsistent_policies_;
  }

  void
  Profile_Transport_Resolver::profile (TAO_Profile *p)
  {
    // Dont do anything if the incoming profile is null
    if (p)
      {
        // @note This is just a workaround for a more serious problem
        // with profile management. This would cover some potential
        // issues that Ossama is working on.  Ossama, please remove
        // them when you are done.
        TAO_Profile *tmp = this->profile_;

        (void) p->_incr_refcnt ();
        this->profile_ = p;

        if (tmp)
          {
            (void) tmp->_decr_refcnt ();
          }
      }
  }


  void
  Profile_Transport_Resolver::resolve (ACE_Time_Value *max_time_val)
  {
    TAO::ORB_Countdown_Time countdown (max_time_val);

    TAO_Invocation_Endpoint_Selector *es =
      this->stub_->orb_core ()->endpoint_selector_factory ()->get_selector ();

    // Select the endpoint
    es->select_endpoint (this, max_time_val);

    if (this->transport_.get () == nullptr)
      {
        // No useable endpoint could be found. We will not
        // be able to send the message. Wait to throw an exception until
        // after the send_request interception point has been called.
        return;
      }

    TAO_GIOP_Message_Version const & version = this->profile_->version ();

    // Initialize the messaging object
    this->transport_->messaging_init (version);

    if (!this->transport_->is_tcs_set ())
      {
        TAO_Codeset_Manager * const tcm =
          this->stub_->orb_core ()->codeset_manager ();
        if (tcm)
          tcm->set_tcs (*this->profile_, *this->transport_);
      }
  }

  bool
  Profile_Transport_Resolver::try_connect (
      TAO_Transport_Descriptor_Interface *desc,
      ACE_Time_Value *timeout)
  {
    return this->try_connect_i (desc, timeout, false);
  }

  bool
  Profile_Transport_Resolver::try_parallel_connect (
       TAO_Transport_Descriptor_Interface *desc,
       ACE_Time_Value *timeout)
  {
    return this->try_connect_i (desc, timeout, true);
  }


  bool
  Profile_Transport_Resolver::try_connect_i (
       TAO_Transport_Descriptor_Interface *desc,
       ACE_Time_Value *timeout,
       bool parallel)
  {
    TAO_Connector_Registry *conn_reg =
      this->stub_->orb_core ()->connector_registry ();

    if (conn_reg == nullptr)
      {
        throw ::CORBA::INTERNAL (
          CORBA::SystemException::_tao_minor_code (
            0,
            EINVAL),
          CORBA::COMPLETED_NO);
      }

    ACE_Time_Value connection_timeout;
    bool has_con_timeout = this->get_connection_timeout (connection_timeout);

    if (has_con_timeout && !this->blocked_)
      {
        timeout = &connection_timeout;
      }
    else if (has_con_timeout)
      {
        if (timeout == nullptr || connection_timeout < *timeout)
          timeout = &connection_timeout;
        else
          has_con_timeout = false;
      }
    else if (!this->blocked_)
      {
        timeout = nullptr;
      }

    TAO_Connector *con = conn_reg->get_connector (desc->endpoint ()->tag ());
    ACE_ASSERT(con != nullptr);
    if (parallel)
      {
        this->transport_.set (con->parallel_connect (this, desc, timeout));
      }
    else
      {
        this->transport_.set (con->connect (this, desc, timeout));
      }
    // A timeout error occurred.
    // If the user has set a roundtrip timeout policy, throw a timeout
    // exception.  Otherwise, just fall through and return false to
    // look at the next endpoint.
    if (this->transport_.get () == nullptr &&
        has_con_timeout == false &&
        errno == ETIME)
      {
        throw ::CORBA::TIMEOUT (
          CORBA::SystemException::_tao_minor_code (
            TAO_TIMEOUT_CONNECT_MINOR_CODE,
            errno),
          CORBA::COMPLETED_NO);
      }
    else if (this->transport_.get () == nullptr)
      {
        return false;
      }
    else
      {
        // Determine the sync scope (if any)
        Messaging::SyncScope sync_scope;
        bool has_synchronization = false;
        this->stub_->orb_core ()->call_sync_scope_hook (this->stub_,
                                                        has_synchronization,
                                                        sync_scope);
      }

    return true;
  }

  bool
  Profile_Transport_Resolver::use_parallel_connect () const
  {
    TAO_ORB_Core *oc = this->stub_->orb_core();
    return (oc->orb_params()->use_parallel_connects()
#if 0       // it was decided that even with blocked connects
            // parallel connects could be useful, at least for cache
            // processing.
            oc->client_factory()->connect_strategy() !=
            TAO_Client_Strategy_Factory::TAO_BLOCKED_CONNECT
#endif /* 0 */
            );
  }

  bool
  Profile_Transport_Resolver::get_connection_timeout (
    ACE_Time_Value &max_wait_time)
  {
    bool is_conn_timeout = false;

    // Check for the connection timout policy in the ORB
    this->stub_->orb_core ()->connection_timeout (this->stub_,
                                                  is_conn_timeout,
                                                  max_wait_time);

    return is_conn_timeout;
  }


  void
  Profile_Transport_Resolver::init_inconsistent_policies ()
  {
    ACE_NEW_THROW_EX (this->inconsistent_policies_,
                      CORBA::PolicyList (0),
                      CORBA::NO_MEMORY (
                      CORBA::SystemException::_tao_minor_code (
                        0,
                        ENOMEM),
                      CORBA::COMPLETED_NO));
  }


  int
  Profile_Transport_Resolver::find_transport (TAO_Transport_Descriptor_Interface *desc)
  {
    TAO::Transport_Cache_Manager & cache =
      this->profile_->orb_core()->lane_resources ().transport_cache();

    // the cache increments the reference count on the transport if
    // the find is successful. We want to return a "boolean" of 0 for
    // failure, 1 for success.
    size_t busy_count;
    TAO_Transport* tmp = this->transport_.get ();
    if (cache.find_transport(desc, tmp, busy_count) !=
        Transport_Cache_Manager::CACHE_FOUND_AVAILABLE)
      return 0;

    this->transport_.set (tmp);
    return 1;
  }

}

TAO_END_VERSIONED_NAMESPACE_DECL