2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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.listener;
26 import java.util.Properties;
29 * A class for instantiating Listener objects. It is primarily used to hold properties that start with the given prefix.
30 * It also holds a class that implements {@see Listener} and will be used by the controller to spawn a new listener
36 public class ListenerProperties {
38 private String prefix;
40 private Class<? extends Listener> listenerClass;
42 private Properties props;
45 * Creates a new listener object with the given prefix and properties. Any property starting with the prefix is
46 * added to the internal properties object with the prefix removed. All other properties are ignored.
47 * ListenerProperties constructor
50 * The prefix of the properties to load
52 * The properties object to load from.
54 public ListenerProperties(String prefix, Properties allProps) {
56 props = new Properties();
58 String dottedPrefix = String.format("%s.", prefix);
59 for (String key : allProps.stringPropertyNames()) {
60 if (key.startsWith(dottedPrefix) && key.length() > dottedPrefix.length()) {
61 props.put(key.substring(dottedPrefix.length()), allProps.get(key));
67 * @return The prefix of these properties
69 public String getPrefix() {
74 * Sets the listener class. Will be used by {@see Controller} to instantiate the Listener thread for this object
77 * The class to be created. Implements {@see Listener}
79 public void setListenerClass(Class<? extends Listener> cls) {
80 this.listenerClass = cls;
84 * @return The class that will be used by {@see Controller} to instantiate the Listener thread for this object
86 public Class<? extends Listener> getListenerClass() {
91 * Returns a property matching a given KEYS
94 * The KEYS object who's value to return.
95 * @return The value of the property or null if none exists
97 public String getProperty(KEYS key) {
98 return getProperty(key, null);
102 * Returns a property matching a given string.
105 * The key who's value to return.
106 * @return The value of the property or null if none exists
108 public String getProperty(String key) {
109 return getProperty(key, null);
113 * Returns a property matching a given KEYS
116 * The KEYS object who's value to return.
117 * @param defaultValue
118 * The value to return if the property is not found
119 * @return The value of the property or null if none exists
121 public String getProperty(KEYS key, String defaultValue) {
122 return getProperty(key.getPropertySuffix(), defaultValue);
126 * Returns a property matching a given string.
129 * The key who's value to return.
130 * @param defaultValue
131 * The value to return if the property is not found
132 * @return The value of the property or null if none exists
134 public String getProperty(String key, String defaultValue) {
135 return props.getProperty(key, defaultValue);
139 * @return The properties object containing all properties
141 public Properties getProperties() {
146 * Reads the <i>prefix</i>.disabled property to determine if the listener is disabled and should not be run by the
147 * controller. Defaults to false if property not set or value cannot be parsed.
149 * @return true if the listener is disabled and should not be started. false if the listener should be start
150 * normally (default).
152 public boolean isDisabled() {
153 return Boolean.valueOf(getProperty(KEYS.DISABLED, "false"));
157 public String toString() {
158 return String.format("%s", prefix);
163 * Set of common properties that will be used by most systems. Primarily relating to DMaaP and ThreadPools
165 * @since Apr 25, 2016
170 * Property to determine if the listener should be disabled. If not set, defaults to false
172 DISABLED("disabled"),
175 * Property for the message service type. Should be a lower case string. See MessageService.
177 MESSAGE_SERVICE("service"),
180 * A hostname or comma separated list (no spaces) of hostnames of servers in a cluster. Can have ports included
184 * <li>server1.appc.onap.org</li>
185 * <li>server1.appc.onap.org:3904</li>
186 * <li>server1.appc.onap.org,server2.appc.onap.org</li>
189 HOSTS("poolMembers"),
192 * The topic that will be used for DMaaP read operations. Can only support a single topic.
194 TOPIC_READ("topic.read"),
197 * The topic or topics that will be used to write to. If multiple topics are provided, should be in a comma
198 * seperated list with no spaces.<br>
202 * <li>TOPIC-1,TOPIC-2,ANOTHER-TOPIC</li>
205 TOPIC_WRITE("topic.write"),
208 * The highland park filter to use on read requests. If you are reading and writing to the same topic this must
209 * be provided. Filter should be in JSON format (not url escaped).
211 TOPIC_READ_FILTER("topic.read.filter"),
214 * The amount of time in seconds that the DMaaP polling connection should stay open for. Recommended to be set
215 * high (around 60 seconds) as most clients will return immediately and not wait until the timeout is up to
216 * return if they have data.
218 TOPIC_READ_TIMEOUT("topic.read.timeout"),
221 * Blacklist time for a server with response problem in seconds
224 PROBLEM_WITH_RESPONSE_BLACKLIST_TIME("topic.responseProblem.blacklistTime"),
226 * Blacklist time for a server with server problem in seconds
229 PROBLEM_SERVERSIDE_ERROR_BLACKLIST_TIME("topic.serverError.blacklistTime"),
231 * Blacklist time for a server with DNS problem in seconds
234 PROBLEM_DNS_BLACKLIST_TIME("topic.dnsIssue.blacklistTime"),
236 * Blacklist time for a server with IO Exception problem in seconds
239 PROBLEM_IO_EXCEPTION_BLACKLIST_TIME("topic.ioException.blacklistTime"),
242 * The name of the client to use. Should be unique to the application.
244 CLIENT_NAME("client.name"),
247 * The id of the client to use. Should be unique for each instance of the application in an environment.
249 CLIENT_ID("client.name.id"),
252 * The User (DMaaP) to use for authentication. If a user is provided, you must include the
253 * domain name (e.g. example<b>@example.com</b>).
255 AUTH_USER_KEY("client.key"),
258 * The password (DMaaP) to use for authentication.
260 AUTH_SECRET_KEY("client.secret"),
263 * The minimum amount of size of the queue. A client should request new messages once the queue has dropped
266 THREADS_MIN_QUEUE("threads.queuesize.min"),
269 * The maximum size of the queue. A client will request no new messages once this maximum size has been reached.
271 THREADS_MAX_QUEUE("threads.queuesize.max"),
274 * The minimum size of the worker threads pool. This is the pool each listener will use to launch longer running
277 THREADS_MIN_POOL("threads.poolsize.min"),
280 * The maximum size of the worker threads pool. This is the pool each listener will use to launch longer running
283 THREADS_MAX_POOL("threads.poolsize.max");
285 private String suffix;
287 private KEYS(String val) {
293 * The prefix to prepend
294 * @return a fully property name that corroponds to what is used in the properties file. Format is PREFIX.KEY
296 public String getFullProp(String prefix) {
297 return String.format("%s.%s", prefix, suffix);
300 public String getPropertySuffix() {