4ac1c6fc250c4595aa4099cbaff2fc791e92f35c
[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.apache.commons.collections4.queue.CircularFifoQueue;
26 import org.openecomp.policy.drools.event.comm.Topic;
27 import org.openecomp.policy.drools.event.comm.bus.BusTopic;
28
29 public abstract class BusTopicBase implements BusTopic, Topic {
30         
31         protected List<String> servers;
32
33         protected String topic;
34         
35         protected String apiKey;
36         protected String apiSecret;
37         protected boolean useHttps;
38         protected boolean allowSelfSignedCerts;
39         
40         protected CircularFifoQueue<String> recentEvents = new CircularFifoQueue<String>(10);
41         
42         /**
43          * Instantiates a new Bus Topic Base
44          * 
45          * @param servers list of servers
46          * @param topic topic name
47          * @param apiKey API Key
48          * @param apiSecret API Secret
49          * @param useHttps does connection use HTTPS?
50          * @param allowSelfSignedCerts are self-signed certificates allow
51          *  
52          * @return a Bus Topic Base
53          * @throws IllegalArgumentException if invalid parameters are present
54          */
55         public BusTopicBase(List<String> servers, 
56                                                   String topic, 
57                                                   String apiKey, 
58                                                   String apiSecret,
59                                                   boolean useHttps,
60                                                   boolean allowSelfSignedCerts) 
61         throws IllegalArgumentException {
62                 
63                 if (servers == null || servers.isEmpty()) {
64                         throw new IllegalArgumentException("UEB Server(s) must be provided");
65                 }
66                 
67                 if (topic == null || topic.isEmpty()) {
68                         throw new IllegalArgumentException("An UEB Topic must be provided");
69                 }
70                 
71                 this.servers = servers;
72                 this.topic = topic;
73                 
74                 this.apiKey = apiKey;
75                 this.apiSecret = apiSecret;
76                 this.useHttps = useHttps;
77                 this.allowSelfSignedCerts = allowSelfSignedCerts;
78         }
79         
80         /**
81          * {@inheritDoc}
82          */
83         @Override
84         public String getTopic() {
85                 return topic;
86         }
87         
88         /**
89          * {@inheritDoc}
90          */
91         @Override
92         public List<String> getServers() {
93                 return servers;
94         }
95         
96         /**
97          * {@inheritDoc}
98          */
99         @Override
100         public String getApiKey() {
101                 return apiKey;
102         }
103
104         /**
105          * {@inheritDoc}
106          */
107         @Override
108         public String getApiSecret() {
109                 return apiSecret;
110         }
111         
112         /**
113          * @return useHttps
114          */
115         public boolean isUseHttps(){
116                 return useHttps;
117         }
118
119         /**
120          * @return allowSelfSignedCerts
121          */
122         public boolean isAllowSelfSignedCerts(){
123                 return allowSelfSignedCerts;
124         }
125         
126         /**
127          * @return the recentEvents
128          */
129         @Override
130         public synchronized String[] getRecentEvents() {
131                 String[] events = new String[recentEvents.size()];
132                 return recentEvents.toArray(events);
133         }
134
135
136         @Override
137         public String toString() {
138                 StringBuilder builder = new StringBuilder();
139                 builder.append("UebTopicBase [servers=").append(servers)
140                         .append(", topic=").append(topic)
141                         .append(", apiKey=").append(apiKey)
142                         .append(", apiSecret=").append(apiSecret)
143                         .append(", useHttps=").append(useHttps)
144                         .append(", allowSelfSignedCerts=").append(allowSelfSignedCerts)
145                         .append("]");
146                 return builder.toString();
147         }
148
149 }