f905bd7d14af6656968a729e4f552dcfd81b3a9b
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2017-2019, 2021 AT&T Intellectual Property. All rights reserved.
6  * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.common.endpoints.event.comm.bus.internal;
23
24 import org.onap.policy.common.endpoints.event.comm.Topic;
25 import org.onap.policy.common.endpoints.event.comm.bus.UebTopicSink;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * This implementation publishes events for the associated UEB topic, inline with the calling
31  * thread.
32  */
33 public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSink {
34
35     /**
36      * Logger.
37      */
38     private static Logger logger = LoggerFactory.getLogger(InlineUebTopicSink.class);
39
40     /**
41      * Argument-based UEB Topic Writer instantiation. BusTopicParams contains below mentioned
42      * attributes.
43      *
44      * <p>servers              list of UEB servers available for publishing
45      * topic                the topic to publish to
46      * apiKey               the api key (optional)
47      * apiSecret            the api secret (optional)
48      * partitionId          the partition key (optional, autogenerated if not provided)
49      * useHttps             does connection use HTTPS?
50      * allowSelfSignedCerts are self-signed certificates allow
51      * @param busTopicParams contains attributes needed
52      * @throws IllegalArgumentException if invalid arguments are detected
53      */
54     public InlineUebTopicSink(BusTopicParams busTopicParams) {
55         super(busTopicParams);
56     }
57
58     /**
59      * Instantiation of internal resources.
60      */
61     @Override
62     public void init() {
63
64         this.publisher = new BusPublisher.CambriaPublisherWrapper(BusTopicParams.builder()
65                 .servers(this.servers)
66                 .topic(this.effectiveTopic)
67                 .apiKey(this.apiKey)
68                 .apiSecret(this.apiSecret)
69                 .useHttps(this.useHttps)
70                 .allowSelfSignedCerts(this.allowSelfSignedCerts)
71                 .build());
72         logger.info("{}: UEB SINK created", this);
73     }
74
75     @Override
76     public String toString() {
77         return "InlineUebTopicSink [getTopicCommInfrastructure()=" + getTopicCommInfrastructure() + ", toString()="
78                         + super.toString() + "]";
79     }
80
81     @Override
82     public CommInfrastructure getTopicCommInfrastructure() {
83         return Topic.CommInfrastructure.UEB;
84     }
85 }