1 karl 1.12 //%2006////////////////////////////////////////////////////////////////////////
|
2 tony 1.1 //
|
3 karl 1.6 // 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 karl 1.4 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.6 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.7 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.12 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 tony 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 venkat.puvvada 1.15 //
|
21 tony 1.1 // 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 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include "CIMListenerIndicationDispatcher.h"
35
36 #include <Pegasus/Common/Config.h>
37 #include <Pegasus/Common/Constants.h>
38 #include <Pegasus/Common/OperationContext.h>
39 #include <Pegasus/Common/CIMMessage.h>
40 #include <Pegasus/Common/Thread.h>
41 #include <Pegasus/Common/Tracer.h>
42 tony 1.1
43 #include <Pegasus/Listener/List.h>
44 #include <Pegasus/Consumer/CIMIndicationConsumer.h>
|
45 kumpf 1.11 #include <Pegasus/Common/ContentLanguageList.h>
|
46 tony 1.1
47 PEGASUS_NAMESPACE_BEGIN
48
49 ///////////////////////////////////////////////////////////////////////////////
50 // CIMListenerIndicationDispatchEvent
51 ///////////////////////////////////////////////////////////////////////////////
52 class CIMListenerIndicationDispatchEvent
53 {
54 public:
|
55 chuck 1.2 CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer,
56 String url,
57 CIMInstance instance,
|
58 kumpf 1.11 ContentLanguageList contentLangs);
|
59 tony 1.1 ~CIMListenerIndicationDispatchEvent();
60
61 CIMIndicationConsumer* getConsumer() const;
62
63 String getURL() const;
64 CIMInstance getIndicationInstance() const;
|
65 venkat.puvvada 1.15 ContentLanguageList getContentLanguages() const;
|
66 tony 1.1
67 private:
68 CIMIndicationConsumer* _consumer;
69 String _url;
70 CIMInstance _instance;
|
71 kumpf 1.11 ContentLanguageList _contentLangs;
|
72 tony 1.1 };
73
|
74 chuck 1.2 CIMListenerIndicationDispatchEvent::CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer,
75 String url,
76 CIMInstance instance,
|
77 kumpf 1.11 ContentLanguageList contentLangs)
|
78 chuck 1.2 :_consumer(consumer),_url(url),_instance(instance), _contentLangs(contentLangs)
|
79 tony 1.1 {
80 }
81 CIMListenerIndicationDispatchEvent::~CIMListenerIndicationDispatchEvent()
82 {
83 }
84 CIMIndicationConsumer* CIMListenerIndicationDispatchEvent::getConsumer() const
85 {
86 return _consumer;
87 }
88 String CIMListenerIndicationDispatchEvent::getURL() const
89 {
90 return _url;
91 }
92 CIMInstance CIMListenerIndicationDispatchEvent::getIndicationInstance() const
93 {
94 return _instance;
95 }
|
96 kumpf 1.11 ContentLanguageList CIMListenerIndicationDispatchEvent::getContentLanguages() const
|
97 chuck 1.2 {
98 return _contentLangs;
99 }
|
100 tony 1.1
101 ///////////////////////////////////////////////////////////////////////////////
102 // CIMListenerIndicationDispatcherRep
103 ///////////////////////////////////////////////////////////////////////////////
104 class CIMListenerIndicationDispatcherRep
105 {
106 public:
107 CIMListenerIndicationDispatcherRep();
108 virtual ~CIMListenerIndicationDispatcherRep();
|
109 venkat.puvvada 1.15
|
110 tony 1.1 Boolean addConsumer(CIMIndicationConsumer* consumer);
111 Boolean removeConsumer(CIMIndicationConsumer* consumer);
112
113 CIMExportIndicationResponseMessage* handleIndicationRequest(CIMExportIndicationRequestMessage* request);
114
|
115 venkat.puvvada 1.15
|
116 mike 1.13 static ThreadReturnType PEGASUS_THREAD_CDECL deliver_routine(void *param);
|
117 tony 1.1
118 private:
|
119 kumpf 1.11 void deliverIndication(String url, CIMInstance instance, ContentLanguageList contentLangs);
|
120 tony 1.1
121 ThreadPool* _thread_pool;
122 PtrList* _consumers;
123 };
124
|
125 kumpf 1.9 static struct timeval deallocateWait = {15, 0};
|
126 tony 1.1
127
128 CIMListenerIndicationDispatcherRep::CIMListenerIndicationDispatcherRep()
129 :_thread_pool(new ThreadPool(0, "ListenerIndicationDispatcher", 0, 0,
|
130 kumpf 1.9 deallocateWait))
|
131 tony 1.1 ,_consumers(new PtrList())
132 {
|
133 venkat.puvvada 1.15
|
134 tony 1.1 }
135 CIMListenerIndicationDispatcherRep::~CIMListenerIndicationDispatcherRep()
136 {
|
137 kumpf 1.9 delete _thread_pool;
138 delete _consumers;
|
139 tony 1.1 }
|
140 venkat.puvvada 1.15
|
141 tony 1.1 Boolean CIMListenerIndicationDispatcherRep::addConsumer(CIMIndicationConsumer* consumer)
142 {
143 _consumers->add(consumer);
144 return true;
145 }
146 Boolean CIMListenerIndicationDispatcherRep::removeConsumer(CIMIndicationConsumer* consumer)
147 {
148 _consumers->remove(consumer);
149 return true;
150 }
151 CIMExportIndicationResponseMessage* CIMListenerIndicationDispatcherRep::handleIndicationRequest(CIMExportIndicationRequestMessage* request)
152 {
153 PEG_METHOD_ENTER(TRC_SERVER,
154 "CIMListenerIndicationDispatcherRep::handleIndicationRequest");
155
156 CIMInstance instance = request->indicationInstance;
157 String url = request->destinationPath;
|
158 kumpf 1.11 ContentLanguageList contentLangs =((ContentLanguageListContainer)request->operationContext.
|
159 se.gupta 1.5 get(ContentLanguageListContainer::NAME)).getLanguages();
|
160 tony 1.1
|
161 chuck 1.2 deliverIndication(url,instance,contentLangs);
|
162 tony 1.1
|
163 venkat.puvvada 1.15 // compose a response message
|
164 tony 1.1 CIMException cimException;
165
166 CIMExportIndicationResponseMessage* response = new CIMExportIndicationResponseMessage(
167 request->messageId,
168 cimException,
169 request->queueIds.copyAndPop());
170
171 response->dest = request->queueIds.top();
172
173 PEG_METHOD_EXIT();
174
175 return response;
176 }
177
|
178 chuck 1.2 void CIMListenerIndicationDispatcherRep::deliverIndication(String url,
179 CIMInstance instance,
|
180 kumpf 1.11 ContentLanguageList contentLangs)
|
181 tony 1.1 {
182 // go thru all consumers and broadcast the result; should be run in seperate thread
|
183 venkat.puvvada 1.15 AutoPtr<Iterator> it( _consumers->iterator() );
184
|
185 tony 1.1 while(it->hasNext()==true)
186 {
187 CIMIndicationConsumer* consumer = static_cast<CIMIndicationConsumer*>(it->next());
|
188 chuck 1.2 CIMListenerIndicationDispatchEvent* event = new CIMListenerIndicationDispatchEvent(
189 consumer,
190 url,
191 instance,
192 contentLangs);
|
193 konrad.r 1.10 ThreadStatus rtn = _thread_pool->allocate_and_awaken(event,deliver_routine);
|
194 venkat.puvvada 1.15
195 if (rtn != PEGASUS_THREAD_OK)
|
196 konrad.r 1.10 {
|
197 yi.zhou 1.14 Logger::put(Logger::STANDARD_LOG, System::CIMLISTENER, Logger::TRACE,
|
198 konrad.r 1.10 "Not enough threads to allocate a worker to deliver the event. ");
|
199 venkat.puvvada 1.15
|
200 marek 1.16 PEG_TRACE_CSTRING(TRC_SERVER, Tracer::LEVEL2,
|
201 konrad.r 1.10 "Could not allocate thread to deliver event. Instead using current thread.");
202 delete event;
203 throw Exception(MessageLoaderParms("Listener.CIMListenerIndicationDispatcher.CANNOT_ALLOCATE_THREAD",
204 "Not enough threads to allocate a worker to deliver the event."));
205 }
|
206 tony 1.1 }
207 }
|
208 mike 1.13 ThreadReturnType PEGASUS_THREAD_CDECL CIMListenerIndicationDispatcherRep::deliver_routine(void *param)
|
209 tony 1.1 {
210 CIMListenerIndicationDispatchEvent* event = static_cast<CIMListenerIndicationDispatchEvent*>(param);
211
212 if(event!=NULL)
213 {
214 CIMIndicationConsumer* consumer = event->getConsumer();
215 OperationContext context;
|
216 chuck 1.2 context.insert(ContentLanguageListContainer(event->getContentLanguages()));
|
217 tony 1.1 if(consumer)
218 {
219 consumer->consumeIndication(context,event->getURL(),event->getIndicationInstance());
220 }
221
222 delete event;
223 }
|
224 venkat.puvvada 1.15
|
225 tony 1.1 return (0);
226 }
227
228 ///////////////////////////////////////////////////////////////////////////////
229 // CIMListenerIndicationDispatcher
230 ///////////////////////////////////////////////////////////////////////////////
231 CIMListenerIndicationDispatcher::CIMListenerIndicationDispatcher()
232 :Base(PEGASUS_QUEUENAME_LISTENERINDICATIONDISPACTCHER)
233 ,_rep(new CIMListenerIndicationDispatcherRep())
234 {
235 }
236 CIMListenerIndicationDispatcher::~CIMListenerIndicationDispatcher()
237 {
238 if(_rep!=NULL)
|
239 tony 1.3 delete static_cast<CIMListenerIndicationDispatcherRep*>(_rep);
|
240 tony 1.1
241 _rep=NULL;
242 }
243
244 void CIMListenerIndicationDispatcher::handleEnqueue()
245 {
246 PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue");
|
247 venkat.puvvada 1.15
|
248 tony 1.1 Message *message = dequeue();
249 if(message)
250 handleEnqueue(message);
|
251 venkat.puvvada 1.15
|
252 tony 1.1 PEG_METHOD_EXIT();
253 }
254
255 void CIMListenerIndicationDispatcher::handleEnqueue(Message* message)
256 {
257 PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue");
|
258 venkat.puvvada 1.15
|
259 tony 1.1 if(message!=NULL)
260 {
261 switch (message->getType())
262 {
263 case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
264 {
265 CIMExportIndicationRequestMessage* request = (CIMExportIndicationRequestMessage*)message;
266
|
267 venkat.puvvada 1.15 CIMExportIndicationResponseMessage* response =
|
268 tony 1.1 static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->handleIndicationRequest(request);
269
270 _enqueueResponse(request, response);
271 }
272 break;
273 default:
274 break;
|
275 venkat.puvvada 1.15 }
|
276 tony 1.1 delete message;
|
277 venkat.puvvada 1.15 }
278
|
279 tony 1.1 PEG_METHOD_EXIT();
280 }
281 Boolean CIMListenerIndicationDispatcher::addConsumer(CIMIndicationConsumer* consumer)
282 {
283 return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->addConsumer(consumer);
284 }
285 Boolean CIMListenerIndicationDispatcher::removeConsumer(CIMIndicationConsumer* consumer)
286 {
287 return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->removeConsumer(consumer);
288 }
289
290 PEGASUS_NAMESPACE_END
|