blob: ad03b42708cce44f6b60294f594803e2fa6d469a (
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
|
// -*- C++ -*-
// $Id$
#include "orbsvcs/Naming/FaultTolerant/FT_Round_Robin.h"
#include "orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h"
#include "orbsvcs/PortableGroup/PG_conf.h"
#include "tao/debug.h"
#include "tao/ORB_Constants.h"
TAO_BEGIN_VERSIONED_NAMESPACE_DECL
TAO_FT_Round_Robin::TAO_FT_Round_Robin (void)
: lock_ (),
location_index_map_ (TAO_PG_MAX_OBJECT_GROUPS)
{
}
TAO_FT_Round_Robin::~TAO_FT_Round_Robin (void)
{
}
bool
TAO_FT_Round_Robin::next_location (
PortableGroup::ObjectGroup_ptr object_group,
TAO_FT_Naming_Manager *naming_manager,
PortableGroup::Location& location)
{
// TODO: Simplify the algorithm to store a map of object
// group id to last location index. We will round robin
// over this list assuming the list will not change that often.
const PortableGroup::ObjectGroupId id =
naming_manager->get_object_group_id (object_group);
ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
monitor,
this->lock_,
0);
// If entry is already in the map for this id
// Get the index
// increment the index
// if the index is past the length set it to the first element
// Else
// Set the index to 0
// Add the entry in the map
//
PortableGroup::Locations_var locations =
naming_manager->locations_of_members (object_group);
const CORBA::ULong len = locations->length ();
// No locations exist, so we cant get the next one
if (len == 0)
return false;
TAO_FT_Location_Index_Map::ENTRY * entry;
if (this->location_index_map_.find (id, entry) == 0)
{
CORBA::ULong & i = entry->int_id_;
// Increment index to point to next location.
i++;
if (len <= i)
i = 0; // Reset, i.e. wrap around
location = locations[i];
return true;
}
// Could not find an entry
// Create an entry at location 0
const CORBA::ULong start = 0;
location = locations[start];
if (this->location_index_map_.bind (id, start) != 0)
{ // The location was already bound or some failure occured. Should not happen.
throw CORBA::INTERNAL ();
}
return true;
}
TAO_END_VERSIONED_NAMESPACE_DECL
|