summaryrefslogtreecommitdiffstats
path: root/policy-endpoints/src/main/java
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-03-18 15:59:04 -0500
committerJorge Hernandez <jorge.hernandez-herrero@att.com>2019-03-18 15:59:04 -0500
commitb124ec93d5b5ad22867a84624a0a07ab625d4356 (patch)
treeea1aab09a4bb808741717021ca759f65881c62ff /policy-endpoints/src/main/java
parent1ea998182b78ee8e857aa2974c554ca952f1f68f (diff)
TopicSinkClient support for unmanaged topics
Change-Id: I6b92dcc0f225aa712b34adb9a1f9ab47df412c81 Issue-ID: POLICY-1608 Signed-off-by: Jorge Hernandez <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-endpoints/src/main/java')
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClient.java31
1 files changed, 22 insertions, 9 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClient.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClient.java
index e44d1f76..f08a1381 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClient.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/client/TopicSinkClient.java
@@ -23,6 +23,7 @@ package org.onap.policy.common.endpoints.event.comm.client;
import java.util.List;
import lombok.Getter;
+import lombok.NonNull;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.utils.coder.Coder;
@@ -43,14 +44,9 @@ public class TopicSinkClient {
private static final Coder CODER = new StandardCoder();
/**
- * Topic to which messages are published.
- */
- @Getter
- private final String topic;
-
- /**
* Where messages are published.
*/
+ @Getter
private final TopicSink sink;
/**
@@ -60,8 +56,6 @@ public class TopicSinkClient {
* @throws TopicSinkClientException if the topic does not exist
*/
public TopicSinkClient(final String topic) throws TopicSinkClientException {
- this.topic = topic;
-
final List<TopicSink> lst = getTopicSinks(topic);
if (lst.isEmpty()) {
throw new TopicSinkClientException("no sinks for topic: " + topic);
@@ -71,6 +65,25 @@ public class TopicSinkClient {
}
/**
+ * Constructs the client from a sink object.
+ *
+ * @param sink topic sink publisher
+ */
+ public TopicSinkClient(@NonNull TopicSink sink) {
+ this.sink = sink;
+ }
+
+
+ /**
+ * Gets the canonical topic name.
+ *
+ * @return topic name
+ */
+ public String getTopic() {
+ return this.sink.getTopic();
+ }
+
+ /**
* Sends a message to the topic, after encoding the message as json.
*
* @param message message to be encoded and sent
@@ -82,7 +95,7 @@ public class TopicSinkClient {
return sink.send(json);
} catch (RuntimeException | CoderException e) {
- logger.warn("send to {} failed because of {}", topic, e.getMessage(), e);
+ logger.warn("send to {} failed because of {}", sink.getTopic(), e.getMessage(), e);
return false;
}
}