2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.common.endpoints.event.comm.bus;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Collections;
26 import java.util.List;
27 import java.util.Properties;
28 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
29 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
34 public abstract class NoopTopicFactory<T extends NoopTopicEndpoint> extends TopicBaseHashedFactory<T> {
37 * Get Topics Property Name.
39 * @return property name.
41 protected abstract String getTopicsPropertyName();
47 protected List<String> getTopicNames(Properties properties) {
48 String topics = properties.getProperty(getTopicsPropertyName());
49 if (topics == null || topics.isEmpty()) {
50 return new ArrayList<>();
53 return Arrays.asList(topics.split("\\s*,\\s*"));
60 protected List<String> getServers(String topicName, Properties properties) {
62 properties.getProperty(getTopicsPropertyName() + "." + topicName
63 + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX);
65 if (servers == null || servers.isEmpty()) {
66 servers = CommInfrastructure.NOOP.toString();
69 return new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*")));
76 protected boolean isManaged(String topicName, Properties properties) {
77 String managedString =
78 properties.getProperty(getTopicsPropertyName()
79 + "." + topicName + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX);
81 boolean managed = true;
82 if (managedString != null && !managedString.isEmpty()) {
83 managed = Boolean.parseBoolean(managedString);
93 public T build(List<String> serverList, String topic, boolean managed) {
95 if (serverList == null || serverList.isEmpty()) {
96 servers = Collections.singletonList(CommInfrastructure.NOOP.toString());
101 return super.build(servers, topic, managed);
108 public String toString() {
109 return "NoopTopicFactory[ " + super.toString() + " ]";