1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.utils;
24 import java.util.ArrayList;
25 import java.util.List;
27 import java.util.UUID;
28 import java.util.concurrent.BlockingQueue;
29 import java.util.concurrent.ExecutorService;
30 import java.util.concurrent.LinkedBlockingQueue;
32 import org.onap.dcaegen2.services.sonhms.EventHandler;
33 import org.onap.dcaegen2.services.sonhms.HoMetricsComponent;
34 import org.onap.dcaegen2.services.sonhms.child.ChildThread;
35 import org.onap.dcaegen2.services.sonhms.child.Graph;
36 import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
37 import org.onap.dcaegen2.services.sonhms.model.ThreadId;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
43 public class ThreadUtils {
45 private static Logger log = LoggerFactory.getLogger(ThreadUtils.class);
50 public Boolean createNewThread(List<Graph> newClusters, BlockingQueue<List<String>> childStatusQueue,
51 ExecutorService pool, EventHandler eventHandler,String cellId) {
54 for (Graph cluster : newClusters) {
56 BlockingQueue<Map<CellPciPair, ArrayList<CellPciPair>>> queue = new LinkedBlockingQueue<>();
57 ThreadId threadId = new ThreadId();
58 threadId.setChildThreadId(0);
59 ChildThread child = new ChildThread(childStatusQueue, cluster, queue, threadId, new HoMetricsComponent());
61 log.info("Creating new child thread");
63 waitForThreadId(threadId);
64 UUID clusterId = UUID.randomUUID();
66 ClusterUtils clusterUtils = new ClusterUtils();
67 clusterUtils.saveCluster(cluster, clusterId, threadId.getChildThreadId());
68 EventHandler.addChildThreadMap(threadId.getChildThreadId(), child);
69 eventHandler.addChildStatus(threadId.getChildThreadId(), "processingNotifications");
75 private void waitForThreadId(ThreadId threadId) {
77 ThreadId thread = threadId;
79 synchronized (thread) {
80 while (thread.getChildThreadId() == 0) {
84 } catch (InterruptedException e) {
86 log.error("ChildThread queue error {}", e);
87 Thread.currentThread().interrupt();