3737/**
3838 * The collection of runtime options for a new RPC call.
3939 */
40- public final class GrpcCallOption {
40+ public final class GrpcCallOptions {
4141
4242 private final Deadline deadline ;
4343 private final Executor executor ;
4444 private final String compressorName ;
4545 private final Boolean waitForReady ;
4646 private final Integer maxInboundMessageSize ;
4747 private final Integer maxOutboundMessageSize ;
48- private final CallOption [] callOptionCallback ;
48+ private final CallOption [] callOptions ;
4949
50- private GrpcCallOption (@ Nonnull final Builder builder ) {
50+ private GrpcCallOptions (@ Nonnull final Builder builder ) {
5151 this .deadline = builder .deadline ;
5252 this .executor = builder .executor ;
5353 this .compressorName = builder .compressorName ;
5454 this .waitForReady = builder .waitForReady ;
5555 this .maxInboundMessageSize = builder .maxInboundMessageSize ;
5656 this .maxOutboundMessageSize = builder .maxOutboundMessageSize ;
57- this .callOptionCallback = builder .callOptions .toArray (new CallOption [0 ]);
57+ this .callOptions = builder .callOptions .toArray (new CallOption [0 ]);
5858 }
5959
6060 /**
@@ -124,16 +124,16 @@ public Integer getMaxOutboundMessageSize() {
124124 * @return the CallOption list
125125 */
126126 @ Nonnull
127- public CallOption [] getCallOptionCallback () {
128- return callOptionCallback ;
127+ public CallOption [] getCallOptions () {
128+ return callOptions ;
129129 }
130130
131131 @ Override
132132 public boolean equals (final Object o ) {
133133 if (o == null || getClass () != o .getClass ()) {
134134 return false ;
135135 }
136- GrpcCallOption that = (GrpcCallOption ) o ;
136+ GrpcCallOptions that = (GrpcCallOptions ) o ;
137137 return Objects .equals (deadline , that .deadline )
138138 && Objects .equals (executor , that .executor )
139139 && Objects .equals (compressorName , that .compressorName )
@@ -174,7 +174,7 @@ public static final class Builder {
174174 private Executor executor ;
175175 private String compressorName ;
176176 private Boolean waitForReady ;
177- private Integer maxInboundMessageSize ;
177+ private Integer maxInboundMessageSize = Integer . MAX_VALUE ;
178178 private Integer maxOutboundMessageSize ;
179179 private final List <CallOption > callOptions = new ArrayList <>();
180180
@@ -184,14 +184,7 @@ public static final class Builder {
184184 * @return this
185185 */
186186 public Builder withDeadline (final @ Nonnull Deadline deadline ) {
187- var callOption = new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
188- @ Override
189- public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
190- return stub .withDeadline (deadline );
191- }
192- };
193187 this .deadline = deadline ;
194- callOptions .add (callOption );
195188 return this ;
196189 }
197190
@@ -202,14 +195,7 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
202195 * @return this
203196 */
204197 public Builder withExecutor (@ Nonnull final Executor executor ) {
205- var callOption = new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
206- @ Override
207- public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
208- return stub .withExecutor (executor );
209- }
210- };
211198 this .executor = executor ;
212- callOptions .add (callOption );
213199 return this ;
214200 }
215201
@@ -224,14 +210,7 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
224210 * @return this
225211 */
226212 public Builder withCompressorName (@ Nonnull final String compressorName ) {
227- var callOption = new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
228- @ Override
229- public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
230- return stub .withCompression (compressorName );
231- }
232- };
233213 this .compressorName = compressorName ;
234- callOptions .add (callOption );
235214 return this ;
236215 }
237216
@@ -244,14 +223,7 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
244223 * @return this
245224 */
246225 public Builder withWaitForReady () {
247- var callOption = new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
248- @ Override
249- public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
250- return stub .withWaitForReady ();
251- }
252- };
253226 this .waitForReady = true ;
254- callOptions .add (callOption );
255227 return this ;
256228 }
257229
@@ -262,14 +234,7 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
262234 * @return this
263235 */
264236 public Builder withMaxInboundMessageSize (@ Nonnull final Integer maxInboundMessageSize ) {
265- var callOption = new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
266- @ Override
267- public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
268- return stub .withMaxInboundMessageSize (maxInboundMessageSize );
269- }
270- };
271237 this .maxInboundMessageSize = maxInboundMessageSize ;
272- callOptions .add (callOption );
273238 return this ;
274239 }
275240
@@ -279,24 +244,106 @@ public <T extends AbstractStub<T>> T wrapStub(final T stub) {
279244 * @return this
280245 */
281246 public Builder withMaxOutboundMessageSize (@ Nonnull final Integer maxOutboundMessageSize ) {
282- var callOption = new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
247+ this .maxOutboundMessageSize = maxOutboundMessageSize ;
248+ return this ;
249+ }
250+
251+ private org .apache .arrow .flight .CallOptions .GrpcCallOption createDeadlineCallOption (
252+ final Deadline deadline ) {
253+ return new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
254+ @ Override
255+ public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
256+ return stub .withDeadline (deadline );
257+ }
258+ };
259+ }
260+
261+ private org .apache .arrow .flight .CallOptions .GrpcCallOption createExecutorCallOption (
262+ final Executor executor ) {
263+ return new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
264+ @ Override
265+ public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
266+ return stub .withExecutor (executor );
267+ }
268+ };
269+ }
270+
271+ private org .apache .arrow .flight .CallOptions .GrpcCallOption createCompressionCallOption (
272+ final String compressorName ) {
273+ return new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
274+ @ Override
275+ public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
276+ return stub .withCompression (compressorName );
277+ }
278+ };
279+ }
280+
281+ private org .apache .arrow .flight .CallOptions .GrpcCallOption createWaitForReadyCallOption () {
282+ return new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
283+ @ Override
284+ public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
285+ return stub .withWaitForReady ();
286+ }
287+ };
288+ }
289+
290+ private org .apache .arrow .flight .CallOptions .GrpcCallOption createMaxInboundMessageSizeCallOption (
291+ final Integer maxInboundMessageSize ) {
292+ return new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
293+ @ Override
294+ public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
295+ return stub .withMaxInboundMessageSize (maxInboundMessageSize );
296+ }
297+ };
298+ }
299+
300+ private org .apache .arrow .flight .CallOptions .GrpcCallOption createMaxOutboundMessageSizeCallOption (
301+ final Integer maxOutboundMessageSize ) {
302+ return new org .apache .arrow .flight .CallOptions .GrpcCallOption () {
283303 @ Override
284304 public <T extends AbstractStub <T >> T wrapStub (final T stub ) {
285305 return stub .withMaxOutboundMessageSize (maxOutboundMessageSize );
286306 }
287307 };
288- this .maxOutboundMessageSize = maxOutboundMessageSize ;
289- callOptions .add (callOption );
290- return this ;
291308 }
292309
293310 /**
294- * Build an instance of GrpcCallOption .
311+ * Build an instance of GrpcCallOptions .
295312 *
296- * @return the GrpcCallOption instance
313+ * @return the GrpcCallOptions instance
297314 */
298- public GrpcCallOption build () {
299- return new GrpcCallOption (this );
315+ public GrpcCallOptions build () {
316+ if (deadline != null ) {
317+ var callOption = createDeadlineCallOption (deadline );
318+ callOptions .add (callOption );
319+ }
320+
321+ if (executor != null ) {
322+ var callOption = createExecutorCallOption (executor );
323+ callOptions .add (callOption );
324+ }
325+
326+ if (compressorName != null ) {
327+ var callOption = createCompressionCallOption (compressorName );
328+ callOptions .add (callOption );
329+ }
330+
331+ if (waitForReady != null ) {
332+ var callOption = createWaitForReadyCallOption ();
333+ callOptions .add (callOption );
334+ }
335+
336+ if (maxInboundMessageSize != null ) {
337+ var callOption = createMaxInboundMessageSizeCallOption (maxInboundMessageSize );
338+ callOptions .add (callOption );
339+ }
340+
341+ if (maxOutboundMessageSize != null ) {
342+ var callOption = createMaxOutboundMessageSizeCallOption (maxOutboundMessageSize );
343+ callOptions .add (callOption );
344+ }
345+
346+ return new GrpcCallOptions (this );
300347 }
301348 }
302349}
0 commit comments