2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.executionqueue.helper;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.onap.appc.configuration.Configuration;
30 import org.onap.appc.configuration.ConfigurationFactory;
32 import java.util.concurrent.Executors;
33 import java.util.concurrent.ThreadFactory;
34 import java.util.concurrent.atomic.AtomicInteger;
38 private final EELFLogger logger = EELFManager.getInstance().getLogger(Util.class);
39 private final int default_queue_size = 10;
40 private final int default_threadpool_size = 10;
41 private final String queue_size_key = "appc.dispatcher.executionqueue.backlog.size";
42 private final String threadpool_size_key = "appc.dispatcher.executionqueue.threadpool.size";
44 private Configuration configuration;
48 * <p>Used by blueprint.
52 configuration = ConfigurationFactory.getConfiguration();
55 public int getExecutionQueueSize() {
56 String sizeStr = configuration.getProperty(queue_size_key, String.valueOf(default_queue_size));
58 int size = default_queue_size;
60 size = Integer.parseInt(sizeStr);
61 } catch (NumberFormatException e) {
62 logger.error("Error while parse key:" + queue_size_key + " got from configuration " + e.getMessage(), e);
68 public int getThreadPoolSize() {
69 String sizeStr = configuration.getProperty(threadpool_size_key, String.valueOf(default_threadpool_size));
71 int size = default_threadpool_size;
73 size = Integer.parseInt(sizeStr);
74 } catch (NumberFormatException e) {
75 logger.error("Error while parse key:" + threadpool_size_key + " got from configuration "
82 public ThreadFactory getThreadFactory(final boolean isDaemon, final String threadNamePrefix) {
83 return new ThreadFactory() {
84 private final String THREAD_NAME_PATTERN = "%s-%d";
85 private final ThreadFactory factory = Executors.defaultThreadFactory();
86 private final AtomicInteger counter = new AtomicInteger();
88 public Thread newThread(Runnable r) {
89 Thread t = factory.newThread(r);
90 t.setDaemon(isDaemon);
91 if (threadNamePrefix != null && !threadNamePrefix.isEmpty()) {
92 final String threadName = String.format(THREAD_NAME_PATTERN, threadNamePrefix, counter
94 t.setName(threadName);