2 * ===============================LICENSE_START======================================
4 * ================================================================================
5 * Copyright © 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===========================================
21 package org.onap.dcae.apod.analytics.dmaap.domain.config;
23 import com.google.common.base.Objects;
24 import org.onap.dcae.apod.analytics.common.AnalyticsConstants;
26 import javax.annotation.Nonnull;
30 * Immutable DMaaP MR Configuration for DMaaP MR Publisher.
32 * Use {@link DMaaPMRPublisherConfig.Builder} to construct Subscriber Configuration
35 * @author Rajiv Singla . Creation Date: 10/12/2016.
37 public class DMaaPMRPublisherConfig extends DMaaPMRBaseConfig {
40 * Publisher batching queue size
42 private int maxBatchSize;
45 * Publisher Recovery Queue Size
47 private int maxRecoveryQueueSize;
50 private DMaaPMRPublisherConfig(@Nonnull String hostName,
51 @Nonnull Integer portNumber,
52 @Nonnull String topicName,
53 @Nonnull String protocol,
56 @Nonnull String contentType,
58 int maxRecoveryQueueSize) {
59 this.hostName = hostName;
60 this.portNumber = portNumber;
61 this.topicName = topicName;
62 this.protocol = protocol;
63 this.userName = userName;
64 this.userPassword = userPassword;
65 this.contentType = contentType;
66 this.maxBatchSize = maxBatchSize;
67 this.maxRecoveryQueueSize = maxRecoveryQueueSize;
72 * Builder to initialize immutable {@link DMaaPMRPublisherConfig} object
74 public static class Builder {
76 private String hostName;
77 private Integer portNumber;
78 private String topicName;
79 private String userName;
80 private String userPassword;
81 private String protocol;
82 private String contentType;
83 private int maxBatchSize;
84 private int maxRecoveryQueueSize;
86 public Builder(@Nonnull String hostName, @Nonnull String topicName) {
88 this.hostName = hostName;
89 this.topicName = topicName;
91 this.portNumber = AnalyticsConstants.DEFAULT_PORT_NUMBER;
92 this.userName = AnalyticsConstants.DEFAULT_USER_NAME;
93 this.userPassword = AnalyticsConstants.DEFAULT_USER_PASSWORD;
94 this.protocol = AnalyticsConstants.DEFAULT_PROTOCOL;
95 this.contentType = AnalyticsConstants.DEFAULT_CONTENT_TYPE;
96 this.maxBatchSize = AnalyticsConstants.DEFAULT_PUBLISHER_MAX_BATCH_SIZE;
97 this.maxRecoveryQueueSize = AnalyticsConstants.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE;
101 * Setup for custom host port number - Defaults to 80.
103 * @param portNumber custom port number
104 * @return Builder object itself for chaining
106 public Builder setPortNumber(@Nonnull Integer portNumber) {
107 this.portNumber = portNumber;
113 * Setup user name for authentication. If no username is provided authentication will be disabled
115 * @param userName user name for DMaaP Topic Authentication
116 * @return Builder object itself for chaining
118 public Builder setUserName(@Nonnull String userName) {
119 this.userName = userName;
125 * Setup user password for authentication. If no password is provided authentication will be disabled
127 * @param userPassword user password for DMaaP Topic Authentication
128 * @return Builder object itself for chaining
130 public Builder setUserPassword(@Nonnull String userPassword) {
131 this.userPassword = userPassword;
137 * Setup custom Publisher protocol - Defaults to https.
138 * Note: Only http and https are currently supported.
140 * @param protocol protocol e.g. https
141 * @return Builder object itself for chaining
143 public Builder setProtocol(@Nonnull String protocol) {
144 this.protocol = normalizeValidateProtocol(protocol);
150 * Setup custom Publisher content-type - Defaults to application/json
152 * @param contentType content type e.g. application/json
153 * @return Builder object itself for chaining
155 public Builder setContentType(@Nonnull String contentType) {
156 final String normalizedContentType = normalizeValidateContentType(contentType);
157 this.contentType = normalizedContentType;
163 * Setup custom Publisher Max Batch Size - Defaults to 100
165 * @param maxBatchSize max Batch Size
166 * @return Builder object itself for chaining
168 public Builder setMaxBatchSize(int maxBatchSize) {
169 this.maxBatchSize = maxBatchSize;
175 * Setup custom Maximum Recovery Queue Size. Recovery Queue is used to hold messages temporarily in case
176 * DMaaP MR Publisher topic is not responding for any reason. Defaults to 100,000
178 * @param maxRecoveryQueueSize max recovery queue size
179 * @return Builder object itself for chaining
181 public Builder setMaxRecoveryQueueSize(int maxRecoveryQueueSize) {
182 this.maxRecoveryQueueSize = maxRecoveryQueueSize;
187 * Creates immutable instance of {@link DMaaPMRPublisherConfig}
189 * @return Builds and returns thread safe, immutable {@link DMaaPMRPublisherConfig} object
191 public DMaaPMRPublisherConfig build() {
192 return new DMaaPMRPublisherConfig(hostName, portNumber, topicName, protocol, userName, userPassword,
193 contentType, maxBatchSize, maxRecoveryQueueSize);
200 * Returns max Publisher Batch Queue Size
202 * @return max Publisher Batch Queue size
204 public int getMaxBatchSize() {
209 * Returns max Publisher Recovery Queue Size
211 * @return max Recovery Queue size
213 public int getMaxRecoveryQueueSize() {
214 return maxRecoveryQueueSize;
219 public boolean equals(Object o) {
223 if (o == null || getClass() != o.getClass()) {
226 if (!super.equals(o)) {
229 DMaaPMRPublisherConfig that = (DMaaPMRPublisherConfig) o;
230 return maxBatchSize == that.maxBatchSize &&
231 maxRecoveryQueueSize == that.maxRecoveryQueueSize;
235 public int hashCode() {
236 return Objects.hashCode(super.hashCode(), maxBatchSize, maxRecoveryQueueSize);
241 public String toString() {
242 return Objects.toStringHelper(this)
243 .add("baseConfig", super.toString())
244 .add("maxBatchSize", maxBatchSize)
245 .add("maxRecoveryQueueSize", maxRecoveryQueueSize)