218e44b40ac520032ab1b0c86ddec674866b42e5
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2017-2018 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 java.util.List;
25
26 import org.onap.policy.common.endpoints.event.comm.Topic;
27 import org.onap.policy.common.endpoints.event.comm.bus.UebTopicSink;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * This implementation publishes events for the associated UEB topic, inline with the calling
33  * thread.
34  */
35 public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSink {
36
37     /**
38      * logger
39      */
40     private static Logger logger = LoggerFactory.getLogger(InlineUebTopicSink.class);
41
42     /**
43      * Argument-based UEB Topic Writer instantiation. BusTopicParams contains below mentioned
44      * attributes
45      *
46      * servers              list of UEB servers available for publishing
47      * topic                the topic to publish to
48      * apiKey               the api key (optional)
49      * apiSecret            the api secret (optional)
50      * partitionId          the partition key (optional, autogenerated if not provided)
51      * useHttps             does connection use HTTPS?
52      * allowSelfSignedCerts are self-signed certificates allow
53      * @param busTopicParams contains attributes needed
54      * @throws IllegalArgumentException if invalid arguments are detected
55      */
56     public InlineUebTopicSink(BusTopicParams busTopicParams) {
57         super(busTopicParams);
58     }
59
60     /**
61      * Instantiation of internal resources
62      */
63     @Override
64     public void init() {
65
66         this.publisher = new BusPublisher.CambriaPublisherWrapper(BusTopicParams.builder()
67                 .servers(this.servers)
68                 .topic(this.topic)
69                 .apiKey(this.apiKey)
70                 .apiSecret(this.apiSecret)
71                 .useHttps(this.useHttps)
72                 .allowSelfSignedCerts(this.allowSelfSignedCerts)
73                 .build());
74         logger.info("{}: UEB SINK created", this);
75     }
76
77     @Override
78     public String toString() {
79         StringBuilder builder = new StringBuilder();
80         builder.append("InlineUebTopicSink [getTopicCommInfrastructure()=").append(getTopicCommInfrastructure())
81                 .append(", toString()=").append(super.toString()).append("]");
82         return builder.toString();
83     }
84
85     /**
86      * {@inheritDoc}
87      */
88     @Override
89     public CommInfrastructure getTopicCommInfrastructure() {
90         return Topic.CommInfrastructure.UEB;
91     }
92 }