2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019, 2021 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 com.google.re2j.Pattern;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.Properties;
29 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
30 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
35 public abstract class NoopTopicFactory<T extends NoopTopicEndpoint> extends TopicBaseHashedFactory<T> {
36 private static final Pattern COMMA_SPACE_PAT = Pattern.compile("\\s*,\\s*");
39 * Get Topics Property Name.
41 * @return property name.
43 protected abstract String getTopicsPropertyName();
49 protected List<String> getTopicNames(Properties properties) {
50 String topics = properties.getProperty(getTopicsPropertyName());
51 if (topics == null || topics.isEmpty()) {
52 return new ArrayList<>();
55 return Arrays.asList(COMMA_SPACE_PAT.split(topics));
62 protected List<String> getServers(String topicName, Properties properties) {
64 properties.getProperty(getTopicsPropertyName() + "." + topicName
65 + PolicyEndPointProperties.PROPERTY_TOPIC_SERVERS_SUFFIX);
67 if (servers == null || servers.isEmpty()) {
68 servers = CommInfrastructure.NOOP.toString();
71 return new ArrayList<>(Arrays.asList(COMMA_SPACE_PAT.split(servers)));
78 protected boolean isManaged(String topicName, Properties properties) {
80 properties.getProperty(getTopicsPropertyName()
81 + "." + topicName + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX);
84 if (managedString != null && !managedString.isEmpty()) {
85 managed = Boolean.parseBoolean(managedString);
95 public T build(List<String> serverList, String topic, boolean managed) {
97 if (serverList == null || serverList.isEmpty()) {
98 servers = Collections.singletonList(CommInfrastructure.NOOP.toString());
100 servers = serverList;
103 return super.build(servers, topic, managed);
110 public String toString() {
111 return "NoopTopicFactory[ " + super.toString() + " ]";