2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.executionqueue.helper;
28 import org.onap.appc.configuration.Configuration;
29 import org.onap.appc.configuration.ConfigurationFactory;
30 import com.att.eelf.configuration.EELFLogger;
31 import com.att.eelf.configuration.EELFManager;
32 import java.util.concurrent.Executors;
33 import java.util.concurrent.ThreadFactory;
34 import java.util.concurrent.atomic.AtomicInteger;
38 private int defaultQueueSize = 10;
39 private int defaultThreadpoolSize = 10;
40 private String queueSizeKey = "appc.dispatcher.executionqueue.backlog.size";
41 private String threadpoolSizeKey = "appc.dispatcher.executionqueue.threadpool.size";
42 private EELFLogger logger = EELFManager.getInstance().getLogger(Util.class);
44 private Configuration configuration;
48 * <p>Used by blueprint.
51 configuration = ConfigurationFactory.getConfiguration();
54 public int getExecutionQueueSize() {
55 String sizeStr = configuration.getProperty(queueSizeKey, String.valueOf(defaultQueueSize));
57 int size = defaultQueueSize;
59 size = Integer.parseInt(sizeStr);
60 } catch (NumberFormatException e) {
61 logger.error("Error parsing dispatcher execution queue backlog size", e);
67 public int getThreadPoolSize() {
68 String sizeStr = configuration.getProperty(threadpoolSizeKey, String.valueOf(defaultThreadpoolSize));
70 int size = defaultThreadpoolSize;
72 size = Integer.parseInt(sizeStr);
73 } catch (NumberFormatException e) {
74 logger.error("Error parsing dispatcher execution queue threadpool size", e);
80 public ThreadFactory getThreadFactory(final boolean isDaemon, final String threadNamePrefix) {
81 return new ThreadFactory() {
82 private final String THREAD_NAME_PATTERN = "%s-%d";
83 private final ThreadFactory factory = Executors.defaultThreadFactory();
84 private final AtomicInteger counter = new AtomicInteger();
86 public Thread newThread(Runnable r) {
87 Thread t = factory.newThread(r);
88 t.setDaemon(isDaemon);
89 if (threadNamePrefix != null && !threadNamePrefix.isEmpty()) {
90 final String threadName = String.format(THREAD_NAME_PATTERN, threadNamePrefix, counter.incrementAndGet());
91 t.setName(threadName);