summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_Pull_Handler.cpp
blob: 3e1c589bbfb4a7e9d9fccdb806b8fe3a2323d4c7 (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
// -*- C++ -*-

#include "LB_Pull_Handler.h"

#include "tao/debug.h"

ACE_RCSID (LoadBalancing,
           LB_Pull_Handler,
           "$Id$")

TAO_LB_Pull_Handler::TAO_LB_Pull_Handler (
  TAO_LB_Location_Map &location_map)
  : location_map_ (location_map)
{
}

int
TAO_LB_Pull_Handler::handle_timeout (
  const ACE_Time_Value & /* current_time */,
  const void * /* arg */)
{
  TAO_LB_Location_Map::iterator begin =
    this->location_map_.begin ();

  TAO_LB_Location_Map::iterator end =
    this->location_map_.end ();

  if (being == end)
    return 0;       // No work to be done.

  // Iterate over all registered load monitors.
  //
  // @todo This could be potentially very slow.  Improve concurrent
  //       operation at some point in the near future.
  for (TAO_LB_Location_Map::iterator i = begin;
       i != end;
       ++i)
    {
      TAO_LB_Location_Map_Entry *location = (*i).int_id_;
      if (!CORBA::is_nil (location->load_monitor.in ()))
        {
          ACE_DECLARE_NEW_CORBA_ENV;
          ACE_TRY
            {
              location->load_list =
                location->load_monitor->current_load (ACE_TRY_ENV);
              ACE_TRY_CHECK;

//               ACE_DEBUG ((LM_DEBUG,
//                           "LOCATION = %s\tLOAD = %f\n",
//                           (*i).ext_id_[0].id.in (),
//                           location->load_list[0].value));
            }
          ACE_CATCHANY
            {
              // Catch the exception and ignore it.

              if (TAO_debug_level > 0)
                ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                                     "(%P|%t) Load monitoring exception");
            }
          ACE_ENDTRY;
        }
    }

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      this->balancing_strategy_->analyze_loads (this->location_map_,
                                                ACE_TRY_ENV);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      // Catch the exception and ignore it.

      if (TAO_debug_level > 0)
        ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
                             "(%P|%t) Load analysis exception");
    }
  ACE_ENDTRY;

  return 0;
}