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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2