1 karl 1.7 //%2006////////////////////////////////////////////////////////////////////////
|
2 h.sterling 1.1 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.7 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 h.sterling 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Heather Sterling (hsterl@us.ibm.com)
33 //
34 h.sterling 1.1 // Modified By:
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #ifndef Pegasus_Dynamic_Consumer_h
39 #define Pegasus_Dynamic_Consumer_h
40
41 #include <Pegasus/Common/Config.h>
|
42 h.sterling 1.5 #include <Pegasus/Common/ArrayInternal.h>
|
43 h.sterling 1.1 #include <Pegasus/Common/System.h>
44 #include <Pegasus/Common/Thread.h>
|
45 mike 1.8 #include <Pegasus/Common/List.h>
|
46 mike 1.9 #include <Pegasus/Common/Mutex.h>
|
47 h.sterling 1.1 #include <Pegasus/DynListener/Linkage.h>
48 #include <Pegasus/Provider/CIMOMHandle.h>
49 #include "DynamicConsumerFacade.h"
50 #include "ConsumerModule.h"
51
52 PEGASUS_NAMESPACE_BEGIN
53
54
55 /** The IndicationDispatchEvent class encapsulates an event and all of the information associated with the event.
56 * The operation context, URL, and the CIM indication instance are the parameters to the consumeIndication() method
57 * of the CIMIndicationConsumer interface. Additionally, we need to store the number of retries in order to resend
58 * indications if the consumer fails.
59 */
|
60 mike 1.8 class PEGASUS_DYNLISTENER_LINKAGE IndicationDispatchEvent : public Linkable
|
61 h.sterling 1.1 {
62 public:
63
|
64 h.sterling 1.5 IndicationDispatchEvent();
65
|
66 h.sterling 1.1 IndicationDispatchEvent(OperationContext context,
67 String url,
68 CIMInstance instance);
69
|
70 h.sterling 1.6 IndicationDispatchEvent(const IndicationDispatchEvent &event);
71
|
72 h.sterling 1.1 ~IndicationDispatchEvent();
73
74 OperationContext getContext() const;
75
76 String getURL() const;
77
78 CIMInstance getIndicationInstance() const;
79
|
80 mike 1.4 Uint32 getRetries();
|
81 h.sterling 1.1
82 void increaseRetries();
83
|
84 h.sterling 1.2 CIMDateTime getLastAttemptTime();
85
|
86 h.sterling 1.5 IndicationDispatchEvent& operator=(const IndicationDispatchEvent &event);
87
|
88 h.sterling 1.1 Boolean operator==(const IndicationDispatchEvent &event) const;
89
90 private:
91 OperationContext _context;
92 String _url;
93 CIMInstance _instance;
94 AtomicInt _retries;
|
95 h.sterling 1.2 CIMDateTime _lastAttemptTime;
|
96 h.sterling 1.1
97 };
98
99
100
101 /** The DynamicConsumer class represents the logical consumer extracted from a
102 * consumer module. It is wrapped in a facade to stabalize the interface
103 * and is directly tied to a module.
104 *
105 * The synchronization of these actions is left up to the caller. For example,
106 * the caller must ensure that terminate is not called while initialize is executing.
107 * The ConsumerManager uses a consumer table mutex to ensure that no mutually exclusive
108 * operations occur at the same time. The exception to this is the operation of the worker
109 * thread, which is signalled during a shutdown operation or when a new event occurs.
110 */
111
112 class PEGASUS_DYNLISTENER_LINKAGE DynamicConsumer : public DynamicConsumerFacade
113 {
114 public:
115
116 typedef DynamicConsumerFacade Base;
117 h.sterling 1.1
118 DynamicConsumer();
119
120 DynamicConsumer(const String& name);
121
122 DynamicConsumer(const String & name,
123 ConsumerModule* consumerModule,
124 CIMIndicationConsumerProvider* consumerRef);
125
126 ~DynamicConsumer(void);
127
128 virtual void initialize(void);
129
130 virtual void terminate(void);
131
132 void enqueueEvent(IndicationDispatchEvent* event);
133
134 void sendShutdownSignal();
135
136 String getName(void) const;
137
138 h.sterling 1.1 Boolean isInitialized(void) const;
139
140 Boolean isLoaded(void) const;
141
|
142 h.sterling 1.3 void waitForEventThread(void);
143
|
144 h.sterling 1.1 Boolean isIdle(void);
145
146 virtual void getIdleTimer(struct timeval *);
147
148 virtual void updateIdleTimer(void);
149
150 Uint32 getPendingIndications(void);
151
152 void set(ConsumerModule* consumerModule,
153 CIMIndicationConsumerProvider* consumerRef);
154
155 Semaphore* getShutdownSemaphore();
156
157 void setShutdownSemaphore(Semaphore* shutdownSempahore);
158
159 void reset();
160
161 String toString();
162
163 protected:
164 ConsumerModule* _module;
165 h.sterling 1.1
166 private:
167 friend class ConsumerManager;
168
169 //indication queue
|
170 mike 1.9 List<IndicationDispatchEvent,Mutex> _eventqueue;
|
171 h.sterling 1.1
172 //this mutex controls the state of the consumer to ensure it is not initializing, terminating, etc at the same time
173 //ATTN: Do we need this? The ConsumerManager will be controlling the status of the consumers.
174 //Check back here when doing global queue
175 Mutex _statusMutex;
176
177 //physical consumer variables
178 CIMIndicationConsumerProvider* getConsumer();
179 ConsumerModule* getModule(void) const;
180
181 String _name;
182 String _fileName;
183
184 //state variables
185 Boolean _initialized;
186 Boolean _dieNow; //indicates we are shutting down
187
188 // we must keep track of this ourself, since we cannot use the cimomhandle
189 struct timeval _idleTime;
190 Mutex _idleTimeMutex;
191 Boolean _no_unload;
192 h.sterling 1.1
193 //Signals the worker thread to wake up and check the queue.
194 //This is signalled in the following scenarios:
195 // 1) shutdown event
196 // 2) event was placed in queue
197 // This allows for a simulated "WaitForMultipleObjects"
198 Semaphore* _check_queue;
199
|
200 h.sterling 1.3 //Signals that the event thread is listening and can now be signalled.
201 //This eliminates any synchronization issues that may occur when the first event comes in or if shutdown is called
202 //right as the consumer thread is being started
203 Semaphore* _listeningSemaphore;
|
204 h.sterling 1.1
205 //ATTN: For now, we must store the shutdown semaphore on the consumer, in order to be able to gracefully
206 //unload it during a normal shutdown OR an idle shutdown. Pegasus's ThreadPool does not provide
207 //a way to access any thread information once it is spawned; the only option is to pass a blocking
208 //semaphore in, which will signal when the thread completes. Since we are using one dedicated thread
209 //per consumer for now, we can store one shutdown semaphore per consumer. We'll change the implementation
210 //when we go to a global queue.
211
212 //This is used to tell the consumer manager that the worker thread has indeed stopped
213 //it's passed in from the manager during initialization and can be checked to determine
214 //whether the consumer can be unloaded. This setup will change as the global queueing is
215 //set up.
216 Semaphore* _shutdownSemaphore;
217
218 //these functions are used to serialize and deserialize outstanding indications
|
219 h.sterling 1.5 void _loadOutstandingIndications(Array<IndicationDispatchEvent> indications);
|
220 h.sterling 1.1
|
221 h.sterling 1.5 Array<IndicationDispatchEvent> _retrieveOutstandingIndications();
|
222 h.sterling 1.1
223 };
224
225 PEGASUS_NAMESPACE_END
226
227 #endif
228
|