Fix sonar issues in dcaegen2/services/mapper
[dcaegen2/services/mapper.git] / UniversalVesAdapter / src / main / java / org / onap / universalvesadapter / service / VesService.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : DCAE
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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 package org.onap.universalvesadapter.service;
21
22 import org.onap.universalvesadapter.dmaap.Creator;
23 import org.onap.universalvesadapter.dmaap.MRPublisher.DMaaPMRPublisher;
24 import org.onap.universalvesadapter.dmaap.MRSubcriber.DMaaPMRSubscriber;
25 import org.onap.universalvesadapter.exception.MapperConfigException;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
30
31 /**
32  * Service that starts the universal ves adapter module to listen for events
33  * 
34  * @author kmalbari
35  *
36  */
37 @Component
38 public class VesService {
39
40         private final Logger LOGGER = LoggerFactory.getLogger(VesService.class);
41
42         private boolean isRunning = true;
43
44         @Autowired
45         private DMaapService dmaapService;
46
47         @Autowired
48         private Creator creator;
49
50
51         /**
52          * method triggers universal VES adapter module.
53          */
54         public void start() throws MapperConfigException {
55                 LOGGER.debug("Creating Subcriber and Publisher with creator.............");
56                 DMaaPMRSubscriber subcriber = creator.getDMaaPMRSubscriber();
57
58                 DMaaPMRPublisher publisher = creator.getDMaaPMRPublisher();
59
60                 // Create subscriber & publisher thread
61                 Thread t1 = new Thread(new Runnable() {
62                         @Override
63                         public void run() {
64                                 try {
65                                         LOGGER.debug("starting subscriber & publisher thread:{}", Thread.currentThread().getName());
66                                         dmaapService.fetchAndPublishInDMaaP(subcriber, publisher, creator);
67                                 } catch (InterruptedException e) {
68                                     LOGGER.error("Exception in starting of subscriber & publisher thread:{}",e);
69                                     Thread.currentThread().interrupt();
70                                 }
71                         }
72                 });
73
74                 // Start subscriber & publisher thread
75                 t1.setName("SNMP-COLLECTOR");
76                 t1.start();
77
78         }
79
80         /**
81          * method stops universal ves adapter module
82          */
83         public void stop() {
84                 isRunning = false;
85         }
86 }
87