-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
679 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
vertx-grpc-client/src/main/java/io/vertx/grpc/client/GrpcClientOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
/* | ||
* Copyright (c) 2011-2024 Contributors to the Eclipse Foundation | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
* which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
*/ | ||
package io.vertx.grpc.client; | ||
|
||
import io.vertx.codegen.annotations.DataObject; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Options configuring a gRPC client. | ||
*/ | ||
@DataObject | ||
public class GrpcClientOptions { | ||
|
||
/** | ||
* The default value for automatic deadline schedule = {@code false}. | ||
*/ | ||
public static final boolean DEFAULT_SCHEDULE_DEADLINE_AUTOMATICALLY = false; | ||
|
||
/** | ||
* The default value of the timeout = {@code 0} (no timeout). | ||
*/ | ||
public static final int DEFAULT_TIMEOUT = 0; | ||
|
||
/** | ||
* The default value of the timeout unit = {@link TimeUnit#SECONDS}. | ||
*/ | ||
public static final TimeUnit DEFAULT_TIMEOUT_UNIT = TimeUnit.SECONDS; | ||
|
||
private boolean scheduleDeadlineAutomatically; | ||
private int timeout; | ||
private TimeUnit timeoutUnit; | ||
|
||
/** | ||
* Default constructor. | ||
*/ | ||
public GrpcClientOptions() { | ||
scheduleDeadlineAutomatically = DEFAULT_SCHEDULE_DEADLINE_AUTOMATICALLY; | ||
timeout = DEFAULT_TIMEOUT; | ||
timeoutUnit = DEFAULT_TIMEOUT_UNIT; | ||
} | ||
|
||
/** | ||
* Copy constructor. | ||
* | ||
* @param other the options to copy | ||
*/ | ||
public GrpcClientOptions(GrpcClientOptions other) { | ||
scheduleDeadlineAutomatically = other.scheduleDeadlineAutomatically; | ||
timeout = other.timeout; | ||
timeoutUnit = other.timeoutUnit; | ||
} | ||
|
||
/** | ||
* @return whether the client will automatically schedule a deadline when a request carrying a timeout is sent. | ||
*/ | ||
public boolean getScheduleDeadlineAutomatically() { | ||
return scheduleDeadlineAutomatically; | ||
} | ||
|
||
/** | ||
* <p>Set whether a deadline is automatically scheduled when a request carrying a timeout (either set explicitly or through this | ||
* options instance) is sent.</p> | ||
* | ||
* <ul> | ||
* <li>When the automatic deadline is set and a request carrying a timeout is sent, a deadline (timer) is created to cancel the request | ||
* when the response has not been timely received. The deadline can be obtained with {@link GrpcClientRequest#deadline()}.</li> | ||
* <li>When the deadline is not set and a request carrying a timeout is sent, the timeout is sent to the server and it remains the | ||
* responsibility of the caller to eventually cancel the request. Note: the server might cancel the request as well when its local deadline is met.</li> | ||
* </ul> | ||
* | ||
* @param handleDeadlineAutomatically whether to automatically set | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
public GrpcClientOptions setScheduleDeadlineAutomatically(boolean handleDeadlineAutomatically) { | ||
this.scheduleDeadlineAutomatically = handleDeadlineAutomatically; | ||
return this; | ||
} | ||
|
||
/** | ||
* Return the default timeout set when sending gRPC requests, the initial value is {@code 0} which does not | ||
* send a timeout. | ||
* | ||
* @return the default timeout. | ||
*/ | ||
public int getTimeout() { | ||
return timeout; | ||
} | ||
|
||
/** | ||
* Set the default timeout set when sending gRPC requests, this value should be set along with {@link #setTimeoutUnit(TimeUnit)}. | ||
* | ||
* @param timeout the timeout value | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
public GrpcClientOptions setTimeout(int timeout) { | ||
if (timeout < 0L) { | ||
throw new IllegalArgumentException("Timeout value must be >= 0"); | ||
} | ||
this.timeout = timeout; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return the unit of time of the default timeout. | ||
*/ | ||
public TimeUnit getTimeoutUnit() { | ||
return timeoutUnit; | ||
} | ||
|
||
/** | ||
* Set the unit of time of the default timeout value. | ||
* | ||
* @param timeoutUnit the unit of time | ||
* @return a reference to this, so the API can be used fluently | ||
*/ | ||
public GrpcClientOptions setTimeoutUnit(TimeUnit timeoutUnit) { | ||
this.timeoutUnit = Objects.requireNonNull(timeoutUnit); | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.