417c6d472b7308f7c3625e8ebba3f2f6cd7a93ea
[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.DmaapTopicSink;
27 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
28 import org.openecomp.policy.common.logging.flexlogger.Logger;
29
30 /**
31  * This implementation publishes events for the associated DMAAP topic,
32  * inline with the calling thread.
33  */
34 public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTopicSink {
35         
36         protected static Logger logger = 
37                         FlexLogger.getLogger(InlineDmaapTopicSink.class);
38         
39         protected final String userName;
40         protected final String password;
41         
42         public InlineDmaapTopicSink(List<String> servers, String topic, 
43                                             String apiKey, String apiSecret,
44                                     String userName, String password,
45                                             String partitionKey) 
46                 throws IllegalArgumentException {
47                 
48                 super(servers, topic, apiKey, apiSecret, partitionKey);
49                 
50                 this.userName = userName;
51                 this.password = password;
52         }
53         
54
55         @Override
56         public void init() {
57                 this.publisher = 
58                                 new BusPublisher.DmaapPublisherWrapper(this.servers, 
59                                                                                this.topic, 
60                                                                                this.userName, 
61                                                                                this.password);
62                 if (logger.isInfoEnabled())
63                         logger.info("DMAAP SINK TOPIC created " + this);
64         }
65
66         /**
67          * {@inheritDoc}
68          */
69         @Override
70         public CommInfrastructure getTopicCommInfrastructure() {
71                 return Topic.CommInfrastructure.DMAAP;
72         }
73
74
75         @Override
76         public String toString() {
77                 StringBuilder builder = new StringBuilder();
78                 builder.append("InlineDmaapTopicSink [userName=").append(userName).append(", password=").append(password)
79                                 .append(", getTopicCommInfrastructure()=").append(getTopicCommInfrastructure()).append(", toString()=")
80                                 .append(super.toString()).append("]");
81                 return builder.toString();
82         }
83
84 }