/** Configures the Publisher's retry parameters. */ public Builder setRetrySettings(RetrySettings retrySettings) { Preconditions.checkArgument( retrySettings.getTotalTimeout().compareTo(MIN_TOTAL_TIMEOUT) >= 0); Preconditions.checkArgument( retrySettings.getInitialRpcTimeout().compareTo(MIN_RPC_TIMEOUT) >= 0); this.retrySettings = retrySettings; return this; }
/** * Set acknowledgement expiration padding. * * <p>This is the time accounted before a message expiration is to happen, so the {@link * Subscriber} is able to send an ack extension beforehand. * * <p>This padding duration is configurable so you can account for network latency. A reasonable * number must be provided so messages don't expire because of network latency between when the * ack extension is required and when it reaches the Pub/Sub service. * * @param ackExpirationPadding must be greater or equal to {@link #MIN_ACK_EXPIRATION_PADDING} */ @InternalApi Builder setAckExpirationPadding(Duration ackExpirationPadding) { Preconditions.checkArgument(ackExpirationPadding.compareTo(MIN_ACK_EXPIRATION_PADDING) >= 0); this.ackExpirationPadding = ackExpirationPadding; return this; }
/** * This method simply calls {@link Thread#sleep(long)}. * * @param delay time to sleep * @throws InterruptedException if any thread has interrupted the current thread */ protected void sleep(Duration delay) throws InterruptedException { if (Duration.ZERO.compareTo(delay) < 0) { Thread.sleep(delay.toMillis()); } } }
/** * This method simply calls {@link Thread#sleep(long)}. * * @param delay time to sleep * @throws InterruptedException if any thread has interrupted the current thread */ protected void sleep(Duration delay) throws InterruptedException { if (Duration.ZERO.compareTo(delay) < 0) { Thread.sleep(delay.toMillis()); } } }
@Override public GrpcCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeout) { if (streamIdleTimeout != null) { Preconditions.checkArgument( streamIdleTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); } return new GrpcCallContext( channel, callOptions, timeout, streamWaitTimeout, streamIdleTimeout, channelAffinity, extraHeaders); }
@Override public GrpcCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeout) { if (streamWaitTimeout != null) { Preconditions.checkArgument( streamWaitTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); } return new GrpcCallContext( channel, callOptions, timeout, streamWaitTimeout, streamIdleTimeout, channelAffinity, extraHeaders); }
@Override public GrpcCallContext withStreamWaitTimeout(@Nullable Duration streamWaitTimeout) { if (streamWaitTimeout != null) { Preconditions.checkArgument( streamWaitTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); } return new GrpcCallContext( channel, callOptions, timeout, streamWaitTimeout, streamIdleTimeout, channelAffinity, extraHeaders); }
@Override public GrpcCallContext withStreamIdleTimeout(@Nullable Duration streamIdleTimeout) { if (streamIdleTimeout != null) { Preconditions.checkArgument( streamIdleTimeout.compareTo(Duration.ZERO) >= 0, "Invalid timeout: < 0 s"); } return new GrpcCallContext( channel, callOptions, timeout, streamWaitTimeout, streamIdleTimeout, channelAffinity, extraHeaders); }
@Override public GrpcCallContext withTimeout(@Nullable Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; } // Prevent expanding timeouts if (timeout != null && this.timeout != null && this.timeout.compareTo(timeout) <= 0) { return this; } return new GrpcCallContext( this.channel, this.callOptions, timeout, this.streamWaitTimeout, this.streamIdleTimeout, this.channelAffinity, this.extraHeaders); }
@Override public HttpJsonCallContext withTimeout(Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; } // Prevent expanding deadlines if (timeout != null && this.timeout != null && this.timeout.compareTo(timeout) <= 0) { return this; } return new HttpJsonCallContext( this.channel, timeout, this.deadline, this.credentials, this.extraHeaders, this.tracer); }
@Override public GrpcCallContext withTimeout(@Nullable Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; } // Prevent expanding timeouts if (timeout != null && this.timeout != null && this.timeout.compareTo(timeout) <= 0) { return this; } return new GrpcCallContext( this.channel, this.callOptions, timeout, this.streamWaitTimeout, this.streamIdleTimeout, this.channelAffinity, this.extraHeaders); }
@Override public HttpJsonCallContext withTimeout(Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; } // Prevent expanding deadlines if (timeout != null && this.timeout != null && this.timeout.compareTo(timeout) <= 0) { return this; } return new HttpJsonCallContext( this.channel, timeout, this.deadline, this.credentials, this.extraHeaders, this.tracer); }
/** Build the BatchingSettings object. */ public BatchingSettings build() { BatchingSettings settings = autoBuild(); Preconditions.checkArgument( settings.getElementCountThreshold() == null || settings.getElementCountThreshold() > 0, "elementCountThreshold must be either unset or positive"); Preconditions.checkArgument( settings.getRequestByteThreshold() == null || settings.getRequestByteThreshold() > 0, "requestByteThreshold must be either unset or positive"); Preconditions.checkArgument( settings.getDelayThreshold() == null || settings.getDelayThreshold().compareTo(Duration.ZERO) > 0, "delayThreshold must be either unset or positive"); return settings; } }
/** Build the BatchingSettings object. */ public BatchingSettings build() { BatchingSettings settings = autoBuild(); Preconditions.checkArgument( settings.getElementCountThreshold() == null || settings.getElementCountThreshold() > 0, "elementCountThreshold must be either unset or positive"); Preconditions.checkArgument( settings.getRequestByteThreshold() == null || settings.getRequestByteThreshold() > 0, "requestByteThreshold must be either unset or positive"); Preconditions.checkArgument( settings.getDelayThreshold() == null || settings.getDelayThreshold().compareTo(Duration.ZERO) > 0, "delayThreshold must be either unset or positive"); return settings; } }
public RetrySettings build() { RetrySettings params = autoBuild(); if (params.getTotalTimeout().toMillis() < 0) { throw new IllegalStateException("total timeout must not be negative"); } if (params.getInitialRetryDelay().toMillis() < 0) { throw new IllegalStateException("initial retry delay must not be negative"); } if (params.getRetryDelayMultiplier() < 1.0) { throw new IllegalStateException("retry delay multiplier must be at least 1"); } if (params.getMaxRetryDelay().compareTo(params.getInitialRetryDelay()) < 0) { throw new IllegalStateException("max retry delay must not be shorter than initial delay"); } if (params.getMaxAttempts() < 0) { throw new IllegalStateException("max attempts must be non-negative"); } if (params.getInitialRpcTimeout().toMillis() < 0) { throw new IllegalStateException("initial rpc timeout must not be negative"); } if (params.getMaxRpcTimeout().compareTo(params.getInitialRpcTimeout()) < 0) { throw new IllegalStateException("max rpc timeout must not be shorter than initial timeout"); } if (params.getRpcTimeoutMultiplier() < 1.0) { throw new IllegalStateException("rpc timeout multiplier must be at least 1"); } return params; }
public RetrySettings build() { RetrySettings params = autoBuild(); if (params.getTotalTimeout().toMillis() < 0) { throw new IllegalStateException("total timeout must not be negative"); } if (params.getInitialRetryDelay().toMillis() < 0) { throw new IllegalStateException("initial retry delay must not be negative"); } if (params.getRetryDelayMultiplier() < 1.0) { throw new IllegalStateException("retry delay multiplier must be at least 1"); } if (params.getMaxRetryDelay().compareTo(params.getInitialRetryDelay()) < 0) { throw new IllegalStateException("max retry delay must not be shorter than initial delay"); } if (params.getMaxAttempts() < 0) { throw new IllegalStateException("max attempts must be non-negative"); } if (params.getInitialRpcTimeout().toMillis() < 0) { throw new IllegalStateException("initial rpc timeout must not be negative"); } if (params.getMaxRpcTimeout().compareTo(params.getInitialRpcTimeout()) < 0) { throw new IllegalStateException("max rpc timeout must not be shorter than initial timeout"); } if (params.getRpcTimeoutMultiplier() < 1.0) { throw new IllegalStateException("rpc timeout multiplier must be at least 1"); } return params; }
@Override public FakeCallContext withTimeout(Duration timeout) { // Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts. if (timeout != null && (timeout.isZero() || timeout.isNegative())) { timeout = null; } // Prevent expanding timeouts if (timeout != null && this.timeout != null && this.timeout.compareTo(timeout) <= 0) { return this; } return new FakeCallContext( this.credentials, this.channel, timeout, this.streamWaitTimeout, this.streamIdleTimeout, this.extraHeaders, this.tracer); }