2d4b15527ce52bfabebe147785b079e39e3c1009
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-endpoints
4  * ================================================================================
5  * Copyright (C) 2017 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.openecomp.policy.drools.event.comm.bus.internal;
22
23 import java.util.List;
24
25 import org.openecomp.policy.drools.event.comm.Topic;
26 import org.openecomp.policy.drools.event.comm.bus.UebTopicSink;
27 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
28
29 /**
30  * This implementation publishes events for the associated UEB topic,
31  * inline with the calling thread.
32  */
33 public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSink {
34         
35         /**
36          * logger 
37          */
38         private static org.openecomp.policy.common.logging.flexlogger.Logger logger = 
39                                                                                 FlexLogger.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          * 
50          * @throws IllegalArgumentException if invalid arguments are detected
51          */
52         public InlineUebTopicSink(List<String> servers, 
53                                                                 String topic, 
54                                                 String apiKey, 
55                                                 String apiSecret,
56                                                 String partitionId) 
57     throws IllegalArgumentException {           
58                 super(servers, topic, apiKey, apiSecret, partitionId);
59         }
60         
61         /**
62          * Instantiation of internal resources
63          */
64         @Override
65         public void init() {    
66                 
67                 this.publisher = 
68                                 new BusPublisher.CambriaPublisherWrapper(this.servers, 
69                                                                                  this.topic, 
70                                                                                  this.apiKey, 
71                                                                                  this.apiSecret);
72                 if (logger.isInfoEnabled())
73                         logger.info("UEB SINK TOPIC created " + this);
74         }
75         
76         @Override
77         public String toString() {
78                 StringBuilder builder = new StringBuilder();
79                 builder.append("InlineUebTopicSink [getTopicCommInfrastructure()=").append(getTopicCommInfrastructure())
80                                 .append(", toString()=").append(super.toString()).append("]");
81                 return builder.toString();
82         }
83
84         /**
85          * {@inheritDoc}
86          */
87         @Override
88         public CommInfrastructure getTopicCommInfrastructure() {
89                 return Topic.CommInfrastructure.UEB;
90         }
91 }