version 1.1, 2003/08/15 14:10:29
|
version 1.21, 2008/12/01 17:50:44
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%LICENSE//////////////////////////////////////////////////////////////// |
// |
|
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
|
// The Open Group, Tivoli Systems |
|
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// Licensed to The Open Group (TOG) under one or more contributor license |
// of this software and associated documentation files (the "Software"), to |
// agreements. Refer to the OpenPegasusNOTICE.txt file distributed with |
// deal in the Software without restriction, including without limitation the |
// this work for additional information regarding copyright ownership. |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// Each contributor licenses this file to you under the OpenPegasus Open |
// sell copies of the Software, and to permit persons to whom the Software is |
// Source License; you may not use this file except in compliance with the |
// furnished to do so, subject to the following conditions: |
// License. |
// | // |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// Permission is hereby granted, free of charge, to any person obtaining a |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// copy of this software and associated documentation files (the "Software"), |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
// to deal in the Software without restriction, including without limitation |
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
// and/or sell copies of the Software, and to permit persons to whom the |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
// Software is furnished to do so, subject to the following conditions: |
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
// | // |
//============================================================================== |
// The above copyright notice and this permission notice shall be included |
|
// in all copies or substantial portions of the Software. |
// | // |
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
// | // |
// Author: Dong Xiang, EMC Corporation (xiang_dong@emc.com) |
////////////////////////////////////////////////////////////////////////// |
// |
|
// Modified By: |
|
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
| |
#include <Pegasus/Listener/List.h> | #include <Pegasus/Listener/List.h> |
#include <Pegasus/Consumer/CIMIndicationConsumer.h> | #include <Pegasus/Consumer/CIMIndicationConsumer.h> |
|
#include <Pegasus/Common/ContentLanguageList.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
class CIMListenerIndicationDispatchEvent | class CIMListenerIndicationDispatchEvent |
{ | { |
public: | public: |
CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer, String url, CIMInstance instance); |
CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer, |
|
String url, |
|
CIMInstance instance, |
|
ContentLanguageList contentLangs); |
~CIMListenerIndicationDispatchEvent(); | ~CIMListenerIndicationDispatchEvent(); |
| |
CIMIndicationConsumer* getConsumer() const; | CIMIndicationConsumer* getConsumer() const; |
| |
String getURL() const; | String getURL() const; |
CIMInstance getIndicationInstance() const; | CIMInstance getIndicationInstance() const; |
|
ContentLanguageList getContentLanguages() const; |
| |
private: | private: |
CIMIndicationConsumer* _consumer; | CIMIndicationConsumer* _consumer; |
String _url; | String _url; |
CIMInstance _instance; | CIMInstance _instance; |
|
ContentLanguageList _contentLangs; |
}; | }; |
| |
CIMListenerIndicationDispatchEvent::CIMListenerIndicationDispatchEvent(CIMIndicationConsumer* consumer, String url, CIMInstance instance) |
CIMListenerIndicationDispatchEvent::CIMListenerIndicationDispatchEvent( |
:_consumer(consumer),_url(url),_instance(instance) |
CIMIndicationConsumer* consumer, |
|
String url, |
|
CIMInstance instance, |
|
ContentLanguageList contentLangs) |
|
:_consumer(consumer),_url(url),_instance(instance), _contentLangs(contentLangs) |
{ | { |
} | } |
CIMListenerIndicationDispatchEvent::~CIMListenerIndicationDispatchEvent() | CIMListenerIndicationDispatchEvent::~CIMListenerIndicationDispatchEvent() |
|
|
{ | { |
return _instance; | return _instance; |
} | } |
|
ContentLanguageList |
|
CIMListenerIndicationDispatchEvent::getContentLanguages() const |
|
{ |
|
return _contentLangs; |
|
} |
| |
/////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////// |
// CIMListenerIndicationDispatcherRep | // CIMListenerIndicationDispatcherRep |
|
|
Boolean addConsumer(CIMIndicationConsumer* consumer); | Boolean addConsumer(CIMIndicationConsumer* consumer); |
Boolean removeConsumer(CIMIndicationConsumer* consumer); | Boolean removeConsumer(CIMIndicationConsumer* consumer); |
| |
CIMExportIndicationResponseMessage* handleIndicationRequest(CIMExportIndicationRequestMessage* request); |
CIMExportIndicationResponseMessage* handleIndicationRequest( |
|
CIMExportIndicationRequestMessage* request); |
| |
| |
static PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL deliver_routine(void *param); |
static ThreadReturnType PEGASUS_THREAD_CDECL deliver_routine(void *param); |
| |
private: | private: |
void deliverIndication(String url, CIMInstance instance); |
void deliverIndication(String url, |
|
CIMInstance instance, |
|
ContentLanguageList contentLangs); |
| |
ThreadPool* _thread_pool; | ThreadPool* _thread_pool; |
PtrList* _consumers; | PtrList* _consumers; |
}; | }; |
| |
static struct timeval create_time = {0, 1}; |
static struct timeval deallocateWait = {15, 0}; |
static struct timeval destroy_time = {15, 0}; |
|
static struct timeval deadlock_time = {0, 0}; |
|
| |
| |
CIMListenerIndicationDispatcherRep::CIMListenerIndicationDispatcherRep() | CIMListenerIndicationDispatcherRep::CIMListenerIndicationDispatcherRep() |
:_thread_pool(new ThreadPool(0, "ListenerIndicationDispatcher", 0, 0, | :_thread_pool(new ThreadPool(0, "ListenerIndicationDispatcher", 0, 0, |
create_time, destroy_time, deadlock_time)) |
deallocateWait)), _consumers(new PtrList()) |
,_consumers(new PtrList()) |
|
{ | { |
| |
} | } |
CIMListenerIndicationDispatcherRep::~CIMListenerIndicationDispatcherRep() | CIMListenerIndicationDispatcherRep::~CIMListenerIndicationDispatcherRep() |
{ | { |
if(_thread_pool!=NULL) |
|
{ |
|
_thread_pool->kill_dead_threads(); |
|
delete _thread_pool; | delete _thread_pool; |
} |
|
if(_consumers!=NULL) |
|
delete _consumers; | delete _consumers; |
} | } |
| |
Boolean CIMListenerIndicationDispatcherRep::addConsumer(CIMIndicationConsumer* consumer) |
Boolean CIMListenerIndicationDispatcherRep::addConsumer( |
|
CIMIndicationConsumer* consumer) |
{ | { |
_consumers->add(consumer); | _consumers->add(consumer); |
return true; | return true; |
} | } |
Boolean CIMListenerIndicationDispatcherRep::removeConsumer(CIMIndicationConsumer* consumer) |
Boolean CIMListenerIndicationDispatcherRep::removeConsumer( |
|
CIMIndicationConsumer* consumer) |
{ | { |
_consumers->remove(consumer); | _consumers->remove(consumer); |
return true; | return true; |
} | } |
CIMExportIndicationResponseMessage* CIMListenerIndicationDispatcherRep::handleIndicationRequest(CIMExportIndicationRequestMessage* request) |
CIMExportIndicationResponseMessage* |
|
CIMListenerIndicationDispatcherRep::handleIndicationRequest( |
|
CIMExportIndicationRequestMessage* request) |
{ | { |
PEG_METHOD_ENTER(TRC_SERVER, | PEG_METHOD_ENTER(TRC_SERVER, |
"CIMListenerIndicationDispatcherRep::handleIndicationRequest"); | "CIMListenerIndicationDispatcherRep::handleIndicationRequest"); |
| |
CIMInstance instance = request->indicationInstance; | CIMInstance instance = request->indicationInstance; |
String url = request->destinationPath; | String url = request->destinationPath; |
|
ContentLanguageList contentLangs = |
|
((ContentLanguageListContainer)request->operationContext. |
|
get(ContentLanguageListContainer::NAME)).getLanguages(); |
| |
deliverIndication(url,instance); |
deliverIndication(url,instance,contentLangs); |
| |
// compose a response message | // compose a response message |
CIMException cimException; | CIMException cimException; |
| |
CIMExportIndicationResponseMessage* response = new CIMExportIndicationResponseMessage( |
CIMExportIndicationResponseMessage* response = |
request->messageId, |
dynamic_cast<CIMExportIndicationResponseMessage*>( |
cimException, |
request->buildResponse()); |
request->queueIds.copyAndPop()); |
response->cimException = cimException; |
|
|
response->dest = request->queueIds.top(); | response->dest = request->queueIds.top(); |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
|
|
return response; | return response; |
} | } |
| |
void CIMListenerIndicationDispatcherRep::deliverIndication(String url, CIMInstance instance) |
void CIMListenerIndicationDispatcherRep::deliverIndication(String url, |
{ |
CIMInstance instance, |
// go thru all consumers and broadcast the result; should be run in seperate thread |
ContentLanguageList contentLangs) |
Iterator* it = _consumers->iterator(); |
{ |
|
// go thru all consumers and broadcast the result; |
|
// should be run in seperate thread |
|
AutoPtr<Iterator> it( _consumers->iterator() ); |
|
|
while(it->hasNext()==true) | while(it->hasNext()==true) |
{ | { |
CIMIndicationConsumer* consumer = static_cast<CIMIndicationConsumer*>(it->next()); |
CIMIndicationConsumer* consumer = |
CIMListenerIndicationDispatchEvent* event = new CIMListenerIndicationDispatchEvent(consumer,url,instance); |
static_cast<CIMIndicationConsumer*>(it->next()); |
_thread_pool->allocate_and_awaken(event,deliver_routine); |
CIMListenerIndicationDispatchEvent* event = |
|
new CIMListenerIndicationDispatchEvent(consumer, |
|
url, |
|
instance, |
|
contentLangs); |
|
ThreadStatus rtn = _thread_pool->allocate_and_awaken( |
|
event,deliver_routine); |
|
|
|
if (rtn != PEGASUS_THREAD_OK) |
|
{ |
|
PEG_TRACE_CSTRING( |
|
TRC_SERVER, |
|
Tracer::LEVEL1, |
|
"Could not allocate thread to deliver event." |
|
" Instead using current thread."); |
|
delete event; |
|
throw Exception(MessageLoaderParms( |
|
"Listener.CIMListenerIndicationDispatcher." |
|
"CANNOT_ALLOCATE_THREAD", |
|
"Not enough threads to allocate a worker to deliver the" |
|
" event.")); |
} | } |
} | } |
PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL CIMListenerIndicationDispatcherRep::deliver_routine(void *param) |
} |
|
ThreadReturnType PEGASUS_THREAD_CDECL |
|
CIMListenerIndicationDispatcherRep::deliver_routine(void *param) |
{ | { |
CIMListenerIndicationDispatchEvent* event = static_cast<CIMListenerIndicationDispatchEvent*>(param); |
CIMListenerIndicationDispatchEvent* event = |
|
static_cast<CIMListenerIndicationDispatchEvent*>(param); |
| |
if(event!=NULL) | if(event!=NULL) |
{ | { |
CIMIndicationConsumer* consumer = event->getConsumer(); | CIMIndicationConsumer* consumer = event->getConsumer(); |
OperationContext context; | OperationContext context; |
|
context.insert(ContentLanguageListContainer( |
|
event->getContentLanguages())); |
if(consumer) | if(consumer) |
{ | { |
consumer->consumeIndication(context,event->getURL(),event->getIndicationInstance()); |
consumer->consumeIndication(context, |
|
event->getURL(),event->getIndicationInstance()); |
} | } |
| |
delete event; | delete event; |
|
|
CIMListenerIndicationDispatcher::~CIMListenerIndicationDispatcher() | CIMListenerIndicationDispatcher::~CIMListenerIndicationDispatcher() |
{ | { |
if(_rep!=NULL) | if(_rep!=NULL) |
delete _rep; |
delete static_cast<CIMListenerIndicationDispatcherRep*>(_rep); |
| |
_rep=NULL; | _rep=NULL; |
} | } |
| |
void CIMListenerIndicationDispatcher::handleEnqueue() | void CIMListenerIndicationDispatcher::handleEnqueue() |
{ | { |
PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue"); |
PEG_METHOD_ENTER(TRC_SERVER, |
|
"CIMListenerIndicationDispatcher::handleEnqueue"); |
| |
Message *message = dequeue(); | Message *message = dequeue(); |
if(message) | if(message) |
|
|
| |
void CIMListenerIndicationDispatcher::handleEnqueue(Message* message) | void CIMListenerIndicationDispatcher::handleEnqueue(Message* message) |
{ | { |
PEG_METHOD_ENTER(TRC_SERVER, "CIMListenerIndicationDispatcher::handleEnqueue"); |
PEG_METHOD_ENTER(TRC_SERVER, |
|
"CIMListenerIndicationDispatcher::handleEnqueue"); |
| |
if(message!=NULL) | if(message!=NULL) |
{ | { |
|
|
{ | { |
case CIM_EXPORT_INDICATION_REQUEST_MESSAGE: | case CIM_EXPORT_INDICATION_REQUEST_MESSAGE: |
{ | { |
CIMExportIndicationRequestMessage* request = (CIMExportIndicationRequestMessage*)message; |
CIMExportIndicationRequestMessage* request = |
|
(CIMExportIndicationRequestMessage*)message; |
| |
CIMExportIndicationResponseMessage* response = | CIMExportIndicationResponseMessage* response = |
static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->handleIndicationRequest(request); |
static_cast<CIMListenerIndicationDispatcherRep*>(_rep)-> |
|
handleIndicationRequest(request); |
| |
_enqueueResponse(request, response); | _enqueueResponse(request, response); |
} | } |
|
|
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
Boolean CIMListenerIndicationDispatcher::addConsumer(CIMIndicationConsumer* consumer) |
Boolean CIMListenerIndicationDispatcher::addConsumer( |
|
CIMIndicationConsumer* consumer) |
{ | { |
return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->addConsumer(consumer); |
return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->addConsumer( |
|
consumer); |
} | } |
Boolean CIMListenerIndicationDispatcher::removeConsumer(CIMIndicationConsumer* consumer) |
Boolean CIMListenerIndicationDispatcher::removeConsumer( |
|
CIMIndicationConsumer* consumer) |
{ | { |
return static_cast<CIMListenerIndicationDispatcherRep*>(_rep)->removeConsumer(consumer); |
return static_cast<CIMListenerIndicationDispatcherRep*> |
|
(_rep)->removeConsumer(consumer); |
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |