(file) Return to CIMListenerIndicationDispatcher.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Listener

  1 karl  1.6 //%2004////////////////////////////////////////////////////////////////////////
  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 tony  1.1 //
 10           // Permission is hereby granted, free of charge, to any person obtaining a copy
 11           // of this software and associated documentation files (the "Software"), to
 12           // deal in the Software without restriction, including without limitation the
 13           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 14           // sell copies of the Software, and to permit persons to whom the Software is
 15           // furnished to do so, subject to the following conditions:
 16           // 
 17           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 18           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 19           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 20           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 21           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 22           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 23           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 24           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25           //
 26           //==============================================================================
 27           //
 28           //
 29           // Author: Dong Xiang, EMC Corporation (xiang_dong@emc.com)
 30 tony  1.1 //
 31 se.gupta 1.5 // Modified By:	Seema Gupta (gseema@in.ibm.com) for PEP135
 32 tony     1.1 //
 33              //%/////////////////////////////////////////////////////////////////////////////
 34              
 35              #include "CIMListenerIndicationDispatcher.h"
 36              
 37              #include <Pegasus/Common/Config.h>
 38              #include <Pegasus/Common/Constants.h>
 39              #include <Pegasus/Common/OperationContext.h>
 40              #include <Pegasus/Common/CIMMessage.h>
 41              #include <Pegasus/Common/Thread.h>
 42              #include <Pegasus/Common/Tracer.h>
 43              
 44              #include <Pegasus/Listener/List.h>
 45              #include <Pegasus/Consumer/CIMIndicationConsumer.h>
 46 chuck    1.2 #include <Pegasus/Common/ContentLanguages.h>
 47 tony     1.1 
 48              PEGASUS_NAMESPACE_BEGIN
 49              
 50              ///////////////////////////////////////////////////////////////////////////////
 51              // CIMListenerIndicationDispatchEvent
 52              ///////////////////////////////////////////////////////////////////////////////
 53              class CIMListenerIndicationDispatchEvent
 54              {
 55              public:
 56 chuck    1.2 	CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer,
 57                                                         String url,
 58                                                         CIMInstance instance,
 59                                                         ContentLanguages contentLangs);
 60 tony     1.1 	~CIMListenerIndicationDispatchEvent();
 61              
 62              	CIMIndicationConsumer* getConsumer() const;
 63              
 64              	String getURL() const;
 65              	CIMInstance getIndicationInstance() const;
 66 chuck    1.2         ContentLanguages getContentLanguages() const; 
 67 tony     1.1 
 68              private:
 69              	CIMIndicationConsumer*	_consumer;
 70              	String									_url;
 71              	CIMInstance							_instance;
 72 chuck    1.2         ContentLanguages                    _contentLangs;
 73 tony     1.1 };
 74              
 75 chuck    1.2 CIMListenerIndicationDispatchEvent::CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer,
 76                                                                                     String url,
 77                                                                                     CIMInstance instance,
 78                                                                                     ContentLanguages contentLangs)
 79              :_consumer(consumer),_url(url),_instance(instance), _contentLangs(contentLangs)
 80 tony     1.1 {
 81              }
 82              CIMListenerIndicationDispatchEvent::~CIMListenerIndicationDispatchEvent()
 83              {
 84              }
 85              CIMIndicationConsumer* CIMListenerIndicationDispatchEvent::getConsumer() const
 86              {
 87              	return _consumer;
 88              }
 89              String CIMListenerIndicationDispatchEvent::getURL() const
 90              {
 91              	return _url;
 92              }
 93              CIMInstance CIMListenerIndicationDispatchEvent::getIndicationInstance() const
 94              {
 95              	return _instance;
 96              }
 97 chuck    1.2 ContentLanguages CIMListenerIndicationDispatchEvent::getContentLanguages() const
 98              {
 99              	return _contentLangs;
100              }
101 tony     1.1 
102              ///////////////////////////////////////////////////////////////////////////////
103              // CIMListenerIndicationDispatcherRep
104              ///////////////////////////////////////////////////////////////////////////////
105              class CIMListenerIndicationDispatcherRep
106              {
107              public:
108              	CIMListenerIndicationDispatcherRep();
109              	virtual ~CIMListenerIndicationDispatcherRep();
110              	
111              	Boolean addConsumer(CIMIndicationConsumer* consumer);
112              	Boolean removeConsumer(CIMIndicationConsumer* consumer);
113              
114              	CIMExportIndicationResponseMessage* handleIndicationRequest(CIMExportIndicationRequestMessage* request);
115              
116              	
117              	static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL deliver_routine(void *param);
118              
119              private:
120 chuck    1.2 	void	deliverIndication(String url, CIMInstance instance, ContentLanguages contentLangs);
121 tony     1.1 
122              	ThreadPool* _thread_pool;
123              	PtrList*		_consumers;
124              };
125              
126              static struct timeval create_time = {0, 1};
127              static struct timeval destroy_time = {15, 0};
128              static struct timeval deadlock_time = {0, 0};
129              
130              
131              CIMListenerIndicationDispatcherRep::CIMListenerIndicationDispatcherRep()
132              :_thread_pool(new ThreadPool(0, "ListenerIndicationDispatcher", 0, 0,
133              	create_time, destroy_time, deadlock_time))
134              ,_consumers(new PtrList())
135              {
136              	      
137              }
138              CIMListenerIndicationDispatcherRep::~CIMListenerIndicationDispatcherRep()
139              {
140              	if(_thread_pool!=NULL)
141              	{
142 tony     1.1 		 _thread_pool->kill_dead_threads();
143              		 delete _thread_pool;
144                }
145              	if(_consumers!=NULL)
146              		delete _consumers;
147              }
148              	
149              Boolean CIMListenerIndicationDispatcherRep::addConsumer(CIMIndicationConsumer* consumer)
150              {
151              	_consumers->add(consumer);
152              	return true;
153              }
154              Boolean CIMListenerIndicationDispatcherRep::removeConsumer(CIMIndicationConsumer* consumer)
155              {
156              	_consumers->remove(consumer);
157              	return true;
158              }
159              CIMExportIndicationResponseMessage* CIMListenerIndicationDispatcherRep::handleIndicationRequest(CIMExportIndicationRequestMessage* request)
160              {
161              	PEG_METHOD_ENTER(TRC_SERVER,
162              		"CIMListenerIndicationDispatcherRep::handleIndicationRequest");
163 tony     1.1 
164              	CIMInstance instance = request->indicationInstance;
165              	String			url = request->destinationPath;
166 se.gupta 1.5     ContentLanguages contentLangs =((ContentLanguageListContainer)request->operationContext.
167              			                                    get(ContentLanguageListContainer::NAME)).getLanguages();
168 tony     1.1 
169 chuck    1.2 	deliverIndication(url,instance,contentLangs);
170 tony     1.1 
171              	// compose a response message  
172              	CIMException cimException;
173              
174              	CIMExportIndicationResponseMessage* response = new CIMExportIndicationResponseMessage(
175              		request->messageId,
176              		cimException,
177              		request->queueIds.copyAndPop());
178              
179              	response->dest = request->queueIds.top();
180              
181              	PEG_METHOD_EXIT();
182              
183              	return response;
184              }
185              
186 chuck    1.2 void CIMListenerIndicationDispatcherRep::deliverIndication(String url,
187                                                                         CIMInstance instance,
188                                                                         ContentLanguages contentLangs)
189 tony     1.1 {
190              	// go thru all consumers and broadcast the result; should be run in seperate thread
191              	Iterator* it = _consumers->iterator();
192              	while(it->hasNext()==true)
193              	{
194              		CIMIndicationConsumer* consumer = static_cast<CIMIndicationConsumer*>(it->next());
195 chuck    1.2 		CIMListenerIndicationDispatchEvent* event = new CIMListenerIndicationDispatchEvent(
196                                                                                                   consumer,
197                                                                                                   url,
198                                                                                                   instance,
199                                                                                                   contentLangs);
200 denise.eckstein 1.6.2.1                 ThreadStatus rtn = _thread_pool->allocate_and_awaken(event,deliver_routine);
201                         
202                                         if (rtn != PEGASUS_THREAD_OK)
203                                         {
204                                             Logger::put(Logger::STANDARD_LOG, System::CIMSERVER, Logger::TRACE,
205                                                         "Not enough threads to allocate a worker to deliver the event. ");
206                         
207                                             Tracer::trace(TRC_SERVER, Tracer::LEVEL2,
208                                                         "Could not allocate thread to deliver event. Instead using current thread.");
209                                             delete event;
210                                             throw Exception("Not enough threads to allocate a worker to deliver the event.");
211                                         }
212 tony            1.1     	}
213                         }
214                         PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL CIMListenerIndicationDispatcherRep::deliver_routine(void *param)
215                         {
216                         	CIMListenerIndicationDispatchEvent* event = static_cast<CIMListenerIndicationDispatchEvent*>(param);
217                         
218                         	if(event!=NULL)
219                         	{
220                         		CIMIndicationConsumer* consumer = event->getConsumer();
221                         		OperationContext context;
222 chuck           1.2     	        context.insert(ContentLanguageListContainer(event->getContentLanguages()));
223 tony            1.1     		if(consumer)
224                         		{
225                         			consumer->consumeIndication(context,event->getURL(),event->getIndicationInstance());
226                         		}
227                         
228                         		delete event;
229                         	}
230                         		
231                         	return (0);
232                         }
233                         
234                         ///////////////////////////////////////////////////////////////////////////////
235                         // CIMListenerIndicationDispatcher
236                         ///////////////////////////////////////////////////////////////////////////////
237                         CIMListenerIndicationDispatcher::CIMListenerIndicationDispatcher()
238                         :Base(PEGASUS_QUEUENAME_LISTENERINDICATIONDISPACTCHER)
239                         ,_rep(new CIMListenerIndicationDispatcherRep())
240                         {
241                         }
242                         CIMListenerIndicationDispatcher::~CIMListenerIndicationDispatcher()
243                         {
244 tony            1.1     	if(_rep!=NULL)
245 tony            1.3     		delete static_cast<CIMListenerIndicationDispatcherRep*>(_rep);
246 tony            1.1     
247                         	_rep=NULL;
248                         }
249                         
250                         void CIMListenerIndicationDispatcher::handleEnqueue()
251                         {
252                         	PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue");
253                         	
254                         	Message *message = dequeue();
255                         	if(message)
256                         		handleEnqueue(message);
257                         	
258                         	PEG_METHOD_EXIT();
259                         }
260                         
261                         void CIMListenerIndicationDispatcher::handleEnqueue(Message* message)
262                         {
263                         	PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue");
264                         	
265                         	if(message!=NULL)
266                         	{
267 tony            1.1     		switch (message->getType())
268                             {
269                         			case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
270                         				{
271                         					CIMExportIndicationRequestMessage* request = (CIMExportIndicationRequestMessage*)message;
272                         
273                         					CIMExportIndicationResponseMessage* response = 
274                         						static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->handleIndicationRequest(request);
275                         
276                         					_enqueueResponse(request, response);
277                         				}
278                         				break;
279                         		default:
280                         			break;
281                             }	
282                             delete message;
283                         	}	
284                            
285                         	PEG_METHOD_EXIT();
286                         }
287                         Boolean CIMListenerIndicationDispatcher::addConsumer(CIMIndicationConsumer* consumer)
288 tony            1.1     {
289                         	return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->addConsumer(consumer);
290                         }
291                         Boolean CIMListenerIndicationDispatcher::removeConsumer(CIMIndicationConsumer* consumer)
292                         {
293                         	return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->removeConsumer(consumer);
294                         }
295                         
296                         PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2