summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/EC_ConsumerAdmin_T.h
blob: a3312e2efc609452f2201335dde2c4d904c1f935 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/* -*- C++ -*- */
// $Id$
//
// ============================================================================
//
// = LIBRARY
//   ORBSVCS Real-time Event Channel
//
// = FILENAME
//   EC_ConsumerAdmin_T
//
// = AUTHOR
//   Carlos O'Ryan (coryan@cs.wustl.edu)
//
// = DESCRIPTION
//   Implement concrete versions of the EC_ConsumerAdmin class. This
//   concrete versions provide specific locking policies and
//   strategies to handle delayed vs. immediate connections and
//   disconnections.
//
// = CREDITS
//   Based on previous work by Tim Harrison (harrison@cs.wustl.edu)
//   and other members of the DOC group.
//   More details can be found in:
//   http://www.cs.wustl.edu/~schmidt/oopsla.ps.gz
//   http://www.cs.wustl.edu/~schmidt/JSAC-98.ps.gz
//
//
// ============================================================================

#ifndef TAO_EC_CONSUMERADMIN_T_H
#define TAO_EC_CONSUMERADMIN_T_H

#include "EC_ConsumerAdmin.h"

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

template<ACE_SYNCH_DECL>
class TAO_EC_ConsumerAdmin_T : public TAO_EC_ConsumerAdmin
{
  // = TITLE
  //   ConsumerAdmin_T
  //
  // = DESCRIPTION
  //   Implements the locking policies for the TAO_EC_ConsumerAdmin
  //   class, we use a parametric class to handle the co-variations
  //   between mutexes and condition variables.
  //
  // = MEMORY MANAGMENT
  //
  // = LOCKING
  //   The kind of locking is specified as the template argument.
  //   Clients still should follow the locking protocol: call busy()
  //   to use the iterator and idle() once finished, the
  //   Busy_Lock_Adapter can help there.
  //
  // = TODO
  //
public:
  TAO_EC_ConsumerAdmin_T (TAO_EC_Event_Channel* event_channel);
  // constructor...

  // = The TAO_EC_ConsumerAdmin methods
  virtual int busy (void);
  virtual int idle (void);

protected:
  virtual int busy_i (void);
  // Implements the busy() method, but without locking.

  virtual int idle_i (void);
  // Implements the busy() method, but without locking.

protected:
  int busy_count (void) const;
  // Return the current value of busy_count [derived classes are not
  // allowed to modify this]

  ACE_SYNCH_MUTEX_T lock_;
  // The lock

  ACE_SYNCH_CONDITION_T busy_cond_;
  // A condition variable to wait while the object is too busy.

private:
  int busy_count_;
  // The number of threads iterating on us

  int reached_hwm_;
  // The set was too busy and reached its HWM, now everybody has to
  // wait until we reach the LWM (0)
};

// ****************************************************************

template<ACE_SYNCH_DECL>
class TAO_EC_ConsumerAdmin_Immediate : public TAO_EC_ConsumerAdmin_T<ACE_SYNCH_USE>
{
  // = TITLE
  //   ConsumerAdmin_Immediate
  //
  // = DESCRIPTION
  //   A concrete version of the EC_ConsumerAdmin class; using the
  //   locking strategy in EC_ConsumerAdmin_T and immediate execution
  //   for the connected() and disconnected() operations.
  //
  // = MEMORY MANAGMENT
  //
  // = LOCKING
  //   The kind of locking is specified as the template argument.
  //   Clients still should follow the locking protocol: call busy()
  //   to use the iterator and idle() once finished, the
  //   Busy_Lock_Adapter can help there.
  //
  // = TODO
  //
public:
  TAO_EC_ConsumerAdmin_Immediate (TAO_EC_Event_Channel* event_channel);
  // constructor...

  // = The TAO_EC_ConsumerAdmin methods
  virtual void connected (TAO_EC_ProxyPushSupplier*,
                          CORBA::Environment&);
  virtual void disconnected (TAO_EC_ProxyPushSupplier*,
                             CORBA::Environment&);
};

// ****************************************************************

template<ACE_SYNCH_DECL>
class TAO_EC_ConsumerAdmin_Delayed : public TAO_EC_ConsumerAdmin_T<ACE_SYNCH_USE>
{
  // = TITLE
  //   ConsumerAdmin_Delayed
  //
  // = DESCRIPTION
  //   A concrete version of the EC_ConsumerAdmin class; using the
  //   locking strategy in EC_ConsumerAdmin_T and storing the
  //   execution of connected() and disconnected() operations as
  //   command objects, that are executed once the set is idle.
  //
  // = MEMORY MANAGMENT
  //
  // = LOCKING
  //   The kind of locking is specified as the template argument.
  //   Clients still should follow the locking protocol: call busy()
  //   to use the iterator and idle() once finished, the
  //   Busy_Lock_Adapter can help there.
  //
  // = TODO
  //
public:
  TAO_EC_ConsumerAdmin_Delayed (TAO_EC_Event_Channel* event_channel);
  // constructor...

  // = The TAO_EC_ConsumerAdmin methods
  virtual void connected (TAO_EC_ProxyPushSupplier*,
                          CORBA::Environment&);
  virtual void disconnected (TAO_EC_ProxyPushSupplier*,
                             CORBA::Environment&);

protected:
  virtual void execute_delayed_operations (void);
  // documented in TAO_EC_ConsumerAdmin

private:
  ACE_Unbounded_Queue<ACE_Command_Base*> command_queue_;
  // The commands that carry the delayed operations are enqueued
  // here.
};

// ****************************************************************

#if defined (__ACE_INLINE__)
#include "EC_ConsumerAdmin_T.i"
#endif /* __ACE_INLINE__ */

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "EC_ConsumerAdmin_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("EC_ConsumerAdmin_T.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#endif /* TAO_EC_CONSUMERADMIN_T_H */