~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/examples/Load_Balancing/Load_Balancer_i.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- C++ -*- */
2
 
// Load_Balancer_i.h,v 1.7 2003/11/04 05:21:30 dhinton Exp
3
 
// ============================================================================
4
 
//
5
 
// = FILENAME
6
 
//   Load_Balancer_i.h
7
 
//
8
 
// = DESCRIPTION
9
 
//    Defines classes that implement interfaces in Load_Balancer.idl
10
 
//
11
 
// = AUTHOR
12
 
//    Marina Spivak <marina@cs.wustl.edu>
13
 
//
14
 
// ============================================================================
15
 
 
16
 
#ifndef LOAD_BALANCER_I_H_
17
 
#define LOAD_BALANCER_I_H_
18
 
 
19
 
#include "Load_BalancerS.h"
20
 
#include "ace/Hash_Map_Manager.h"
21
 
#include "ace/SString.h"
22
 
#include "ace/Synch.h"
23
 
#include "ace/Containers.h"
24
 
#include "ace/Null_Mutex.h"
25
 
 
26
 
#if !defined (ACE_LACKS_PRAGMA_ONCE)
27
 
#pragma once
28
 
#endif /* ACE_LACKS_PRAGMA_ONCE */
29
 
 
30
 
// This is to remove "inherits via dominance" warnings from MSVC.
31
 
#if defined (_MSC_VER)
32
 
# pragma warning (disable : 4250)
33
 
#endif /* _MSC_VER */
34
 
 
35
 
class  Object_Group_Factory_i :
36
 
  public virtual POA_Load_Balancer::Object_Group_Factory,
37
 
  public virtual PortableServer::RefCountServantBase
38
 
{
39
 
  // = TITLE
40
 
  //    This class implements Load_Balancer::Object_Group_Factory idl
41
 
  //    interface.
42
 
  //
43
 
  // = DESCRIPTION
44
 
  //    This implementation uses two <ACE_Hash_Map_Manager>s
45
 
  //    to store <Group_ID> to <Object_Group> associations for all
46
 
  //    load balancing groups created by this factory (one map keeps
47
 
  //    track of all random groups, and the other keeps track of all
48
 
  //    round robin groups).
49
 
  //
50
 
public:
51
 
 
52
 
  // = Initialization and termination methods.
53
 
 
54
 
  Object_Group_Factory_i (void);
55
 
  // Constructor.
56
 
 
57
 
  ~Object_Group_Factory_i (void);
58
 
  // Destructor.
59
 
 
60
 
  // = Load_Balancer::Object_Group_Factory idl methods.
61
 
 
62
 
  Load_Balancer::Object_Group_ptr make_round_robin (const char * id
63
 
                                                    ACE_ENV_ARG_DECL)
64
 
    ACE_THROW_SPEC ((CORBA::SystemException,
65
 
                     Load_Balancer::duplicate_group));
66
 
  // Creates an <Object_Group> that resolves requests for arbitrary
67
 
  // members in round robin order.  If an <Object_Group>, of any
68
 
  // type, with Group_ID <id> has already been created by this
69
 
  // factory, and hasn't been destroyed, a <duplicate_group>
70
 
  // exception is thrown.
71
 
 
72
 
  Load_Balancer::Object_Group_ptr make_random (const char * id
73
 
                                               ACE_ENV_ARG_DECL)
74
 
    ACE_THROW_SPEC ((CORBA::SystemException,
75
 
                     Load_Balancer::duplicate_group));
76
 
  // Creates an <Object_Group> that resolves requests for arbitrary
77
 
  // members in random order.  If an <Object_Group>, of any
78
 
  // type, with Group_ID <id> has already been created by this
79
 
  // factory, and hasn't been destroyed, a <duplicate_group>
80
 
  // exception is thrown.
81
 
 
82
 
  Load_Balancer::Object_Group_ptr resolve (const char * id
83
 
                                           ACE_ENV_ARG_DECL)
84
 
    ACE_THROW_SPEC ((CORBA::SystemException,
85
 
                     Load_Balancer::no_such_group));
86
 
  // Locates and returns an <Object_Group> by its <Group_ID>.   If
87
 
  // no <Object_Group> has <Group_ID> of <id>, throw a
88
 
  // <no_such_group> exception.
89
 
 
90
 
  Load_Balancer::Group_List * round_robin_groups (ACE_ENV_SINGLE_ARG_DECL)
91
 
    ACE_THROW_SPEC ((CORBA::SystemException));
92
 
  // Lists all the round robin <Object_Group>s which were created
93
 
  // by this factory, and haven't been destroyed yet, i.e., return
94
 
  // a sequence of <Group_ID>s of all existing round robin
95
 
  // <Object_Group>s created by this factory.
96
 
 
97
 
  Load_Balancer::Group_List * random_groups (ACE_ENV_SINGLE_ARG_DECL)
98
 
    ACE_THROW_SPEC ((CORBA::SystemException));
99
 
  // Lists all the random <Object_Group>s which were created
100
 
  // by this factory, and haven't been destroyed yet, i.e., return
101
 
  // a sequence of <Group_ID>s of all existing random
102
 
  // <Object_Group>s created by this factory.
103
 
 
104
 
  // = Implementation detail methods.
105
 
 
106
 
  void remove_group (const ACE_CString &id, int random);
107
 
  // This method is invoked by an <Object_Group> with group id <id> when it
108
 
  // is being destroyed.  The method removes entry corresponding to
109
 
  // group <id> from <random_groups_> if <random> is 1 or from
110
 
  // <rr_groups_> if <random> is 0.  This recycles <id>, allowing it
111
 
  // to be used for new <Object_Group>, and prevents the destroyed
112
 
  // group from being included in lists returned from <random_groups>
113
 
  // and <round_robin_groups> methods.
114
 
 
115
 
private:
116
 
  // = Helper methods.
117
 
 
118
 
  Load_Balancer::Object_Group_ptr make_group (int random,
119
 
                                              const char * id
120
 
                                              ACE_ENV_ARG_DECL)
121
 
    ACE_THROW_SPEC ((CORBA::SystemException,
122
 
                     Load_Balancer::duplicate_group));
123
 
  // This function factors out common code in <make_round_robin> and
124
 
  // <make_random>.  Creates a random <Object_Group> if <random> parameter is
125
 
  // set to 1 and round robin <Object_Group> if it is 0.
126
 
 
127
 
  Load_Balancer::Group_List * list_groups (int random
128
 
                                           ACE_ENV_ARG_DECL);
129
 
  // This function factors out common code in <random_groups> and
130
 
  // <round_robin_groups>.  Returns a sequence of its random
131
 
  // groups if <random> parameter is set to 1 and a sequence of its
132
 
  // round robin groups if it is 0.
133
 
 
134
 
  typedef ACE_Hash_Map_Manager<ACE_CString,
135
 
    Load_Balancer::Object_Group_var, ACE_Null_Mutex> HASH_MAP;
136
 
  // Typedef for ease of use: hash map associating group ids to
137
 
  // <Object_Group> references.
138
 
 
139
 
  HASH_MAP random_groups_;
140
 
  // Map containing all random <Object_Group>s created by this factory.
141
 
 
142
 
  HASH_MAP rr_groups_;
143
 
  // Map containing all round robin <Object_Group>s created by this factory.
144
 
};
145
 
 
146
 
class Object_Group_i : public virtual POA_Load_Balancer::Object_Group,
147
 
                       public virtual PortableServer::RefCountServantBase
148
 
 
149
 
{
150
 
  // = TITLE
151
 
  //    This abstract class partially implements
152
 
  //    Load_Balancer::Object_Group idl interface.
153
 
  //
154
 
  // = DESCRIPTION
155
 
  //   <Resolve> is the only abstract method - subclasses should
156
 
  //   define it in order to implement an appropriate load balancing
157
 
  //   policy.  Other methods can be overridden as needed.  This class
158
 
  //   factors out code common to <Object_Group> implementations with
159
 
  //   different load balancing policies.
160
 
  //
161
 
public:
162
 
 
163
 
  // = Initialization and termination methods.
164
 
 
165
 
  Object_Group_i (const char * id,
166
 
                  Object_Group_Factory_i * my_factory);
167
 
  // Constructor.
168
 
 
169
 
  ~Object_Group_i (void);
170
 
  // Destructor.
171
 
 
172
 
  // = Load_Balancer::Object_Group idl methods.
173
 
 
174
 
  char * id (ACE_ENV_SINGLE_ARG_DECL)
175
 
    ACE_THROW_SPEC ((CORBA::SystemException));
176
 
  // Get group's id.
177
 
 
178
 
  void bind (const Load_Balancer::Member & member
179
 
             ACE_ENV_ARG_DECL)
180
 
    ACE_THROW_SPEC ((CORBA::SystemException,
181
 
                     Load_Balancer::duplicate_member));
182
 
  // Adds a new <member> to the <Object_Group>.  Note that each
183
 
  // <Member_ID> in an <Object_Group> must be unique.  If the
184
 
  // group already contains a member with the same <Member_ID>, a
185
 
  // <duplicate_member> exceptions is thrown.
186
 
 
187
 
  void unbind (const char * id
188
 
               ACE_ENV_ARG_DECL)
189
 
    ACE_THROW_SPEC ((CORBA::SystemException,
190
 
                     Load_Balancer::no_such_member));
191
 
  // Removes a member with the specified <Member_ID> from the
192
 
  // <Object_Group>.  If none of the group's members have a
193
 
  // Member_ID of <id>, <no_such_member> exception is thrown.
194
 
 
195
 
  CORBA::Object_ptr resolve (ACE_ENV_SINGLE_ARG_DECL)
196
 
    ACE_THROW_SPEC ((CORBA::SystemException,
197
 
                     Load_Balancer::no_such_member)) = 0;
198
 
  // Returns a member object from this <Object_Group> in accordance with
199
 
  // load balancing policy it implements, i.e., ``random'' or
200
 
  // ``round robin.''  If the group contains no members, <no_such_member>
201
 
  // exception is thrown.
202
 
 
203
 
  CORBA::Object_ptr resolve_with_id (const char * id
204
 
                                     ACE_ENV_ARG_DECL)
205
 
    ACE_THROW_SPEC ((CORBA::SystemException,
206
 
                     Load_Balancer::no_such_member));
207
 
  // Returns an object with the specified <Member_ID>.  If this
208
 
  // <Object_Group> contains no members with the specified
209
 
  // <Member_ID>, <no_such_member> exception is thrown.
210
 
 
211
 
  Load_Balancer::Member_ID_List * members (ACE_ENV_SINGLE_ARG_DECL)
212
 
    ACE_THROW_SPEC ((CORBA::SystemException));
213
 
  // Return a sequence of <Member_ID>s of all of its members.
214
 
 
215
 
  void destroy (ACE_ENV_SINGLE_ARG_DECL)
216
 
    ACE_THROW_SPEC ((CORBA::SystemException));
217
 
  // Cleanup the resources associated with this <Object_Group>.
218
 
  // Subsequent calls to this <Object_Group> should fail, and its
219
 
  // <id> should become available.  <Object_Group_Factory>
220
 
  // should no longer list this <Object_Group>.
221
 
 
222
 
protected:
223
 
 
224
 
  typedef ACE_DLList<ACE_CString> LIST;
225
 
  typedef ACE_DLList_Iterator<ACE_CString> ITERATOR;
226
 
  typedef ACE_Hash_Map_Manager<ACE_CString, CORBA::Object_var,
227
 
    ACE_Null_Mutex> HASH_MAP;
228
 
  // Typedefs for ease of use.
229
 
 
230
 
  LIST member_id_list_;
231
 
  // List of ids of all the members of this group.
232
 
 
233
 
  HASH_MAP members_;
234
 
  // Mapping of member_id to obj for all the members of this group.
235
 
 
236
 
  // Note, we store information redundantly in this implementation,
237
 
  // i.e., both <member_id_list_> and <members_> store member ids.
238
 
  // However, this redundancy eases/speeds up the implementation of
239
 
  // certain operations.  <member_id_list_> is useful for implementing
240
 
  // variations of <resolve> method to implement different policies.
241
 
  // <members_> is useful for doing id-based look-up.
242
 
 
243
 
  ACE_CString id_;
244
 
  // This group's id.
245
 
 
246
 
  Object_Group_Factory_i *my_factory_;
247
 
  // Pointer to the <Object_Group_Factory> servant, which created this
248
 
  // <Object_Group> servant.  We need this pointer to be able to
249
 
  // notify the factory when this <Object_Group> is destroyed.  Upon
250
 
  // notification, the factory can update its records and release
251
 
  // resources as necessary.
252
 
};
253
 
 
254
 
 
255
 
class Random_Object_Group : public Object_Group_i
256
 
{
257
 
  // = TITLE
258
 
  //    This class implements <Object_Group> idl interface with the
259
 
  //    random policy for <resolve>.
260
 
  //
261
 
public:
262
 
  Random_Object_Group (const char *id,
263
 
                       Object_Group_Factory_i *my_factory);
264
 
  // Constructor.
265
 
 
266
 
  ~Random_Object_Group (void);
267
 
  // Destructor.
268
 
 
269
 
  CORBA::Object_ptr resolve (ACE_ENV_SINGLE_ARG_DECL)
270
 
    ACE_THROW_SPEC ((CORBA::SystemException,
271
 
                     Load_Balancer::no_such_member));
272
 
  // Returns a member object from this <Object_Group> in accordance with
273
 
  // the "random" load balancing policy.
274
 
 
275
 
  void destroy (ACE_ENV_SINGLE_ARG_DECL)
276
 
    ACE_THROW_SPEC ((CORBA::SystemException));
277
 
  // Cleanup the resources associated with this <Object_Group>.
278
 
  // Subsequent calls to this <Object_Group> should fail, and its
279
 
  // <id> should become available.  <Object_Group_Factory>
280
 
  // should no longer list this <Object_Group>.
281
 
};
282
 
 
283
 
class RR_Object_Group: public Object_Group_i
284
 
{
285
 
  // = TITLE
286
 
  //    This class implements <Object_Group> idl interface with the
287
 
  //    round robin policy for <resolve>.
288
 
  //
289
 
public:
290
 
 
291
 
  RR_Object_Group (const char *id,
292
 
                   Object_Group_Factory_i *my_factory);
293
 
  // Constructor.
294
 
 
295
 
  ~RR_Object_Group (void);
296
 
  // Destructor.
297
 
 
298
 
  void unbind (const char * id
299
 
               ACE_ENV_ARG_DECL)
300
 
    ACE_THROW_SPEC ((CORBA::SystemException,
301
 
                     Load_Balancer::no_such_member));
302
 
  // We need to override the implementation of <unbind> from
303
 
  // Object_Group_i to make sure <resolve>
304
 
  // works correctly.
305
 
 
306
 
  CORBA::Object_ptr resolve (ACE_ENV_SINGLE_ARG_DECL)
307
 
    ACE_THROW_SPEC ((CORBA::SystemException,
308
 
                     Load_Balancer::no_such_member));
309
 
  // Returns a member object from this <Object_Group> in accordance with
310
 
  // the "round robin" load balancing policy.
311
 
 
312
 
  void destroy (ACE_ENV_SINGLE_ARG_DECL)
313
 
    ACE_THROW_SPEC ((CORBA::SystemException));
314
 
  // Cleanup the resources associated with this <Object_Group>.
315
 
  // Subsequent calls to this <Object_Group> should fail, and its
316
 
  // <id> should become available.  <Object_Group_Factory>
317
 
  // should no longer list this <Object_Group>.
318
 
 
319
 
private:
320
 
 
321
 
  size_t next_;
322
 
  // Index into the Object_Group_i::member_id_list_: keeps track of
323
 
  // the member_id to return on the next invocation of <resolve>.
324
 
};
325
 
 
326
 
#endif /* LOAD_BALANCER_I_H_  */