[VID-3] Setting docker image tag
[vid.git] / vid / src / main / java / org / openecomp / portalapp / uebhandler / MainUebHandler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.portalapp.uebhandler;
22
23 import java.util.concurrent.ConcurrentLinkedQueue;
24
25 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.scheduling.annotation.Async;
27 import org.springframework.stereotype.Component;
28
29 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
30 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;
31 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsgTypes;
32
33 //-------------------------------------------------------------------------
34 // Listens for received UEB messages and handles the messages
35 //
36 // Note: To implement a synchronous reply call getMsgId on the request 
37 //       and putMsgId on the reply (echoing the request MsgId).
38 //       
39 /**
40  * The Class MainUebHandler.
41  */
42 //-------------------------------------------------------------------------
43 @Component("MainUebHandler")
44 public class MainUebHandler {
45
46         /** The logger. */
47         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MainUebHandler.class);
48
49
50         /** The inbox queue. */
51         ConcurrentLinkedQueue<UebMsg> inboxQueue = null;
52
53         /** The widget notification handler. */
54         @Autowired
55         WidgetNotificationHandler widgetNotificationHandler;
56
57         /**
58          * Run handler.
59          *
60          * @param queue the queue
61          */
62         @Async
63         public void runHandler(ConcurrentLinkedQueue<UebMsg> queue) {
64                 inboxQueue = queue;
65
66                 logger.info(EELFLoggerDelegate.debugLogger, ("==> MainUebHandler started"));
67
68                 while (true) {
69                         UebMsg msg = null;
70                         while ((msg = inboxQueue.poll()) != null) {
71                                 if (msg.getMsgType() != null) {
72                                         logger.debug(EELFLoggerDelegate.debugLogger, ("<== Received UEB message : " + msg.toString()));
73
74                                         switch (msg.getMsgType()) {
75                                         /*
76                                          * Add your own defined handler objects, use @Component for
77                                          * the class. See WidgetNotificationHandler as an example.
78                                          *
79                                          * Use @Async on methods for performance
80                                          *
81                                          * For syncronous replies use UebManager publishReply and
82                                          * echo back the msgId in your response ie
83                                          * msg.putMsgId(requestMsg.getMsgId())
84                                          *
85                                          * case UebMsgTypes.UEB_MSG_TYPE_XYZ: {
86                                          * XYZHandler.handleMsg(msg); break; }
87                                          */
88                                         case UebMsgTypes.UEB_MSG_TYPE_WIDGET_NOTIFICATION: {
89                                                 widgetNotificationHandler.handleWidgetNotification(msg);
90                                                 break;
91                                         }
92                                         default: {
93                                                 
94                                                 logger.info(EELFLoggerDelegate.debugLogger, ("Unknown message type [" + msg.getMsgType() + "] from " + msg.getSourceTopicName()));
95
96                                                 break;
97                                         }
98                                         }
99                                 }
100                         }
101
102                         if (Thread.interrupted()) {
103                                 
104                                 logger.info(EELFLoggerDelegate.debugLogger, ("==> UebMainHandler exiting"));
105
106                                 break;
107                         }
108
109                         try {
110                                 Thread.sleep(10);
111                         } catch (InterruptedException e) {
112                                 logger.info(EELFLoggerDelegate.debugLogger, ("UebMainHandler interrupted during sleep" + e.getMessage()));
113
114                         }
115                 }
116         }
117 }