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

#include "LB_Pull_Handler.h"

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

TAO_LB_Pull_Handler::TAO_LB_Pull_Handler (
  TAO_LB_ObjectGroup_Map &object_group_map)
  : object_group_map_ (object_group_map)
{
}

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

  TAO_LB_ObjectGroup_Map::iterator begin =
    this->object_group_map_.end ();

  // Iterate over all registered object groups.
  //
  // @todo This could be potentially very slow.  Improve concurrent
  //       operation at some point in the near future.
  for (TAO_LB_ObjectGroup_Map::iterator i = begin;
       i != end;
       ++i
  {
    TAO_LB_ObjectGroup_Map_Entry *object_group = i->ext_id_;

    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, object_group->lock, 0);

    if (entry->replica_infos.is_empty ())
      // @@ What do we do if the set is empty?
      continue;

    TAO_LB_ReplicaInfo_Set::iterator begin =
      object_group->replica_infos.begin ();

    TAO_LB_ReplicaInfo_Set::iterator end =
      object_group->replica_infos.end ();

    // Now iterate over the replica set.

      TAO_LB_ReplicaInfo *replica_info = (*i);

      for (TAO_LB_ReplicaInfo_Set::iterator i = begin;
           i != end;
           ++i)
        {
          LoadBalancing::LoadList_var load =
            (*i)->load_monitor->current_load (ACE_TRY_ENV);
          ACE_CHECK_RETURN (CORBA::Object::_nil ());

          // @@ Hardcode one load and don't bother checking the
          // LoadId, for now.  (just to get things going)
          if (d[CORBA::Long (0)].value > load[CORBA::Long (0)].value)
            {
              replica_info = *i;
              d = (*i)->load_monitor->current_load (ACE_TRY_ENV);
              ACE_CHECK_RETURN (CORBA::Object::_nil ());
            }
        }

  }


  return 0;
}