e36e3afc1477b4087d021797e483d2716b1cc9ad
[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
27 import org.openecomp.policy.drools.event.comm.Topic;
28 import org.openecomp.policy.drools.event.comm.bus.BusTopic;
29
30 public abstract class BusTopicBase implements BusTopic, Topic {
31         
32         protected List<String> servers;
33
34         protected String topic;
35         
36         protected String apiKey;
37         protected String apiSecret;
38         
39         protected CircularFifoQueue<String> recentEvents = new CircularFifoQueue<String>(10);
40         
41         public BusTopicBase(List<String> servers, 
42                                                   String topic, 
43                                                   String apiKey, 
44                                                   String apiSecret) 
45         throws IllegalArgumentException {
46                 
47                 if (servers == null || servers.isEmpty()) {
48                         throw new IllegalArgumentException("UEB Server(s) must be provided");
49                 }
50                 
51                 if (topic == null || topic.isEmpty()) {
52                         throw new IllegalArgumentException("An UEB Topic must be provided");
53                 }
54                 
55                 this.servers = servers;
56                 this.topic = topic;
57                 
58                 this.apiKey = apiKey;
59                 this.apiSecret = apiSecret;
60         }
61         
62         /**
63          * {@inheritDoc}
64          */
65         @Override
66         public String getTopic() {
67                 return topic;
68         }
69         
70         /**
71          * {@inheritDoc}
72          */
73         @Override
74         public List<String> getServers() {
75                 return servers;
76         }
77         
78         /**
79          * {@inheritDoc}
80          */
81         @Override
82         public String getApiKey() {
83                 return apiKey;
84         }
85
86         /**
87          * {@inheritDoc}
88          */
89         @Override
90         public String getApiSecret() {
91                 return apiSecret;
92         }
93         
94         /**
95          * @return the recentEvents
96          */
97         @Override
98         public synchronized String[] getRecentEvents() {
99                 String[] events = new String[recentEvents.size()];
100                 return recentEvents.toArray(events);
101         }
102
103
104         @Override
105         public String toString() {
106                 StringBuilder builder = new StringBuilder();
107                 builder.append("UebTopicBase [servers=").append(servers).append(", topic=").append(topic).append(", apiKey=")
108                                 .append(apiKey).append(", apiSecret=").append(apiSecret).append("]");
109                 return builder.toString();
110         }
111
112 }