[PORTAL-7] Rebase
[portal.git] / ecomp-portal-BE-os / src / main / java / org / openecomp / portalapp / uebhandler / InitUebHandler.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal
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
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  * ================================================================================
19  */
20 package org.openecomp.portalapp.uebhandler;
21
22 import java.util.concurrent.ConcurrentLinkedQueue;
23
24 import javax.annotation.PostConstruct;
25
26 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
27 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
28 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
29 import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants;
30 import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties;
31 import org.openecomp.portalsdk.core.onboarding.ueb.UebManager;
32 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.context.annotation.Configuration;
35 import org.springframework.context.annotation.EnableAspectJAutoProxy;
36
37 //
38 // Adding this class for the sole purpose of insuring that the MainUebHandler really 
39 // honors @Async and kicks off a thread.  For more info google @Async and read about
40 // @Async only working if called from different class.
41 //
42 //@Configuration
43 //@EnableAspectJAutoProxy
44 //@EPMetricsLog
45 public class InitUebHandler {
46         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(InitUebHandler.class);
47         
48         //@Autowired
49         MainUebHandler mainUebHandler;
50         
51         public InitUebHandler() {
52         
53         }
54         
55         //@PostConstruct
56         public void initUeb()   {
57                 
58                 try {
59                         String enableListenerThread = PortalApiProperties.getProperty(PortalApiConstants.UEB_LISTENERS_ENABLE);
60                         if (enableListenerThread.equalsIgnoreCase("true")) {
61                 ConcurrentLinkedQueue<UebMsg> inboxQueue = new ConcurrentLinkedQueue<UebMsg>();
62                     UebManager.getInstance().initListener(inboxQueue);
63                         mainUebHandler.runHandler(inboxQueue);
64                     logger.info(EELFLoggerDelegate.errorLogger, "Returned from initiating mainUebHandler...");
65                 }
66                     else {
67                         logger.info(EELFLoggerDelegate.errorLogger, "Not starting UEB listening thread because ueb_listeners_enable is not set to true in the properties file.");
68                     }
69                 }
70                 catch (Exception e) {
71                         logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
72                         logger.info(EELFLoggerDelegate.errorLogger, "Not starting UEB listening thread because property could not be read " + PortalApiConstants.UEB_LISTENERS_ENABLE + e.getMessage());
73                 }
74         }
75 }