2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.executionqueue.helper;
26 import org.onap.appc.configuration.Configuration;
27 import org.onap.appc.configuration.ConfigurationFactory;
29 import java.util.concurrent.Executors;
30 import java.util.concurrent.ThreadFactory;
31 import java.util.concurrent.atomic.AtomicInteger;
35 private int default_queue_size = 10;
36 private int default_threadpool_size = 10;
37 private String queue_size_key = "appc.dispatcher.executionqueue.backlog.size";
38 private String threadpool_size_key = "appc.dispatcher.executionqueue.threadpool.size";
40 private Configuration configuration;
44 * <p>Used by blueprint.
47 configuration = ConfigurationFactory.getConfiguration();
50 public int getExecutionQueueSize() {
51 String sizeStr = configuration.getProperty(queue_size_key, String.valueOf(default_queue_size));
53 int size = default_queue_size;
55 size = Integer.parseInt(sizeStr);
56 } catch (NumberFormatException e) {
63 public int getThreadPoolSize() {
64 String sizeStr = configuration.getProperty(threadpool_size_key, String.valueOf(default_threadpool_size));
66 int size = default_threadpool_size;
68 size = Integer.parseInt(sizeStr);
69 } catch (NumberFormatException e) {
76 public ThreadFactory getThreadFactory(final boolean isDaemon, final String threadNamePrefix) {
77 return new ThreadFactory() {
78 private final String THREAD_NAME_PATTERN = "%s-%d";
79 private final ThreadFactory factory = Executors.defaultThreadFactory();
80 private final AtomicInteger counter = new AtomicInteger();
82 public Thread newThread(Runnable r) {
83 Thread t = factory.newThread(r);
84 t.setDaemon(isDaemon);
85 if (threadNamePrefix != null && !threadNamePrefix.isEmpty()) {
86 final String threadName = String.format(THREAD_NAME_PATTERN, threadNamePrefix, counter.incrementAndGet());
87 t.setName(threadName);