.setDelayThreshold(Duration.ofMillis(10)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build())
builder .flowControlSettings .toBuilder() .setLimitExceededBehavior(LimitExceededBehavior.ThrowException) .build());
public FlowController(FlowControlSettings settings) { boolean failOnLimits; switch (settings.getLimitExceededBehavior()) { case ThrowException: case Block: default: throw new IllegalArgumentException( "Unknown LimitBehaviour: " + settings.getLimitExceededBehavior()); this.maxOutstandingElementCount = settings.getMaxOutstandingElementCount(); if (maxOutstandingElementCount == null) { outstandingElementCount = null; } else if (settings.getLimitExceededBehavior() == FlowController.LimitExceededBehavior.Block) { outstandingElementCount = new BlockingSemaphore(maxOutstandingElementCount); } else { this.maxOutstandingRequestBytes = settings.getMaxOutstandingRequestBytes(); if (maxOutstandingRequestBytes == null) { outstandingByteCount = null; } else if (settings.getLimitExceededBehavior() == FlowController.LimitExceededBehavior.Block) { outstandingByteCount = new BlockingSemaphore(maxOutstandingRequestBytes); } else {
public FlowControlSettings build() { FlowControlSettings settings = autoBuild(); Preconditions.checkArgument( settings.getMaxOutstandingElementCount() == null || settings.getMaxOutstandingElementCount() > 0, "maxOutstandingElementCount limit is disabled by default, but if set it must be set to a value greater than 0."); Preconditions.checkArgument( settings.getMaxOutstandingRequestBytes() == null || settings.getMaxOutstandingRequestBytes() > 0, "maxOutstandingRequestBytes limit is disabled by default, but if set it must be set to a value greater than 0."); return settings; } }
public FlowController(FlowControlSettings settings) { boolean failOnLimits; switch (settings.getLimitExceededBehavior()) { case ThrowException: case Block: default: throw new IllegalArgumentException( "Unknown LimitBehaviour: " + settings.getLimitExceededBehavior()); this.maxOutstandingElementCount = settings.getMaxOutstandingElementCount(); if (maxOutstandingElementCount == null) { outstandingElementCount = null; } else if (settings.getLimitExceededBehavior() == FlowController.LimitExceededBehavior.Block) { outstandingElementCount = new BlockingSemaphore(maxOutstandingElementCount); } else { this.maxOutstandingRequestBytes = settings.getMaxOutstandingRequestBytes(); if (maxOutstandingRequestBytes == null) { outstandingByteCount = null; } else if (settings.getLimitExceededBehavior() == FlowController.LimitExceededBehavior.Block) { outstandingByteCount = new BlockingSemaphore(maxOutstandingRequestBytes); } else {
public FlowControlSettings build() { FlowControlSettings settings = autoBuild(); Preconditions.checkArgument( settings.getMaxOutstandingElementCount() == null || settings.getMaxOutstandingElementCount() > 0, "maxOutstandingElementCount limit is disabled by default, but if set it must be set to a value greater than 0."); Preconditions.checkArgument( settings.getMaxOutstandingRequestBytes() == null || settings.getMaxOutstandingRequestBytes() > 0, "maxOutstandingRequestBytes limit is disabled by default, but if set it must be set to a value greater than 0."); return settings; } }
.setDelayThreshold(Duration.ofMillis(50)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100000L) .setMaxOutstandingRequestBytes(10485760L)
oldBatchSettings .getFlowControlSettings() .toBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Block) .build())
flowController = new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(1L) .setLimitExceededBehavior(FlowController.LimitExceededBehavior.ThrowException)
oldBatchSettings .getFlowControlSettings() .toBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Block) .build())
public static FlowControlSettings getDefaultInstance() { return FlowControlSettings.newBuilder().build(); }
public static FlowControlSettings getDefaultInstance() { return FlowControlSettings.newBuilder().build(); }
private FlowControlSettings buildFlowControlSettings( GcpPubSubProperties.FlowControl flowControl) { FlowControlSettings.Builder builder = FlowControlSettings.newBuilder(); return ifNotNull(flowControl.getLimitExceededBehavior(), builder::setLimitExceededBehavior) .apply(ifNotNull(flowControl.getMaxOutstandingElementCount(), builder::setMaxOutstandingElementCount) .apply(ifNotNull(flowControl.getMaxOutstandingRequestBytes(), builder::setMaxOutstandingRequestBytes) .apply(false))) ? builder.build() : null; }
private static FlowController getDisabledFlowController() { return new FlowController( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build()); }
/** Get a new builder. */ public static Builder newBuilder() { return new AutoValue_BatchingSettings.Builder() .setIsEnabled(true) .setElementCountThreshold(1L) .setRequestByteThreshold(1L) .setDelayThreshold(Duration.ofMillis(1)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build()); }
.setDelayThreshold(Duration.ofMillis(50)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(100000L) .setMaxOutstandingRequestBytes(10485760L)
/** Get a new builder. */ public static Builder newBuilder() { return new AutoValue_BatchingSettings.Builder() .setIsEnabled(true) .setElementCountThreshold(1L) .setRequestByteThreshold(1L) .setDelayThreshold(Duration.ofMillis(1)) .setFlowControlSettings( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Ignore) .build()); }
@Test public void testReserveRelease_rejectedByNumberOfBytes_noElementCountLimit() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingRequestBytes(10L) .setLimitExceededBehavior(LimitExceededBehavior.ThrowException) .build()); testRejectedReserveRelease( flowController, 10, 10, FlowController.MaxOutstandingRequestBytesReachedException.class); }
@Test public void testReserveRelease_noLimits_ok() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setLimitExceededBehavior(LimitExceededBehavior.Block) .build()); flowController.reserve(1, 1); flowController.release(1, 1); }
@Test public void testReserveRelease_blockedByElementCount_noBytesLimit() throws Exception { FlowController flowController = new FlowController( FlowControlSettings.newBuilder() .setMaxOutstandingElementCount(10L) .setLimitExceededBehavior(LimitExceededBehavior.Block) .build()); testBlockingReserveRelease(flowController, 10, 10); }