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