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.text.DateFormat;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.concurrent.ConcurrentLinkedQueue;
27 import org.openecomp.portalapp.portal.ueb.EPUebMsgTypes;
28 import org.openecomp.portalapp.portal.utils.EPSystemProperties;
29 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
30 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
31 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;
32 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsgTypes;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.scheduling.annotation.Async;
36 import org.springframework.stereotype.Component;
38 import com.att.eelf.configuration.Configuration;
41 //-------------------------------------------------------------------------
42 // Listens for received UEB messages and handles the messages
44 // Note: To implement a synchronous reply call getMsgId on the request
45 // and putMsgId on the reply (echoing the request MsgId).
47 //-------------------------------------------------------------------------
48 @Component("MainUebHandler")
49 public class MainUebHandler
51 final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
52 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MainUebHandler.class);
54 ConcurrentLinkedQueue<UebMsg> inboxQueue = null;
57 FunctionalMenuHandler funcMenuHandler;
60 WidgetNotificationHandler widgetNotificationHandler;
63 public void runHandler(ConcurrentLinkedQueue<UebMsg> queue)
66 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "==> MainUebHandler started");
70 while ((msg = inboxQueue.poll()) != null)
72 if ((msg.getMsgType() != null) && (!msg.getMsgType().equalsIgnoreCase(EPUebMsgTypes.UEB_MSG_TYPE_HEALTH_CHECK)))
74 // TODO: switch this back to debug
75 logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== Received UEB message : " + msg.toString());
76 logger.info(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== Received UEB message : " + msg.toString());
77 MDC.put(EPSystemProperties.PARTNER_NAME, msg.getSourceTopicName());
78 MDC.put(Configuration.MDC_SERVICE_NAME, msg.getMsgType().toString());
79 switch(msg.getMsgType())
81 case UebMsgTypes.UEB_MSG_TYPE_GET_FUNC_MENU:
83 funcMenuHandler.getFunctionalMenu(msg);
86 case UebMsgTypes.UEB_MSG_TYPE_WIDGET_NOTIFICATION:
88 widgetNotificationHandler.handleWidgetNotification(msg);
93 logger.info(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "Unknown UEB message type " + msg.toString());
100 if (Thread.interrupted())
102 logger.info(EELFLoggerDelegate.errorLogger, "==> UebMainHandler exiting");
108 } catch (InterruptedException e) {
109 logger.error(EELFLoggerDelegate.errorLogger, "UebMainHandler interrupted during sleep" + EcompPortalUtils.getStackTrace(e));
110 } catch (Exception e) {
111 logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred during sleep" + EcompPortalUtils.getStackTrace(e));