2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.uebhandler;
22 import java.util.concurrent.ConcurrentLinkedQueue;
24 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;
26 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsgTypes;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.scheduling.annotation.Async;
29 import org.springframework.stereotype.Component;
31 //-------------------------------------------------------------------------
32 // Listens for received UEB messages and handles the messages
34 // Note: To implement a synchronous reply call getMsgId on the request
35 // and putMsgId on the reply (echoing the request MsgId).
37 //-------------------------------------------------------------------------
38 @Component("MainUebHandler")
39 public class MainUebHandler {
41 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MainUebHandler.class);
44 ConcurrentLinkedQueue<UebMsg> inboxQueue = null;
47 WidgetNotificationHandler widgetNotificationHandler;
50 public void runHandler(ConcurrentLinkedQueue<UebMsg> queue) {
53 logger.info(EELFLoggerDelegate.debugLogger, ("==> MainUebHandler started"));
57 while ((msg = inboxQueue.poll()) != null) {
58 if (msg.getMsgType() != null) {
59 logger.debug(EELFLoggerDelegate.debugLogger, ("<== Received UEB message : " + msg.toString()));
61 switch (msg.getMsgType()) {
63 * Add your own defined handler objects, use @Component for
64 * the class. See WidgetNotificationHandler as an example.
66 * Use @Async on methods for performance
68 * For syncronous replies use UebManager publishReply and
69 * echo back the msgId in your response ie
70 * msg.putMsgId(requestMsg.getMsgId())
72 * case UebMsgTypes.UEB_MSG_TYPE_XYZ: {
73 * XYZHandler.handleMsg(msg); break; }
75 case UebMsgTypes.UEB_MSG_TYPE_WIDGET_NOTIFICATION: {
76 widgetNotificationHandler.handleWidgetNotification(msg);
81 logger.info(EELFLoggerDelegate.debugLogger, ("Unknown message type [" + msg.getMsgType() + "] from " + msg.getSourceTopicName()));
89 if (Thread.interrupted()) {
91 logger.info(EELFLoggerDelegate.debugLogger, ("==> UebMainHandler exiting"));
98 } catch (InterruptedException e) {
99 logger.info(EELFLoggerDelegate.debugLogger, ("UebMainHandler interrupted during sleep" + e.getMessage()));