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