blob: aeb018d4e607281f3b43bd482c5ed4a603c84df4 [file] [log] [blame]
Ray Milkey2d572dd2017-04-14 10:01:24 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Shravan Ambati5a11e172016-07-21 15:55:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.kafkaintegration.api.dto;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20/**
21 * DTO to hold Kafka Server Configuration information.
22 *
23 */
24public final class KafkaServerConfig {
25
26 private final String ipAddress;
27
28 private final String port;
29
30 private final int numOfRetries;
31
32 private final int maxInFlightRequestsPerConnection;
33
34 private final int acksRequired;
35
36 private final String keySerializer;
37
38 private final String valueSerializer;
39
40 private KafkaServerConfig(String ipAddress, String port, int numOfRetries,
41 int maxInFlightRequestsPerConnection,
42 int requestRequiredAcks, String keySerializer,
43 String valueSerializer) {
44
45 this.ipAddress = checkNotNull(ipAddress, "Ip Address Cannot be null");
46 this.port = checkNotNull(port, "Port Number cannot be null");
47 this.numOfRetries = numOfRetries;
48 this.maxInFlightRequestsPerConnection =
49 maxInFlightRequestsPerConnection;
50 this.acksRequired = requestRequiredAcks;
51 this.keySerializer = keySerializer;
52 this.valueSerializer = valueSerializer;
53 }
54
55 public final String getIpAddress() {
56 return ipAddress;
57 }
58
59 public final String getPort() {
60 return port;
61 }
62
63 public final int getNumOfRetries() {
64 return numOfRetries;
65 }
66
67 public final int getMaxInFlightRequestsPerConnection() {
68 return maxInFlightRequestsPerConnection;
69 }
70
71 public final int getAcksRequired() {
72 return acksRequired;
73 }
74
75 public final String getKeySerializer() {
76 return keySerializer;
77 }
78
79 public final String getValueSerializer() {
80 return valueSerializer;
81 }
82
83 /**
84 * To create an instance of the builder.
85 *
86 * @return instance of builder
87 */
88 public static Builder builder() {
89 return new Builder();
90 }
91
92 /**
93 * Builder class for KafkaServerConfig.
94 */
95 public static final class Builder {
96 private String ipAddress;
97
98 private String port;
99
100 private int numOfRetries;
101
102 private int maxInFlightRequestsPerConnection;
103
104 private int acksRequired;
105
106 private String keySerializer;
107
108 private String valueSerializer;
109
110 public Builder ipAddress(String ipAddress) {
111 this.ipAddress = ipAddress;
112 return this;
113 }
114
115 public Builder port(String port) {
116 this.port = port;
117 return this;
118 }
119
120 public Builder numOfRetries(int numOfRetries) {
121 this.numOfRetries = numOfRetries;
122 return this;
123 }
124
125 public Builder maxInFlightRequestsPerConnection(int maxInFlightRequestsPerConnection) {
126 this.maxInFlightRequestsPerConnection =
127 maxInFlightRequestsPerConnection;
128 return this;
129 }
130
131 public Builder acksRequired(int acksRequired) {
132 this.acksRequired = acksRequired;
133 return this;
134 }
135
136 public Builder keySerializer(String keySerializer) {
137 this.keySerializer = keySerializer;
138 return this;
139 }
140
141 public Builder valueSerializer(String valueSerializer) {
142 this.valueSerializer = valueSerializer;
143 return this;
144 }
145
146 public KafkaServerConfig build() {
147 checkNotNull(ipAddress, "App name cannot be null");
148 checkNotNull(port, "Subscriber group ID cannot " + "be " + "null");
149
150 return new KafkaServerConfig(ipAddress, port, numOfRetries,
151 maxInFlightRequestsPerConnection,
152 acksRequired, keySerializer,
153 valueSerializer);
154 }
155 }
156}