From 13ce0552dc7156b6e3e226c00295705f27780a40 Mon Sep 17 00:00:00 2001 From: DR695H Date: Tue, 7 Feb 2017 13:11:03 -0500 Subject: actually adding the files to the initial commit Change-Id: I2f0c09692c2ae70be61b8bb552fd1bd2983eb661 Signed-off-by: DR695H --- .../portalapp/uebhandler/InitUebHandler.java | 88 ++++++++++++++++ .../portalapp/uebhandler/MainUebHandler.java | 117 +++++++++++++++++++++ .../uebhandler/WidgetNotificationHandler.java | 61 +++++++++++ 3 files changed, 266 insertions(+) create mode 100644 vid/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java create mode 100644 vid/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java create mode 100644 vid/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java (limited to 'vid/src/main/java/org/openecomp/portalapp/uebhandler') diff --git a/vid/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java b/vid/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java new file mode 100644 index 00000000..31c5882c --- /dev/null +++ b/vid/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.portalapp.uebhandler; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; + +import org.openecomp.portalsdk.core.logging.format.AlarmSeverityEnum; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiConstants; +import org.openecomp.portalsdk.core.onboarding.crossapi.PortalApiProperties; +import org.openecomp.portalsdk.core.onboarding.ueb.UebManager; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.openecomp.vid.conf.ExternalAppConfig; + +// +// Adding this class for the sole purpose of insuring that the MainUebHandler really +// honors @Async and kicks off a thread. For more info google @Async and read about +// @Async only working if called from different class. +/** + * The Class InitUebHandler. + */ +// +@Configuration +public class InitUebHandler { + + /** The logger. */ + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(InitUebHandler.class); + + + /** The main ueb handler. */ + @Autowired + MainUebHandler mainUebHandler; + + /** + * Instantiates a new inits the ueb handler. + */ + public InitUebHandler() { + + } + + /** + * Inits the ueb. + */ + @PostConstruct + public void initUeb() { + + try { + String enableListenerThread = PortalApiProperties.getProperty(PortalApiConstants.UEB_LISTENERS_ENABLE); + if (enableListenerThread.equalsIgnoreCase("true")) { + ConcurrentLinkedQueue inboxQueue = new ConcurrentLinkedQueue(); + UebManager.getInstance().initListener(inboxQueue); + mainUebHandler.runHandler(inboxQueue); + logger.info(EELFLoggerDelegate.debugLogger, ("Returned from initiating mainUebHandler...")); + } + else { + logger.info(EELFLoggerDelegate.debugLogger, ("Not starting UEB listening thread because ueb_listeners_enable is not set to true in the properties file.")); + } + } + catch (Exception e) { + logger.error(EELFLoggerDelegate.debugLogger, ("Not starting UEB listening thread because property could not be read " + PortalApiConstants.UEB_LISTENERS_ENABLE),AlarmSeverityEnum.MAJOR); + } + + } +} + diff --git a/vid/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java b/vid/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java new file mode 100644 index 00000000..5b7f0e4a --- /dev/null +++ b/vid/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.portalapp.uebhandler; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsgTypes; + +//------------------------------------------------------------------------- +// Listens for received UEB messages and handles the messages +// +// Note: To implement a synchronous reply call getMsgId on the request +// and putMsgId on the reply (echoing the request MsgId). +// +/** + * The Class MainUebHandler. + */ +//------------------------------------------------------------------------- +@Component("MainUebHandler") +public class MainUebHandler { + + /** The logger. */ + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MainUebHandler.class); + + + /** The inbox queue. */ + ConcurrentLinkedQueue inboxQueue = null; + + /** The widget notification handler. */ + @Autowired + WidgetNotificationHandler widgetNotificationHandler; + + /** + * Run handler. + * + * @param queue the queue + */ + @Async + public void runHandler(ConcurrentLinkedQueue queue) { + inboxQueue = queue; + + logger.info(EELFLoggerDelegate.debugLogger, ("==> MainUebHandler started")); + + while (true) { + UebMsg msg = null; + while ((msg = inboxQueue.poll()) != null) { + if (msg.getMsgType() != null) { + logger.debug(EELFLoggerDelegate.debugLogger, ("<== Received UEB message : " + msg.toString())); + + switch (msg.getMsgType()) { + /* + * Add your own defined handler objects, use @Component for + * the class. See WidgetNotificationHandler as an example. + * + * Use @Async on methods for performance + * + * For syncronous replies use UebManager publishReply and + * echo back the msgId in your response ie + * msg.putMsgId(requestMsg.getMsgId()) + * + * case UebMsgTypes.UEB_MSG_TYPE_XYZ: { + * XYZHandler.handleMsg(msg); break; } + */ + case UebMsgTypes.UEB_MSG_TYPE_WIDGET_NOTIFICATION: { + widgetNotificationHandler.handleWidgetNotification(msg); + break; + } + default: { + + logger.info(EELFLoggerDelegate.debugLogger, ("Unknown message type [" + msg.getMsgType() + "] from " + msg.getSourceTopicName())); + + break; + } + } + } + } + + if (Thread.interrupted()) { + + logger.info(EELFLoggerDelegate.debugLogger, ("==> UebMainHandler exiting")); + + break; + } + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + logger.info(EELFLoggerDelegate.debugLogger, ("UebMainHandler interrupted during sleep" + e.getMessage())); + + } + } + } +} diff --git a/vid/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java b/vid/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java new file mode 100644 index 00000000..dba84d4a --- /dev/null +++ b/vid/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.portalapp.uebhandler; + +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; + + +/** + * The Class WidgetNotificationHandler. + */ +@Component +public class WidgetNotificationHandler { + + /** The logger. */ + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetNotificationHandler.class); + + + /** + * Instantiates a new widget notification handler. + */ + public WidgetNotificationHandler() { + } + + /** + * Handle widget notification. + * + * @param requestMsg the request msg + */ + @Async + public void handleWidgetNotification(UebMsg requestMsg) { + logger.debug(EELFLoggerDelegate.debugLogger, ("handleWidgetNotification received notification: " + requestMsg.toString())); + /* + * Here the notification msg can be handled + * + * requestMsg.getPayload() - returns string that contains the + * Application defined content + */ + } +} -- cgit 1.2.3-korg