Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make BulkWriterOptions public #502

Merged
merged 1 commit into from Jan 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,26 +19,27 @@
import com.google.api.core.BetaApi;
import com.google.auto.value.AutoValue;
import java.util.concurrent.ScheduledExecutorService;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/** Options used to configure request throttling in BulkWriter. */
@BetaApi
@AutoValue
abstract class BulkWriterOptions {
public abstract class BulkWriterOptions {
/**
* Return whether throttling is enabled.
*
* @return Whether throttling is enabled.
*/
abstract boolean getThrottlingEnabled();
public abstract boolean getThrottlingEnabled();

/**
* Returns the initial maximum number of operations per second allowed by the throttler.
*
* @return The initial maximum number of operations per second allowed by the throttler.
*/
@Nullable
abstract Double getInitialOpsPerSecond();
public abstract Double getInitialOpsPerSecond();

/**
* Returns the maximum number of operations per second allowed by the throttler.
Expand All @@ -49,33 +50,33 @@ abstract class BulkWriterOptions {
* @return The maximum number of operations per second allowed by the throttler.
*/
@Nullable
abstract Double getMaxOpsPerSecond();
public abstract Double getMaxOpsPerSecond();

/**
* @return The {@link ScheduledExecutorService} that BulkWriter uses to schedule all operations.
* If null, the default executor will be used.
*/
@Nullable
abstract ScheduledExecutorService getExecutor();
public abstract ScheduledExecutorService getExecutor();

static Builder builder() {
public static Builder builder() {
return new AutoValue_BulkWriterOptions.Builder()
.setMaxOpsPerSecond(null)
.setInitialOpsPerSecond(null)
.setThrottlingEnabled(true)
.setExecutor(null);
}

abstract Builder toBuilder();
public abstract Builder toBuilder();

@AutoValue.Builder
abstract static class Builder {
public abstract static class Builder {
/**
* Sets whether throttling should be enabled. By default, throttling is enabled.
*
* @param enabled Whether throttling should be enabled.
*/
abstract Builder setThrottlingEnabled(boolean enabled);
public abstract Builder setThrottlingEnabled(boolean enabled);

/**
* Set the initial maximum number of operations per second allowed by the throttler.
Expand All @@ -91,7 +92,7 @@ abstract static class Builder {
* @param initialOpsPerSecond The initial maximum number of operations per second allowed by the
* throttler.
*/
Builder setInitialOpsPerSecond(int initialOpsPerSecond) {
public Builder setInitialOpsPerSecond(int initialOpsPerSecond) {
return setInitialOpsPerSecond(new Double(initialOpsPerSecond));
}

Expand All @@ -111,7 +112,7 @@ Builder setInitialOpsPerSecond(int initialOpsPerSecond) {
* The throttler's allowed operations per second does not ramp up past the specified
* operations per second.
*/
Builder setMaxOpsPerSecond(int maxOpsPerSecond) {
public Builder setMaxOpsPerSecond(int maxOpsPerSecond) {
return setMaxOpsPerSecond(new Double(maxOpsPerSecond));
}

Expand All @@ -120,11 +121,12 @@ Builder setMaxOpsPerSecond(int maxOpsPerSecond) {
*
* @param executor The executor to schedule BulkWriter operations on.
*/
abstract Builder setExecutor(@Nullable ScheduledExecutorService executor);
public abstract Builder setExecutor(@Nullable ScheduledExecutorService executor);

abstract BulkWriterOptions autoBuild();
public abstract BulkWriterOptions autoBuild();

BulkWriterOptions build() {
@Nonnull
public BulkWriterOptions build() {
BulkWriterOptions options = autoBuild();
Double initialRate = options.getInitialOpsPerSecond();
Double maxRate = options.getMaxOpsPerSecond();
Expand Down