1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 Wipro Limited.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 *******************************************************************************/
22 package org.onap.dcaegen2.services.sonhms;
24 import java.sql.Timestamp;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.concurrent.BlockingQueue;
29 import java.util.concurrent.ExecutorService;
30 import java.util.concurrent.Executors;
31 import java.util.concurrent.LinkedBlockingQueue;
33 import javax.annotation.PostConstruct;
35 import org.onap.dcaegen2.services.sonhms.child.ChildThread;
36 import org.onap.dcaegen2.services.sonhms.child.Graph;
37 import org.onap.dcaegen2.services.sonhms.dao.FixedPciCellsRepository;
38 import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
39 import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils;
40 import org.onap.dcaegen2.services.sonhms.utils.ThreadUtils;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.scheduling.annotation.Scheduled;
45 import org.springframework.stereotype.Component;
48 public class MainThreadComponent {
50 private static Logger log = LoggerFactory.getLogger(MainThreadComponent.class);
53 private NewSdnrNotification newNotification;
56 private NewPmNotification newPmNotification;
59 private NewFmNotification newFmNotification;
62 * main thread initialization.
66 log.debug("initializing main thread");
67 Thread thread = new Thread(new MainThread(newNotification, newFmNotification));
69 Thread pmThread = new Thread(new PmThread(newPmNotification));
73 @Scheduled(fixedRate = 300000, initialDelay = 60000)
74 public void checkFixedPciTable() {
75 log.info("Inside checkFixedPciTable method");
76 FixedPciCellsRepository fixedPciCellsRepository = BeanUtil.getBean(FixedPciCellsRepository.class);
77 List<String> fixedPciCellsList = fixedPciCellsRepository.getFixedPciCells();
78 if (!fixedPciCellsList.isEmpty()) {
79 log.info("Fixed Pci table not empty");
80 Timestamp lastInvokedOofTimeStamp = ChildThread.getLastInvokedOofTimeStamp();
81 Timestamp fixedPciCreatedAt = fixedPciCellsRepository.getTimeStampforFixedPci();
82 Long difference = fixedPciCreatedAt.getTime() - lastInvokedOofTimeStamp.getTime();
83 Configuration configuration = Configuration.getInstance();
85 if (difference > configuration.getPolicyFixedPciTimeInterval()) {
86 log.info("Creating new child thread for sending fixedPciCells");
87 List<Graph> cluster = new ArrayList<>();
88 BlockingQueue<List<String>> childStatusQueue = new LinkedBlockingQueue<>();
89 EventHandler eventHandler = new EventHandler(childStatusQueue,
90 Executors.newFixedThreadPool(Configuration.getInstance().getMaximumClusters()), new HashMap<>(),
91 new ClusterUtils(), new ThreadUtils());
92 ExecutorService pool = Executors.newFixedThreadPool(5);
93 ThreadUtils threadUtils = new ThreadUtils();
94 boolean result = threadUtils.createNewThread(cluster, childStatusQueue, pool, eventHandler, null);
95 log.info("Child Thread creation result:"+ result);
99 log.info("Exiting function fixedPci table empty");