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 org.onap.appc.configuration.Configuration;
28 import org.onap.appc.configuration.ConfigurationFactory;
30 import java.util.concurrent.Executors;
31 import java.util.concurrent.ThreadFactory;
32 import java.util.concurrent.atomic.AtomicInteger;
36 private int default_queue_size = 10;
37 private int default_threadpool_size = 10;
38 private String queue_size_key = "appc.dispatcher.executionqueue.backlog.size";
39 private String threadpool_size_key = "appc.dispatcher.executionqueue.threadpool.size";
41 private Configuration configuration;
45 * <p>Used by blueprint.
48 configuration = ConfigurationFactory.getConfiguration();
51 public int getExecutionQueueSize() {
52 String sizeStr = configuration.getProperty(queue_size_key, String.valueOf(default_queue_size));
54 int size = default_queue_size;
56 size = Integer.parseInt(sizeStr);
57 } catch (NumberFormatException e) {
64 public int getThreadPoolSize() {
65 String sizeStr = configuration.getProperty(threadpool_size_key, String.valueOf(default_threadpool_size));
67 int size = default_threadpool_size;
69 size = Integer.parseInt(sizeStr);
70 } catch (NumberFormatException e) {
77 public ThreadFactory getThreadFactory(final boolean isDaemon, final String threadNamePrefix) {
78 return new ThreadFactory() {
79 private final String THREAD_NAME_PATTERN = "%s-%d";
80 private final ThreadFactory factory = Executors.defaultThreadFactory();
81 private final AtomicInteger counter = new AtomicInteger();
83 public Thread newThread(Runnable r) {
84 Thread t = factory.newThread(r);
85 t.setDaemon(isDaemon);
86 if (threadNamePrefix != null && !threadNamePrefix.isEmpty()) {
87 final String threadName = String.format(THREAD_NAME_PATTERN, threadNamePrefix, counter.incrementAndGet());
88 t.setName(threadName);