Skip to content

Commit

Permalink
fix: make BulkWriterOptions public (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Chen committed Jan 20, 2021
1 parent 0e6f3da commit 6ea05be
Showing 1 changed file with 16 additions and 14 deletions.
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

0 comments on commit 6ea05be

Please sign in to comment.