1 karl 1.5 //%2006////////////////////////////////////////////////////////////////////////
|
2 h.sterling 1.1 //
3 // 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 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.5 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 h.sterling 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 //
21 // 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 // Author: Dong Xiang, EMC Corporation (xiang_dong@emc.com)
33 //
34 h.sterling 1.1 // Modified By: Heather Sterling, IBM (hsterl@us.ibm.com)
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include "DynamicListenerIndicationDispatcher.h"
39 #include "DynamicConsumer.h"
40 #include "ConsumerManager.h"
41
42 #include <Pegasus/Common/Config.h>
43 #include <Pegasus/Common/Constants.h>
44 #include <Pegasus/Common/OperationContext.h>
45 #include <Pegasus/Common/Tracer.h>
46
47 #include <Pegasus/Listener/List.h>
48 #include <Pegasus/Consumer/CIMIndicationConsumer.h>
49
50 PEGASUS_NAMESPACE_BEGIN
51 PEGASUS_USING_STD;
52
53 #define PEGASUS_QUEUE_NAME "DynamicListenerIndicationDispatcher"
54
55 h.sterling 1.1
56 DynamicListenerIndicationDispatcher::DynamicListenerIndicationDispatcher(ConsumerManager* consumerManager) :
57 Base(PEGASUS_QUEUE_NAME),
58 _consumerManager(consumerManager)
59 {
60 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerIndicationDispatcher::DynamicListenerIndicationDispatcher");
61
62 PEG_METHOD_EXIT();
63 }
64
65
66 DynamicListenerIndicationDispatcher::~DynamicListenerIndicationDispatcher()
67 {
68 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerIndicationDispatcher::~DynamicListenerIndicationDispatcher");
69
70 PEG_METHOD_EXIT();
71 }
72
73 void DynamicListenerIndicationDispatcher::handleEnqueue()
74 {
75 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerIndicationDispatcher::handleEnqueue");
76 h.sterling 1.1
77 Message *message = dequeue();
78 if (message)
79 handleEnqueue(message);
80
81 PEG_METHOD_EXIT();
82 }
83
84 void DynamicListenerIndicationDispatcher::handleEnqueue(Message* message)
85 {
86 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerIndicationDispatcher::handleEnqueue");
87
88 if (message!=NULL)
89 {
90 switch (message->getType())
91 {
92 case CIM_EXPORT_INDICATION_REQUEST_MESSAGE:
93 {
94 CIMExportIndicationRequestMessage* request = (CIMExportIndicationRequestMessage*)message;
95 CIMException cimException;
96
97 h.sterling 1.1 try
98 {
99 _handleIndicationRequest(request);
100
101 } catch (Exception& ex)
102 {
103 PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL2, "Exception getting consumer: " + ex.getMessage());
104 cimException = CIMException(CIM_ERR_FAILED, ex.getMessage());
105
106 Logger::put(
107 Logger::ERROR_LOG,
|
108 yi.zhou 1.6 System::CIMLISTENER,
|
109 h.sterling 1.1 Logger::SEVERE,
110 "Exception getting consumer: $0",
111 ex.getMessage());
112
113 } catch (...)
114 {
|
115 marek 1.7 PEG_TRACE_CSTRING(TRC_LISTENER, Tracer::LEVEL2, "Exception getting consumer: Unknown");
|
116 h.sterling 1.1 cimException = CIMException(CIM_ERR_FAILED, "Unknown exception");
117
118 Logger::put(
119 Logger::ERROR_LOG,
|
120 yi.zhou 1.6 System::CIMLISTENER,
|
121 h.sterling 1.1 Logger::SEVERE,
122 "Unknown Exception getting consumer");
123 }
124
125 //At this point (barring one of the above exceptions), we can be reasonably sure that the
126 //indication will get delivered and processed. The request was well-formatted and we
127 //were able to locate and load the consumer. Send an acknowledgement to the client
128 //that we received the indication.
129 //We should not wait until the consumer reports ultimate success since that could take a long
130 //time and would require us to store a bunch of status information. Additionally, the wait
131 //could cause a timeout exception on the client end.
132
133 //ATTN: Why isn't the CIM exception getting appended to the response? Go look in Message.h
134 CIMExportIndicationResponseMessage* response = new CIMExportIndicationResponseMessage(
135 request->messageId,
136 cimException,
137 request->queueIds.copyAndPop());
138
139 response->dest = request->queueIds.top();
140 _enqueueResponse(request, response);
141
142 h.sterling 1.1
143 }
144 break;
145 default:
146 {
147 //unsupported message type
148 //it should not get here; this error is caught in the request decoder
149 PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL2,
150 "Unsupported msg type: " + String(MessageTypeToString(message->getType())));
151
152 CIMRequestMessage* cimRequest = dynamic_cast<CIMRequestMessage*>(message);
153
154 CIMResponseMessage* response = cimRequest->buildResponse();
155 response->cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
156 h.sterling 1.2 MessageLoaderParms("DynListener.DynamicListenerIndicationDispatcher.INVALID_MSG_TYPE",
157 "Invalid message type"));
|
158 h.sterling 1.1
159 _enqueueResponse (cimRequest, response);
160 }
161 break;
162 }
163 delete message;
164 }
165
166 PEG_METHOD_EXIT();
167 }
168
169 void DynamicListenerIndicationDispatcher::_handleIndicationRequest(CIMExportIndicationRequestMessage* request)
170 {
171 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerIndicationDispatcher::handleIndicationRequest");
172
173 OperationContext context = request->operationContext;
174 String url = request->destinationPath;
175 CIMInstance instance = request->indicationInstance;
176
177 PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL4, "URL is " + url);
178
179 h.sterling 1.1 Uint32 slash = url.find("/");
180 if (slash == PEG_NOT_FOUND)
181 {
182 Logger::put(
183 Logger::ERROR_LOG,
|
184 yi.zhou 1.6 System::CIMLISTENER,
|
185 h.sterling 1.1 Logger::SEVERE,
186 "Invalid URL $0",
187 url);
188
189 MessageLoaderParms msgLoaderParms(
190 "DynListener.DynamicListenerIndicationDispatcher.BAD_URL",
|
191 h.sterling 1.2 "Invalid CIMXMLIndicationHandler destination: $0.",
|
192 h.sterling 1.1 url);
193
194 throw CIMException(CIM_ERR_FAILED, msgLoaderParms);
195 }
196
197 String consumerName = url.subString(slash+1);
198
|
199 h.sterling 1.3 //check for a trailing slash, in the case that additional information is in the URL, i.e. /CIMListener/MyConsumer/9.44.169.132
200 Uint32 trailingSlash = consumerName.find('/');
201 if (trailingSlash != PEG_NOT_FOUND)
202 {
203 consumerName = consumerName.subString(0, trailingSlash);
204 PEG_TRACE_STRING(TRC_LISTENER, Tracer::LEVEL2, "The consumer name with slash removed is!" + consumerName + "!");
205 }
206
|
207 h.sterling 1.1 //get consumer
208 //this will throw an exception if it fails
209 //gets deleted by the ConsumerManager
210 DynamicConsumer* consumer = _consumerManager->getConsumer(consumerName);
211
212 //deliver indication to consumer
213 //gets deleted by the DynamicConsumer
214 IndicationDispatchEvent* event = new IndicationDispatchEvent(request->operationContext,
215 request->destinationPath,
216 request->indicationInstance);
217
218 //enqueue event
219 consumer->enqueueEvent(event);
220
221 PEG_METHOD_EXIT();
222 }
223
224 PEGASUS_NAMESPACE_END
|