summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Supplier.cpp
blob: dca10de0f2860fbd22fe9e582dc824a200f4b026 (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
#include "tao/corba.h"
#include "orbsvcs/Time_Utilities.h"
#include "orbsvcs/Notify/Properties.h"
#include "orbsvcs/Notify/Supplier.h"
#include "tao/debug.h"
#include "tao/Messaging/Messaging_TypesC.h"

#if ! defined (__ACE_INLINE__)
#include "orbsvcs/Notify/Supplier.inl"
#endif /* __ACE_INLINE__ */

#include "orbsvcs/Notify/ProxyConsumer.h"
#include "orbsvcs/Notify/Proxy.h"

#ifndef DEBUG_LEVEL
# define DEBUG_LEVEL TAO_debug_level
#endif //DEBUG_LEVEL

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_Notify_Supplier::TAO_Notify_Supplier (TAO_Notify_ProxyConsumer* proxy)
  : proxy_ (proxy)
{
}

TAO_Notify_Supplier::~TAO_Notify_Supplier ()
{
}

TAO_Notify_Proxy*
TAO_Notify_Supplier::proxy ()
{
  return this->proxy_consumer ();
}

void
TAO_Notify_Supplier::dispatch_updates_i (
  const CosNotification::EventTypeSeq& added,
  const CosNotification::EventTypeSeq& removed)
{
  if (!CORBA::is_nil (this->subscribe_.in ()))
    this->subscribe_->subscription_change (added, removed);
}

bool
TAO_Notify_Supplier::is_alive (bool allow_nil_supplier)
{
  bool status = false;
  CORBA::Object_var supplier = this->get_supplier ();
  if (CORBA::is_nil (supplier.in ()))
  {
    // The supplier may not connected or the supplier did
    // not provide a callback. In this case, the liveliness
    // check should return true so it will be validated in
    // next period.
    if (allow_nil_supplier)
      return true;
    else
      return status;
  }

  CORBA::PolicyList policy_list;
  try
    {
      bool do_liveliness_check = false;
      ACE_Time_Value now = ACE_OS::gettimeofday ();
      ACE_Time_Value last_ping = proxy_->last_ping();
      if (CORBA::is_nil (this->rtt_obj_.in ()))
      {
        // We need to determine if the supplier on the other end is still
        // alive.  Since we may be in an upcall from the owner of the
        // original supplier, we have to put a timeout on the call in case
        // the client side is not processing ORB requests at this time.  In
        // the event that the timeout exception occurs, we will assume that
        // the original supplier is still around.  If we get any other
        // exception we will say that the original supplier is not
        // available anymore.
        TimeBase::TimeT timeout = 10000000;
        CORBA::Any timeout_any;
        timeout_any <<= timeout;

        policy_list.length (1);
        policy_list[0] = TAO_Notify_PROPERTIES::instance()->orb()->
                          create_policy (
                                Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
                                timeout_any);
        rtt_obj_ =
          supplier->_set_policy_overrides (policy_list,
                                          CORBA::ADD_OVERRIDE);

        // Clean up the policy that was allocated in the try/catch
        for (CORBA::ULong i = 0; i < policy_list.length (); i++)
          policy_list[i]->destroy ();

        do_liveliness_check
          = (last_ping == ACE_Time_Value::zero ? true
          : now - last_ping >= TAO_Notify_PROPERTIES::instance()->validate_client_delay ());
      }
      else
        do_liveliness_check =
          now - last_ping >= TAO_Notify_PROPERTIES::instance()->validate_client_interval ();

      if (CORBA::is_nil (rtt_obj_.in ()))
        status = false;
      else if (do_liveliness_check || allow_nil_supplier)
      {
        this->proxy_->last_ping (now);
        status = !rtt_obj_->_non_existent ();
      }
      else
        status = true;
    }
  catch (const CORBA::TIMEOUT&)
    {
       status = true;
    }
  catch (const CORBA::Exception& ex)
    {
      if (DEBUG_LEVEL > 0)
      {
        ex._tao_print_exception ("TAO_Notify_Supplier::is_alive: false");
      }
    }

  return status;
}

TAO_END_VERSIONED_NAMESPACE_DECL