version 1.9, 2002/02/04 17:37:56
|
version 1.159, 2008/12/16 18:56:00
|
|
|
//%////-*-c++-*-//////////////////////////////////////////////////////////////// |
//%LICENSE//////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// Licensed to The Open Group (TOG) under one or more contributor license |
|
// agreements. Refer to the OpenPegasusNOTICE.txt file distributed with |
|
// this work for additional information regarding copyright ownership. |
|
// Each contributor licenses this file to you under the OpenPegasus Open |
|
// Source License; you may not use this file except in compliance with the |
|
// License. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// Permission is hereby granted, free of charge, to any person obtaining a |
// of this software and associated documentation files (the "Software"), to |
// copy of this software and associated documentation files (the "Software"), |
// deal in the Software without restriction, including without limitation the |
// to deal in the Software without restriction, including without limitation |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// sell copies of the Software, and to permit persons to whom the Software is |
// and/or sell copies of the Software, and to permit persons to whom the |
// furnished to do so, subject to the following conditions: |
// Software is furnished to do so, subject to the following conditions: |
// | // |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// The above copyright notice and this permission notice shall be included |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// in all copies or substantial portions of the Software. |
// "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. |
|
// | // |
//============================================================================== |
// 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: Mike Day (mdday@us.ibm.com) |
////////////////////////////////////////////////////////////////////////// |
// |
|
// Modified By: |
|
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include "MessageQueueService.h" | #include "MessageQueueService.h" |
|
#include <Pegasus/Common/Tracer.h> |
|
#include <Pegasus/Common/MessageLoader.h> |
|
|
|
PEGASUS_USING_STD; |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
MessageQueueService::MessageQueueService(const char *name, |
cimom *MessageQueueService::_meta_dispatcher = 0; |
Uint32 queueID, |
AtomicInt MessageQueueService::_service_count(0); |
Uint32 capabilities, |
Mutex MessageQueueService::_meta_dispatcher_mutex; |
Uint32 mask) |
|
: Base(name, false, queueID), |
static struct timeval deallocateWait = {300, 0}; |
_capabilities(capabilities), |
|
_mask(mask), |
|
_die(0), |
|
_pending(true), |
|
_incoming(true, 1000), |
|
_incoming_queue_shutdown(0), |
|
_req_thread(_req_proc, this, false) |
|
{ |
|
_default_op_timeout.tv_sec = 30; |
|
_default_op_timeout.tv_usec = 100; |
|
_meta_dispatcher = static_cast<cimom *>(Base::lookup(CIMOM_Q_ID)); |
|
if(_meta_dispatcher == 0 ) |
|
throw NullPointer(); |
|
_req_thread.run(); |
|
| |
|
ThreadPool *MessageQueueService::_thread_pool = 0; |
|
|
|
MessageQueueService::PollingList* MessageQueueService::_polling_list; |
|
Mutex MessageQueueService::_polling_list_mutex; |
|
|
|
Thread* MessageQueueService::_polling_thread = 0; |
|
|
|
ThreadPool *MessageQueueService::get_thread_pool() |
|
{ |
|
return _thread_pool; |
} | } |
| |
|
// |
|
// MAX_THREADS_PER_SVC_QUEUE |
|
// |
|
// JR Wunderlich Jun 6, 2005 |
|
// |
|
|
|
#define MAX_THREADS_PER_SVC_QUEUE_LIMIT 5000 |
|
#define MAX_THREADS_PER_SVC_QUEUE_DEFAULT 5 |
|
|
|
#ifndef MAX_THREADS_PER_SVC_QUEUE |
|
# define MAX_THREADS_PER_SVC_QUEUE MAX_THREADS_PER_SVC_QUEUE_DEFAULT |
|
#endif |
| |
MessageQueueService::~MessageQueueService(void) |
Uint32 max_threads_per_svc_queue; |
|
|
|
ThreadReturnType PEGASUS_THREAD_CDECL MessageQueueService::polling_routine( |
|
void* parm) |
{ | { |
_die = 1; |
Thread *myself = reinterpret_cast<Thread *>(parm); |
if (_incoming_queue_shutdown.value() == 0 ) |
MessageQueueService::PollingList *list = |
_incoming.shutdown_queue(); |
reinterpret_cast<MessageQueueService::PollingList*>(myself->get_parm()); |
| |
_req_thread.join(); |
try |
|
{ |
|
while (_stop_polling.get() == 0) |
|
{ |
|
_polling_sem.wait(); |
| |
|
if (_stop_polling.get() != 0) |
|
{ |
|
break; |
} | } |
| |
AtomicInt MessageQueueService::_xid(1); |
// The polling_routine thread must hold the lock on the |
|
// _polling_list while processing incoming messages. |
|
// This lock is used to give this thread ownership of |
|
// services on the _polling_routine list. |
|
|
|
// This is necessary to avoid confict with other threads |
|
// processing the _polling_list |
|
// (e.g., MessageQueueServer::~MessageQueueService). |
|
|
|
_polling_list_mutex.lock(); |
|
MessageQueueService *service = list->front(); |
|
ThreadStatus rtn = PEGASUS_THREAD_OK; |
|
while (service != NULL) |
|
{ |
|
if ((service->_incoming.count() > 0) && |
|
(service->_die.get() == 0) && |
|
(service->_threads.get() < max_threads_per_svc_queue)) |
|
{ |
|
// The _threads count is used to track the |
|
// number of active threads that have been allocated |
|
// to process messages for this service. |
|
|
|
// The _threads count MUST be incremented while |
|
// the polling_routine owns the _polling_thread |
|
// lock and has ownership of the service object. |
|
|
|
service->_threads++; |
|
rtn = _thread_pool->allocate_and_awaken( |
|
service, _req_proc, &_polling_sem); |
|
// if no more threads available, break from processing loop |
|
if (rtn != PEGASUS_THREAD_OK ) |
|
{ |
|
service->_threads--; |
|
PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL1, |
|
"Could not allocate thread for %s. Queue has %d " |
|
"messages waiting and %d threads servicing." |
|
"Skipping the service for right now. ", |
|
service->getQueueName(), |
|
service->_incoming.count(), |
|
service->_threads.get())); |
| |
void MessageQueueService::_shutdown_incoming_queue(void) |
Threads::yield(); |
|
break; |
|
} |
|
} |
|
service = list->next_of(service); |
|
} |
|
_polling_list_mutex.unlock(); |
|
} |
|
} |
|
catch(const Exception &e) |
|
{ |
|
PEG_TRACE((TRC_MESSAGEQUEUESERVICE,Tracer::LEVEL1, |
|
"Exception caught in MessageQueueService::polling_routine : %s", |
|
(const char*)e.getMessage().getCString())); |
|
} |
|
catch(const exception &e) |
|
{ |
|
PEG_TRACE((TRC_MESSAGEQUEUESERVICE,Tracer::LEVEL1, |
|
"Exception caught in MessageQueueService::polling_routine : %s", |
|
e.what())); |
|
} |
|
catch(...) |
{ | { |
|
PEG_TRACE_CSTRING(TRC_MESSAGEQUEUESERVICE,Tracer::LEVEL1, |
|
"Unknown Exception caught in MessageQueueService::polling_routine"); |
|
} |
| |
if (_incoming_queue_shutdown.value() > 0 ) |
PEGASUS_ASSERT(_stop_polling.get()); |
return ; |
|
| |
AsyncIoctl *msg = new AsyncIoctl(get_next_xid(), |
return ThreadReturnType(0); |
0, |
} |
_queueId, |
|
_queueId, |
|
true, |
|
AsyncIoctl::IO_CLOSE, |
|
0, |
|
0); |
|
| |
msg->op = get_op(); |
|
msg->op->_request.insert_first(msg); |
|
| |
|
Semaphore MessageQueueService::_polling_sem(0); |
|
AtomicInt MessageQueueService::_stop_polling(0); |
| |
| |
_incoming.insert_last_wait(msg->op); |
MessageQueueService::MessageQueueService( |
msg->op->_client_sem.wait(); |
const char* name, |
|
Uint32 queueID) |
|
: Base(name, true, queueID), |
|
_die(0), |
|
_threads(0), |
|
_incoming(), |
|
_incoming_queue_shutdown(0) |
|
{ |
|
_isRunning = true; |
| |
msg->op->lock(); |
max_threads_per_svc_queue = MAX_THREADS_PER_SVC_QUEUE; |
AsyncReply * reply = static_cast<AsyncReply *>(msg->op->_response.remove_first()); |
|
reply->op = 0; |
|
msg->op->unlock(); |
|
delete reply; |
|
| |
msg->op->_request.remove(msg); |
// if requested thread max is out of range, then set to |
msg->op->_state |= ASYNC_OPSTATE_RELEASED; |
// MAX_THREADS_PER_SVC_QUEUE_LIMIT |
return_op(msg->op); |
|
| |
msg->op = 0; |
if ((max_threads_per_svc_queue < 1) || |
delete msg; |
(max_threads_per_svc_queue > MAX_THREADS_PER_SVC_QUEUE_LIMIT)) |
|
{ |
|
max_threads_per_svc_queue = MAX_THREADS_PER_SVC_QUEUE_LIMIT; |
} | } |
| |
|
PEG_TRACE((TRC_MESSAGEQUEUESERVICE, Tracer::LEVEL3, |
|
"max_threads_per_svc_queue set to %u.", max_threads_per_svc_queue)); |
|
|
|
AutoMutex autoMut(_meta_dispatcher_mutex); |
| |
PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL MessageQueueService::_req_proc(void * parm) |
if (_meta_dispatcher == 0) |
{ | { |
Thread *myself = reinterpret_cast<Thread *>(parm); |
_stop_polling = 0; |
MessageQueueService *service = reinterpret_cast<MessageQueueService *>(myself->get_parm()); |
PEGASUS_ASSERT(_service_count.get() == 0); |
|
_meta_dispatcher = new cimom(); |
| |
// pull messages off the incoming queue and dispatch them. then |
// _thread_pool = new ThreadPool(initial_cnt, "MessageQueueService", |
// check pending messages that are non-blocking |
// minimum_cnt, maximum_cnt, deallocateWait); |
AsyncOpNode *operation = 0; |
// |
|
_thread_pool = |
|
new ThreadPool(0, "MessageQueueService", 0, 0, deallocateWait); |
|
} |
|
_service_count++; |
| |
while ( service->_die.value() == 0 ) |
// Add to the polling list |
|
if (!_polling_list) |
{ | { |
try |
_polling_list = new PollingList; |
{ |
|
operation = service->_incoming.remove_first_wait(); |
|
} | } |
catch(ListClosed & ) |
_polling_list->insert_back(this); |
{ |
_meta_dispatcher->registerCIMService(this); |
break; |
|
} | } |
if( operation ) |
|
|
|
|
MessageQueueService::~MessageQueueService() |
{ | { |
| |
service->_handle_incoming_operation(operation, myself, service); |
// Close incoming queue. |
|
if (_incoming_queue_shutdown.get() == 0) |
|
{ |
|
AsyncIoClose *msg = new AsyncIoClose( |
|
0, |
|
_queueId, |
|
_queueId, |
|
true); |
|
SendForget(msg); |
|
// Wait until our queue has been shutdown. |
|
while (_incoming_queue_shutdown.get() == 0) |
|
{ |
|
Threads::yield(); |
} | } |
|
|
} | } |
| |
myself->exit_self( (PEGASUS_THREAD_RETURN) 1 ); |
// die now. |
return(0); |
_die = 1; |
} |
|
| |
|
_meta_dispatcher->deregisterCIMService(this); |
| |
void MessageQueueService::_handle_incoming_operation(AsyncOpNode *operation, |
// Wait until all threads processing the messages |
Thread *thread, |
// for this service have completed. |
MessageQueue *queue) |
while (_threads.get() > 0) |
{ | { |
if ( operation != 0 ) |
Threads::yield(); |
{ |
|
operation->lock(); |
|
Message *rq = operation->_request.next(0); |
|
operation->unlock(); |
|
|
|
PEGASUS_ASSERT(rq != 0 ); |
|
PEGASUS_ASSERT(rq->getMask() & message_mask::ha_async ); |
|
PEGASUS_ASSERT(rq->getMask() & message_mask::ha_request); |
|
static_cast<AsyncMessage *>(rq)->_myself = thread; |
|
static_cast<AsyncMessage *>(rq)->_service = queue; |
|
_handle_async_request(static_cast<AsyncRequest *>(rq)); |
|
} | } |
| |
return; |
|
| |
} |
// The polling_routine locks the _polling_list while |
|
// processing the incoming messages for services on the |
|
// list. Deleting the service from the _polling_list |
|
// prior to processing, avoids synchronization issues |
|
// with the _polling_routine. |
|
_removeFromPollingList(this); |
| |
void MessageQueueService::_handle_async_request(AsyncRequest *req) |
|
{ |
|
if ( req != 0 ) |
|
{ | { |
req->op->processing(); |
AutoMutex autoMut(_meta_dispatcher_mutex); |
| |
Uint32 type = req->getType(); |
_service_count--; |
if( type == async_messages::HEARTBEAT ) |
// If we are last service to die, delete metadispatcher. |
handle_heartbeat_request(req); |
if (_service_count.get() == 0) |
else if (type == async_messages::IOCTL) |
|
handle_AsyncIoctl(static_cast<AsyncIoctl *>(req)); |
|
else if (type == async_messages::CIMSERVICE_START) |
|
handle_CimServiceStart(static_cast<CimServiceStart *>(req)); |
|
else if (type == async_messages::CIMSERVICE_STOP) |
|
handle_CimServiceStop(static_cast<CimServiceStop *>(req)); |
|
else if (type == async_messages::CIMSERVICE_PAUSE) |
|
handle_CimServicePause(static_cast<CimServicePause *>(req)); |
|
else if (type == async_messages::CIMSERVICE_RESUME) |
|
handle_CimServiceResume(static_cast<CimServiceResume *>(req)); |
|
else if ( type == async_messages::ASYNC_OP_START) |
|
handle_AsyncOperationStart(static_cast<AsyncOperationStart *>(req)); |
|
else |
|
{ | { |
// we don't handle this request message |
_stop_polling++; |
_make_response(req, async_results::CIM_NAK ); |
_polling_sem.signal(); |
|
if (_polling_thread) |
|
{ |
|
_polling_thread->join(); |
|
delete _polling_thread; |
|
_polling_thread = 0; |
} | } |
|
delete _meta_dispatcher; |
|
_meta_dispatcher = 0; |
|
|
|
delete _thread_pool; |
|
_thread_pool = 0; |
} | } |
} | } |
| |
void MessageQueueService::_make_response(AsyncRequest *req, Uint32 code) |
// Clean up any extra stuff on the queue. |
|
AsyncOpNode* op = 0; |
|
while ((op = _incoming.dequeue())) |
{ | { |
AsyncReply *reply = |
delete op; |
new AsyncReply(async_messages::REPLY, |
} |
req->getKey(), |
|
req->getRouting(), |
|
0, |
|
req->op, |
|
code, |
|
req->resp, |
|
false); |
|
_completeAsyncResponse(req, reply, ASYNC_OPSTATE_COMPLETE, 0 ); |
|
} | } |
| |
|
void MessageQueueService::enqueue(Message* msg) |
void MessageQueueService::_completeAsyncResponse(AsyncRequest *request, |
|
AsyncReply *reply, |
|
Uint32 state, |
|
Uint32 flag) |
|
{ | { |
PEGASUS_ASSERT(request != 0 && reply != 0 ); |
PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE, "MessageQueueService::enqueue()"); |
|
|
AsyncOpNode *op = request->op; |
|
op->lock(); |
|
op->_state |= state ; |
|
op->_flags |= flag; |
|
gettimeofday(&(op->_updated), NULL); |
|
if ( false == op->_response.exists(reinterpret_cast<void *>(reply)) ) |
|
op->_response.insert_last(reply); |
|
op->unlock(); |
|
|
|
op->_client_sem.signal(); |
|
| |
|
Base::enqueue(msg); |
| |
|
PEG_METHOD_EXIT(); |
} | } |
| |
| |
|
ThreadReturnType PEGASUS_THREAD_CDECL MessageQueueService::_req_proc( |
Boolean MessageQueueService::accept_async(AsyncOpNode *op) |
void* parm) |
{ | { |
if (_incoming_queue_shutdown.value() > 0 ) |
MessageQueueService* service = |
return false; |
reinterpret_cast<MessageQueueService*>(parm); |
|
PEGASUS_ASSERT(service != 0); |
op->lock(); |
try |
Message *rq = op->_request.next(0); |
|
op->unlock(); |
|
|
|
if( true == messageOK(rq) && _die.value() == 0 ) |
|
{ | { |
_incoming.insert_last_wait(op); |
if (service->_die.get() != 0) |
return true; |
{ |
} |
service->_threads--; |
return false; |
return 0; |
} | } |
|
// pull messages off the incoming queue and dispatch them. then |
|
// check pending messages that are non-blocking |
|
AsyncOpNode *operation = 0; |
| |
Boolean MessageQueueService::messageOK(const Message *msg) |
// many operations may have been queued. |
|
do |
{ | { |
if (_incoming_queue_shutdown.value() > 0 ) |
operation = service->_incoming.dequeue(); |
return false; |
|
| |
if ( msg != 0 ) |
if (operation) |
{ | { |
Uint32 mask = msg->getMask(); |
operation->_service_ptr = service; |
if ( mask & message_mask::ha_async) |
service->_handle_incoming_operation(operation); |
if ( mask & message_mask::ha_request) |
|
return true; |
|
} | } |
return false; |
} while (operation); |
} | } |
|
catch (const Exception& e) |
|
|
void MessageQueueService::handleEnqueue(void) |
|
{ | { |
Message *msg = dequeue(); |
PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1, |
if( msg ) |
"Caught exception: \"%s\". Exiting _req_proc.", |
|
(const char*)e.getMessage().getCString())); |
|
} |
|
catch (...) |
{ | { |
delete msg; |
PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL1, |
|
"Caught unrecognized exception. Exiting _req_proc."); |
} | } |
|
service->_threads--; |
|
return 0; |
} | } |
| |
void MessageQueueService::handle_heartbeat_request(AsyncRequest *req) |
|
{ |
|
// default action is to echo a heartbeat response |
|
| |
AsyncReply *reply = |
void MessageQueueService::_sendwait_callback( |
new AsyncReply(async_messages::HEARTBEAT, |
AsyncOpNode* op, |
req->getKey(), |
MessageQueue* q, |
req->getRouting(), |
void *parm) |
0, |
{ |
req->op, |
op->_client_sem.signal(); |
async_results::OK, |
|
req->resp, |
|
false); |
|
_completeAsyncResponse(req, reply, ASYNC_OPSTATE_COMPLETE, 0 ); |
|
} | } |
| |
| |
void MessageQueueService::handle_heartbeat_reply(AsyncReply *rep) |
// callback function is responsible for cleaning up all resources |
|
// including op, op->_callback_node, and op->_callback_ptr |
|
void MessageQueueService::_handle_async_callback(AsyncOpNode* op) |
{ | { |
; |
PEGASUS_ASSERT(op->_flags == ASYNC_OPFLAGS_CALLBACK); |
|
// note that _callback_node may be different from op |
|
// op->_callback_response_q is a "this" pointer we can use for |
|
// static callback methods |
|
op->_async_callback( |
|
op->_callback_node, op->_callback_response_q, op->_callback_ptr); |
} | } |
| |
void MessageQueueService::handle_AsyncIoctl(AsyncIoctl *req) |
|
{ |
|
| |
switch( req->ctl ) |
void MessageQueueService::_handle_incoming_operation(AsyncOpNode* operation) |
{ | { |
case AsyncIoctl::IO_CLOSE: |
if (operation != 0) |
{ | { |
// save my bearings |
Message *rq = operation->_request.get(); |
Thread *myself = req->_myself; |
|
MessageQueueService *service = static_cast<MessageQueueService *>(req->_service); |
|
| |
// respond to this message. |
// optimization <<< Thu Mar 7 21:04:05 2002 mdd >>> |
_make_response(req, async_results::OK); |
// move this to the bottom of the loop when the majority of |
// ensure we do not accept any further messages |
// messages become async messages. |
|
|
// ensure we don't recurse on IO_CLOSE |
// divert legacy messages to handleEnqueue |
if( _incoming_queue_shutdown.value() > 0 ) |
if ((rq != 0) && (!(rq->getMask() & MessageMask::ha_async))) |
break; |
{ |
|
operation->_request.release(); |
|
// delete the op node |
|
return_op(operation); |
|
handleEnqueue(rq); |
|
return; |
|
} |
| |
// set the closing flag |
if ((operation->_flags & ASYNC_OPFLAGS_CALLBACK) && |
service->_incoming_queue_shutdown = 1; |
(operation->_state & ASYNC_OPSTATE_COMPLETE)) |
// empty out the queue |
|
while( 1 ) |
|
{ | { |
AsyncOpNode *operation; |
_handle_async_callback(operation); |
try |
|
{ |
|
operation = service->_incoming.remove_first(); |
|
} | } |
catch(IPCException & ) |
else |
{ | { |
break; |
PEGASUS_ASSERT(rq != 0); |
|
_handle_async_request(static_cast<AsyncRequest *>(rq)); |
} | } |
if( operation ) |
|
{ |
|
service->_handle_incoming_operation(operation, myself, service); |
|
} | } |
else |
|
break; |
|
} // message processing loop |
|
|
|
// shutdown the AsyncDQueue |
|
service->_incoming.shutdown_queue(); |
|
// exit the thread ! |
|
myself->exit_self( (PEGASUS_THREAD_RETURN) 1 ); |
|
return; | return; |
} | } |
| |
default: |
void MessageQueueService::_handle_async_request(AsyncRequest *req) |
_make_response(req, async_results::CIM_NAK); |
|
} |
|
} |
|
|
|
void MessageQueueService::handle_CimServiceStart(CimServiceStart *req) |
|
{ | { |
_make_response(req, async_results::CIM_NAK); |
MessageType type = req->getType(); |
} |
if (type == ASYNC_IOCLOSE) |
void MessageQueueService::handle_CimServiceStop(CimServiceStop *req) |
|
{ | { |
_make_response(req, async_results::CIM_NAK); |
handle_AsyncIoClose(static_cast<AsyncIoClose*>(req)); |
} | } |
void MessageQueueService::handle_CimServicePause(CimServicePause *req) |
else if (type == ASYNC_CIMSERVICE_START) |
{ | { |
_make_response(req, async_results::CIM_NAK); |
handle_CimServiceStart(static_cast<CimServiceStart *>(req)); |
} | } |
void MessageQueueService::handle_CimServiceResume(CimServiceResume *req) |
else if (type == ASYNC_CIMSERVICE_STOP) |
{ | { |
_make_response(req, async_results::CIM_NAK); |
handle_CimServiceStop(static_cast<CimServiceStop *>(req)); |
} | } |
|
else |
void MessageQueueService::handle_AsyncOperationStart(AsyncOperationStart *req) |
|
{ | { |
|
// we don't handle this request message |
_make_response(req, async_results::CIM_NAK); | _make_response(req, async_results::CIM_NAK); |
|
|
} | } |
|
|
void MessageQueueService::handle_AsyncOperationResult(AsyncOperationResult *req) |
|
{ |
|
; |
|
} | } |
| |
AsyncOpNode *MessageQueueService::get_op(void) |
Boolean MessageQueueService::_enqueueResponse( |
|
Message* request, |
|
Message* response) |
{ | { |
AsyncOpNode *op = new AsyncOpNode(); |
PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE, |
|
"MessageQueueService::_enqueueResponse"); |
| |
op->_state = ASYNC_OPSTATE_UNKNOWN; |
if (request->getMask() & MessageMask::ha_async) |
op->_flags = ASYNC_OPFLAGS_SINGLE | ASYNC_OPFLAGS_NORMAL; |
{ |
|
if (response->getMask() & MessageMask::ha_async) |
|
{ |
|
_completeAsyncResponse( |
|
static_cast<AsyncRequest *>(request), |
|
static_cast<AsyncReply *>(response)); |
| |
return op; |
PEG_METHOD_EXIT(); |
|
return true; |
} | } |
|
|
void MessageQueueService::return_op(AsyncOpNode *op) |
|
{ |
|
PEGASUS_ASSERT(op->read_state() & ASYNC_OPSTATE_RELEASED ); |
|
delete op; |
|
} | } |
| |
|
AsyncRequest* asyncRequest = |
|
static_cast<AsyncRequest*>(request->get_async()); |
| |
|
if (asyncRequest != 0) |
AsyncReply *MessageQueueService::SendWait(AsyncRequest *request) |
|
{ | { |
if ( request == 0 ) |
PEGASUS_ASSERT(asyncRequest->getMask() & |
return 0 ; |
(MessageMask::ha_async | MessageMask::ha_request)); |
| |
Boolean destroy_op = false; |
AsyncOpNode* op = asyncRequest->op; |
| |
if (request->op == false) |
// the legacy request is going to be deleted by its handler |
{ |
// remove it from the op node |
request->op = get_op(); |
|
request->op->_request.insert_first(request); |
|
destroy_op = true; |
|
} |
|
| |
request->block = true; |
static_cast<AsyncLegacyOperationStart *>(asyncRequest)->get_action(); |
request->op->_state &= ~ASYNC_OPSTATE_COMPLETE; |
|
request->op->put_response(0); |
|
| |
// first link it on our pending list |
AsyncLegacyOperationResult *async_result = |
// _pending.insert_last_wait(request->op); |
new AsyncLegacyOperationResult( |
|
op, |
|
response); |
|
_completeAsyncResponse( |
|
asyncRequest, |
|
async_result); |
| |
// now see if the meta dispatcher will take it |
PEG_METHOD_EXIT(); |
|
return true; |
if (true == _meta_dispatcher->route_async(request->op)) |
} |
{ |
|
request->op->_client_sem.wait(); |
|
PEGASUS_ASSERT(request->op->_state & ASYNC_OPSTATE_COMPLETE); |
|
| |
|
// ensure that the destination queue is in response->dest |
|
PEG_METHOD_EXIT(); |
|
return SendForget(response); |
} | } |
| |
request->op->lock(); |
void MessageQueueService::_make_response(Message* req, Uint32 code) |
AsyncReply * rpl = static_cast<AsyncReply *>(request->op->_response.remove_first()); |
{ |
rpl->op = 0; |
cimom::_make_response(req, code); |
request->op->unlock(); |
} |
| |
if( destroy_op == true) |
void MessageQueueService::_completeAsyncResponse( |
|
AsyncRequest* request, |
|
AsyncReply* reply) |
{ | { |
request->op->lock(); |
PEG_METHOD_ENTER(TRC_MESSAGEQUEUESERVICE, |
request->op->_request.remove(request); |
"MessageQueueService::_completeAsyncResponse"); |
request->op->_state |= ASYNC_OPSTATE_RELEASED; |
|
request->op->unlock(); |
|
| |
return_op(request->op); |
cimom::_completeAsyncResponse(request, reply); |
request->op = 0; |
|
} |
|
| |
return rpl; |
PEG_METHOD_EXIT(); |
} | } |
| |
| |
Boolean MessageQueueService::register_service(String name, |
void MessageQueueService::_complete_op_node( |
Uint32 capabilities, |
AsyncOpNode* op) |
Uint32 mask) |
|
|
|
{ | { |
RegisterCimService *msg = new RegisterCimService(get_next_xid(), |
cimom::_complete_op_node(op); |
0, |
} |
true, |
|
name, |
|
capabilities, |
|
mask, |
|
_queueId); |
|
Boolean registered = false; |
|
AsyncReply *reply = static_cast<AsyncReply *>(SendWait( msg )); |
|
| |
if ( reply != 0 ) |
Boolean MessageQueueService::accept_async(AsyncOpNode* op) |
{ | { |
if(reply->getMask() & message_mask:: ha_async) |
if (!_isRunning) |
{ | { |
if(reply->getMask() & message_mask::ha_reply) |
// Don't accept any messages other than start. |
|
if (op->_request.get()->getType() != ASYNC_CIMSERVICE_START) |
{ | { |
if(reply->result == async_results::OK) |
return false; |
registered = true; |
|
} | } |
} | } |
| |
delete reply; |
if (_incoming_queue_shutdown.get() > 0) |
} |
return false; |
delete msg; |
|
return registered; |
|
} |
|
| |
Boolean MessageQueueService::update_service(Uint32 capabilities, Uint32 mask) |
if (_polling_thread == NULL) |
{ | { |
|
PEGASUS_ASSERT(_polling_list); |
|
_polling_thread = new Thread( |
UpdateCimService *msg = new UpdateCimService(get_next_xid(), |
polling_routine, |
0, |
reinterpret_cast<void *>(_polling_list), |
true, |
false); |
_queueId, |
ThreadStatus tr = PEGASUS_THREAD_OK; |
_capabilities, |
while ( (tr =_polling_thread->run()) != PEGASUS_THREAD_OK) |
_mask); |
|
Boolean registered = false; |
|
|
|
AsyncMessage *reply = SendWait(msg); |
|
if (reply) |
|
{ | { |
if(reply->getMask() & message_mask:: ha_async) |
if (tr == PEGASUS_THREAD_INSUFFICIENT_RESOURCES) |
|
Threads::yield(); |
|
else |
|
throw Exception(MessageLoaderParms( |
|
"Common.MessageQueueService.NOT_ENOUGH_THREAD", |
|
"Could not allocate thread for the polling thread.")); |
|
} |
|
} |
|
if (_die.get() == 0) |
{ | { |
if(reply->getMask() & message_mask::ha_reply) |
if (_incoming.enqueue(op)) |
{ | { |
if(static_cast<AsyncReply *>(reply)->result == async_results::OK) |
_polling_sem.signal(); |
registered = true; |
return true; |
} |
|
} | } |
delete reply; |
|
} | } |
delete msg; |
return false; |
return registered; |
|
} | } |
| |
|
void MessageQueueService::handle_AsyncIoClose(AsyncIoClose *req) |
Boolean MessageQueueService::deregister_service(void) |
|
{ | { |
|
MessageQueueService *service = |
|
static_cast<MessageQueueService*>(req->op->_op_dest); |
| |
_meta_dispatcher->deregister_module(_queueId); |
#ifdef MESSAGEQUEUESERVICE_DEBUG |
return true; |
PEGASUS_STD(cout) << service->getQueueName() << |
|
" Received AsyncIoClose " << PEGASUS_STD(endl); |
|
#endif |
|
// set the closing flag, don't accept any more messages |
|
service->_incoming_queue_shutdown = 1; |
|
|
|
// respond to this message. this is fire and forget, so we |
|
// don't need to delete anything. |
|
// this takes care of two problems that were being found |
|
// << Thu Oct 9 10:52:48 2003 mdd >> |
|
_make_response(req, async_results::OK); |
} | } |
| |
|
void MessageQueueService::handle_CimServiceStart(CimServiceStart* req) |
|
{ |
|
#ifdef MESSAGEQUEUESERVICE_DEBUG |
|
PEGASUS_STD(cout) << getQueueName() << "received START" << |
|
PEGASUS_STD(endl); |
|
#endif |
|
PEGASUS_ASSERT(!_isRunning); |
|
_isRunning = true; |
|
_make_response(req, async_results::OK); |
|
} |
| |
void MessageQueueService::find_services(String name, |
void MessageQueueService::handle_CimServiceStop(CimServiceStop* req) |
Uint32 capabilities, |
|
Uint32 mask, |
|
Array<Uint32> *results) |
|
{ | { |
|
#ifdef MESSAGEQUEUESERVICE_DEBUG |
|
PEGASUS_STD(cout) << getQueueName() << "received STOP" << PEGASUS_STD(endl); |
|
#endif |
|
PEGASUS_ASSERT(_isRunning); |
|
_isRunning = false; |
|
_make_response(req, async_results::CIM_SERVICE_STOPPED); |
|
} |
| |
if( results == 0 ) |
AsyncOpNode* MessageQueueService::get_op() |
throw NullPointer(); |
{ |
|
AsyncOpNode* op = new AsyncOpNode(); |
| |
results->clear(); |
op->_state = ASYNC_OPSTATE_UNKNOWN; |
|
op->_flags = ASYNC_OPFLAGS_UNKNOWN; |
| |
FindServiceQueue *req = |
return op; |
new FindServiceQueue(get_next_xid(), |
} |
0, |
|
_queueId, |
|
true, |
|
name, |
|
capabilities, |
|
mask); |
|
| |
AsyncMessage *reply = SendWait(req); |
void MessageQueueService::return_op(AsyncOpNode* op) |
if(reply) |
|
{ |
|
if( reply->getMask() & message_mask::ha_async) |
|
{ |
|
if(reply->getMask() & message_mask::ha_reply) |
|
{ |
|
if(reply->getType() == async_messages::FIND_SERVICE_Q_RESULT) |
|
{ | { |
if( (static_cast<FindServiceQueueResult *>(reply))->result == async_results::OK ) |
delete op; |
*results = (static_cast<FindServiceQueueResult *>(reply))->qids; |
|
} |
|
} |
|
} |
|
delete reply; |
|
} |
|
delete req; |
|
return ; |
|
} | } |
| |
void MessageQueueService::enumerate_service(Uint32 queue, message_module *result) |
|
{ |
|
if(result == 0) |
|
throw NullPointer(); |
|
| |
EnumerateService *req |
Boolean MessageQueueService::SendAsync( |
= new EnumerateService(get_next_xid(), |
AsyncOpNode* op, |
0, |
Uint32 destination, |
_queueId, |
void (*callback)(AsyncOpNode*, MessageQueue*, void*), |
true, |
MessageQueue* callback_response_q, |
queue); |
void* callback_ptr) |
|
{ |
|
return _sendAsync( |
|
op, |
|
destination, |
|
callback, |
|
callback_response_q, |
|
callback_ptr, |
|
ASYNC_OPFLAGS_CALLBACK); |
| |
AsyncMessage *reply = SendWait(req); |
} |
| |
if (reply) |
Boolean MessageQueueService::_sendAsync( |
|
AsyncOpNode* op, |
|
Uint32 destination, |
|
void (*callback)(AsyncOpNode*, MessageQueue*, void*), |
|
MessageQueue* callback_response_q, |
|
void* callback_ptr, |
|
Uint32 flags) |
|
{ |
|
PEGASUS_ASSERT(op != 0 && callback != 0); |
|
|
|
// destination of this message |
|
op->_op_dest = MessageQueue::lookup(destination); |
|
if (op->_op_dest == 0) |
{ | { |
Boolean found = false; |
return false; |
|
} |
|
op->_flags = flags; |
|
// initialize the callback data |
|
// callback function to be executed by recpt. of response |
|
op->_async_callback = callback; |
|
// the op node |
|
op->_callback_node = op; |
|
// the queue that will receive the response |
|
op->_callback_response_q = callback_response_q; |
|
// user data for callback |
|
op->_callback_ptr = callback_ptr; |
|
// I am the originator of this request |
|
op->_callback_request_q = this; |
| |
if( reply->getMask() & message_mask::ha_async) |
return _meta_dispatcher->route_async(op); |
{ |
} |
if(reply->getMask() & message_mask::ha_reply) |
|
|
Boolean MessageQueueService::SendForget(Message* msg) |
{ | { |
if(reply->getType() == async_messages::ENUMERATE_SERVICE_RESULT) |
AsyncOpNode* op = 0; |
|
Uint32 mask = msg->getMask(); |
|
|
|
if (mask & MessageMask::ha_async) |
{ | { |
if( (static_cast<EnumerateServiceResponse *>(reply))->result == async_results::OK ) |
op = (static_cast<AsyncMessage *>(msg))->op; |
|
} |
|
|
|
if (op == 0) |
{ | { |
if( found == false) |
op = get_op(); |
|
op->_request.reset(msg); |
|
if (mask & MessageMask::ha_async) |
{ | { |
found = true; |
(static_cast<AsyncMessage *>(msg))->op = op; |
|
|
result->put_name( (static_cast<EnumerateServiceResponse *>(reply))->name); |
|
result->put_capabilities((static_cast<EnumerateServiceResponse *>(reply))->capabilities); |
|
result->put_mask((static_cast<EnumerateServiceResponse *>(reply))->mask); |
|
result->put_queue((static_cast<EnumerateServiceResponse *>(reply))->qid); |
|
} | } |
} | } |
|
|
|
PEGASUS_ASSERT(op->_flags == ASYNC_OPFLAGS_UNKNOWN); |
|
PEGASUS_ASSERT(op->_state == ASYNC_OPSTATE_UNKNOWN); |
|
op->_op_dest = MessageQueue::lookup(msg->dest); |
|
if (op->_op_dest == 0) |
|
{ |
|
return_op(op); |
|
return false; |
} | } |
|
|
|
op->_flags = ASYNC_OPFLAGS_FIRE_AND_FORGET; |
|
|
|
// now see if the meta dispatcher will take it |
|
return _meta_dispatcher->route_async(op); |
} | } |
|
|
|
|
|
AsyncReply *MessageQueueService::SendWait(AsyncRequest* request) |
|
{ |
|
if (request == 0) |
|
return 0; |
|
|
|
Boolean destroy_op = false; |
|
|
|
if (request->op == 0) |
|
{ |
|
request->op = get_op(); |
|
request->op->_request.reset(request); |
|
destroy_op = true; |
} | } |
delete reply; |
|
|
PEGASUS_ASSERT(request->op->_flags == ASYNC_OPFLAGS_UNKNOWN); |
|
PEGASUS_ASSERT(request->op->_state == ASYNC_OPSTATE_UNKNOWN); |
|
|
|
request->block = false; |
|
_sendAsync( |
|
request->op, |
|
request->dest, |
|
_sendwait_callback, |
|
this, |
|
(void *)0, |
|
ASYNC_OPFLAGS_PSEUDO_CALLBACK); |
|
|
|
request->op->_client_sem.wait(); |
|
|
|
AsyncReply* rpl = static_cast<AsyncReply *>(request->op->removeResponse()); |
|
rpl->op = 0; |
|
|
|
if (destroy_op == true) |
|
{ |
|
request->op->_request.release(); |
|
return_op(request->op); |
|
request->op = 0; |
|
} |
|
return rpl; |
} | } |
delete req; |
|
| |
return; |
Uint32 MessageQueueService::find_service_qid(const String &name) |
|
{ |
|
MessageQueue* queue = MessageQueue::lookup((const char*)name.getCString()); |
|
PEGASUS_ASSERT(queue); |
|
return queue->getQueueId(); |
} | } |
| |
Uint32 MessageQueueService::get_next_xid(void) |
void MessageQueueService::_removeFromPollingList(MessageQueueService *service) |
{ | { |
_xid++; |
_polling_list_mutex.lock(); |
return _xid.value(); |
_polling_list->remove(service); |
|
_polling_list_mutex.unlock(); |
} | } |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |