34dd4e743d9a5bfa5abb20770f22a73017f28ad1
[policy/common.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2017-2018 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.common.endpoints.event.comm.bus.internal;
22
23 import java.util.List;
24
25 import org.onap.policy.common.endpoints.event.comm.Topic;
26 import org.onap.policy.common.endpoints.event.comm.bus.UebTopicSink;
27 import org.onap.policy.common.endpoints.event.comm.bus.internal.impl.CambriaPublisherWrapper;
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
44      * 
45      * @param servers list of UEB servers available for publishing
46      * @param topic the topic to publish to
47      * @param apiKey the api key (optional)
48      * @param apiSecret the api secret (optional)
49      * @param partitionId the partition key (optional, autogenerated if not provided)
50      * @param useHttps does connection use HTTPS?
51      * @param allowSelfSignedCerts are self-signed certificates allow
52      * 
53      * @throws IllegalArgumentException if invalid arguments are detected
54      */
55     public InlineUebTopicSink(List<String> servers, String topic, String apiKey, String apiSecret, String partitionId,
56             boolean useHttps, boolean allowSelfSignedCerts) {
57         super(servers, topic, apiKey, apiSecret, partitionId, useHttps, allowSelfSignedCerts);
58     }
59
60     /**
61      * Instantiation of internal resources
62      */
63     @Override
64     public void init() {
65
66         this.publisher =
67                 new CambriaPublisherWrapper(this.servers, this.topic, this.apiKey, this.apiSecret,
68                     null, null, this.useHttps, this.allowSelfSignedCerts);
69         logger.info("{}: UEB SINK created", this);
70     }
71
72     @Override
73     public String toString() {
74         StringBuilder builder = new StringBuilder();
75         builder.append("InlineUebTopicSink [getTopicCommInfrastructure()=").append(getTopicCommInfrastructure())
76                 .append(", toString()=").append(super.toString()).append("]");
77         return builder.toString();
78     }
79
80     /**
81      * {@inheritDoc}
82      */
83     @Override
84     public CommInfrastructure getTopicCommInfrastructure() {
85         return Topic.CommInfrastructure.UEB;
86     }
87 }