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(Builder builder) {
51 this.hostName = builder.hostName;
52 this.portNumber = builder.portNumber;
53 this.topicName = builder.topicName;
54 this.protocol = builder.protocol;
55 this.userName = builder.userName;
56 this.userPassword = builder.userPassword;
57 this.contentType = builder.contentType;
58 this.maxBatchSize = builder.maxBatchSize;
59 this.maxRecoveryQueueSize = builder.maxRecoveryQueueSize;
64 * Builder to initialize immutable {@link DMaaPMRPublisherConfig} object
66 public static class Builder {
68 private String hostName;
69 private Integer portNumber;
70 private String topicName;
71 private String userName;
72 private String userPassword;
73 private String protocol;
74 private String contentType;
75 private int maxBatchSize;
76 private int maxRecoveryQueueSize;
78 public Builder(@Nonnull String hostName, @Nonnull String topicName) {
80 this.hostName = hostName;
81 this.topicName = topicName;
83 this.portNumber = AnalyticsConstants.DEFAULT_PORT_NUMBER;
84 this.userName = AnalyticsConstants.DEFAULT_USER_NAME;
85 this.userPassword = AnalyticsConstants.DEFAULT_USER_PASSWORD;
86 this.protocol = AnalyticsConstants.DEFAULT_PROTOCOL;
87 this.contentType = AnalyticsConstants.DEFAULT_CONTENT_TYPE;
88 this.maxBatchSize = AnalyticsConstants.DEFAULT_PUBLISHER_MAX_BATCH_SIZE;
89 this.maxRecoveryQueueSize = AnalyticsConstants.DEFAULT_PUBLISHER_MAX_RECOVERY_QUEUE_SIZE;
93 * Setup for custom host port number - Defaults to 80.
95 * @param portNumber custom port number
96 * @return Builder object itself for chaining
98 public Builder setPortNumber(@Nonnull Integer portNumber) {
99 this.portNumber = portNumber;
105 * Setup user name for authentication. If no username is provided authentication will be disabled
107 * @param userName user name for DMaaP Topic Authentication
108 * @return Builder object itself for chaining
110 public Builder setUserName(@Nonnull String userName) {
111 this.userName = userName;
117 * Setup user password for authentication. If no password is provided authentication will be disabled
119 * @param userPassword user password for DMaaP Topic Authentication
120 * @return Builder object itself for chaining
122 public Builder setUserPassword(@Nonnull String userPassword) {
123 this.userPassword = userPassword;
129 * Setup custom Publisher protocol - Defaults to https.
130 * Note: Only http and https are currently supported.
132 * @param protocol protocol e.g. https
133 * @return Builder object itself for chaining
135 public Builder setProtocol(@Nonnull String protocol) {
136 this.protocol = normalizeValidateProtocol(protocol);
142 * Setup custom Publisher content-type - Defaults to application/json
144 * @param contentType content type e.g. application/json
145 * @return Builder object itself for chaining
147 public Builder setContentType(@Nonnull String contentType) {
148 final String normalizedContentType = normalizeValidateContentType(contentType);
149 this.contentType = normalizedContentType;
155 * Setup custom Publisher Max Batch Size - Defaults to 100
157 * @param maxBatchSize max Batch Size
158 * @return Builder object itself for chaining
160 public Builder setMaxBatchSize(int maxBatchSize) {
161 this.maxBatchSize = maxBatchSize;
167 * Setup custom Maximum Recovery Queue Size. Recovery Queue is used to hold messages temporarily in case
168 * DMaaP MR Publisher topic is not responding for any reason. Defaults to 100,000
170 * @param maxRecoveryQueueSize max recovery queue size
171 * @return Builder object itself for chaining
173 public Builder setMaxRecoveryQueueSize(int maxRecoveryQueueSize) {
174 this.maxRecoveryQueueSize = maxRecoveryQueueSize;
179 * Creates immutable instance of {@link DMaaPMRPublisherConfig}
181 * @return Builds and returns thread safe, immutable {@link DMaaPMRPublisherConfig} object
183 public DMaaPMRPublisherConfig build() {
184 return new DMaaPMRPublisherConfig(this);
191 * Returns max Publisher Batch Queue Size
193 * @return max Publisher Batch Queue size
195 public int getMaxBatchSize() {
200 * Returns max Publisher Recovery Queue Size
202 * @return max Recovery Queue size
204 public int getMaxRecoveryQueueSize() {
205 return maxRecoveryQueueSize;
210 public boolean equals(Object o) {
214 if (o == null || getClass() != o.getClass()) {
217 if (!super.equals(o)) {
220 DMaaPMRPublisherConfig that = (DMaaPMRPublisherConfig) o;
221 return maxBatchSize == that.maxBatchSize &&
222 maxRecoveryQueueSize == that.maxRecoveryQueueSize;
226 public int hashCode() {
227 return Objects.hashCode(super.hashCode(), maxBatchSize, maxRecoveryQueueSize);
232 public String toString() {
233 return Objects.toStringHelper(this)
234 .add("baseConfig", super.toString())
235 .add("maxBatchSize", maxBatchSize)
236 .add("maxRecoveryQueueSize", maxRecoveryQueueSize)