summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/LB_ObjectGroup_Map.h
blob: feccacfbd0707e86d3f5cc22edd4b064cd0c773a (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
// -*- C++ -*-

//=======================================================================
/**
 *  @file     LB_ObjectGroup_Map.h
 *
 *  $Id$
 *
 *  @author  Ossama Othman <ossama@uci.edu>
 */
//=======================================================================


#ifndef TAO_LB_OBJECTGROUP_MAP_H
#define TAO_LB_OBJECTGROUP_MAP_H

#include "ace/pre.h"

#include "ace/config-all.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Hash_Map_Manager_T.h"
#include "orbsvcs/LoadBalancingC.h"
#include "tao/PortableServer/Key_Adapters.h"
#include "tao/PortableServer/PortableServerC.h"

#include "LB_ReplicaInfo.h"


/**
 * @class TAO_LB_ObjectGroup_Map_Entry
 *
 * @brief Value field of the ObjectGroup map.
 */
struct TAO_LB_ObjectGroup_Map_Entry
{
public:

  /// The RepositoryId corresponding to all Replicas in the
  /// ObjectGroup.
  CORBA::String_var type_id;

  /// Reference to the ObjectGroup.
  PortableGroup::ObjectGroup_var object_group;

  /// Unbounded set containing replica references and all related
  /// information for each replica.
  TAO_LB_ReplicaInfo_Set replica_infos;

  /// Properties used when creating this object group, in addition
  /// those set dynamically after the creation.
  PortableGroup::Properties properties;

  /// Lock used to synchronize access to the ReplicaInfo set.
  TAO_SYNCH_MUTEX lock;
};

/**
 * @class TAO_LB_ObjectGroup_Map
 *
 * @brief Class that encapsulates hash map operations on an underlying
 *        object group map.
 *
 * This class contains all the operations necessary to manipulate the
 * underlying object group map.  The canonical hash map operations are
 * supported, in addition to some other operations needed for mapping
 * object group reference (rather than ObjectId) to object group map
 * entry.
 */
class TAO_LB_ObjectGroup_Map
{
public:

  /// ObjectId hash map typedef.
  typedef ACE_Hash_Map_Manager_Ex<
    PortableServer::ObjectId,
    TAO_LB_ObjectGroup_Map_Entry *,
    TAO_ObjectId_Hash,
    ACE_Equal_To<PortableServer::ObjectId>,
    TAO_SYNCH_MUTEX> Table;

  /// Forward STL-style iterator typedef.
  typedef Table::iterator iterator;

  /// Constructor
  TAO_LB_ObjectGroup_Map (void);

  /**
   * @name The Canonical Map Methods
   */
  //@{

  /// Bind the given ObjectId to the given object group map entry.
  int bind (const PortableServer::ObjectId &oid,
            TAO_LB_ObjectGroup_Map_Entry *entry);

  /// Return the object group entry corresponding to the given
  /// ObjectId.
  int find (const PortableServer::ObjectId &oid,
            TAO_LB_ObjectGroup_Map_Entry *&entry);

  /// Unbind the given ObjectId from the map.
  int unbind (const PortableServer::ObjectId &oid);

  /// Return forward iterator that points to the beginning of the
  /// underlying object group map.
  iterator begin (void);

  /// Return forward iterator that points to the end of the underlying
  /// object group map.
  iterator end (void);

  //@}

  /// Set the reference to the POA that created the object group
  /// references passed to the ObjectGroupManager methods.
  void poa (PortableServer::POA_ptr poa);

private:

  /// Obtain the ObjectGroup hash map entry corresponding to the given
  /// ObjectGroup reference.
  TAO_LB_ObjectGroup_Map_Entry *get_group_entry (
      PortableGroup::ObjectGroup_ptr object_group,
      CORBA::Environment &ACE_TRY_ENV)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     PortableGroup::ObjectGroupNotFound));

private:

  /// Reference to the POA that created the object group reference.
  PortableServer::POA_var poa_;

  /// Underlying table that maps ObjectId to object group related
  /// information.
  Table table_;

};


#if defined (__ACE_INLINE__)
#include "LB_ObjectGroup_Map.inl"
#endif  /* __ACE_INLINE__ */

#include "ace/post.h"

#endif  /* TAO_LB_OBJECTGROUP_MAP_H */