Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@

import com.google.api.gax.rpc.ApiStreamObserver;
import io.grpc.stub.StreamObserver;
import org.jspecify.annotations.NullMarked;

/**
* A delegate class that transfers calls to the ApiStreamObserver object.
*
* <p>Package-private for internal use.
*/
@NullMarked
class ApiStreamObserverDelegate<V> implements StreamObserver<V> {

private final ApiStreamObserver<V> delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
import io.grpc.Metadata.Key;
import java.util.Collections;
import java.util.Map;
import org.jspecify.annotations.NullMarked;

/** A utility class that provides helper functions to work with custom call options. */
@NullMarked
class CallOptionsUtil {
// this is a call option name, not a header name, it is not transferred over the wire
private static final CallOptions.Key<Map<Key<String>, String>> DYNAMIC_HEADERS_CALL_OPTION_KEY =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
import com.google.api.core.InternalApi;
import io.grpc.ManagedChannel;
import java.io.IOException;
import org.jspecify.annotations.NullMarked;

/**
* This interface represents a factory for creating one ManagedChannel
*
* <p>This is public only for technical reasons, for advanced usage.
*/
@NullMarked
@InternalApi("For internal use by google-cloud-java clients only")
public interface ChannelFactory {
ManagedChannel createSingleChannel() throws IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* A {@link ManagedChannel} that will send requests round-robin via a set of channels.
Expand All @@ -68,6 +69,7 @@
*
* <p>Package-private for internal use.
*/
@NullMarked
class ChannelPool extends ManagedChannel {
static final String CHANNEL_POOL_CONSECUTIVE_RESIZING_WARNING =
"The gRPC ChannelPool used in the client has been flagged to be repeatedly resizing (5+ times). See https://github.com/googleapis/google-cloud-java/blob/main/docs/grpc_channel_pool_guide.md for more information about this behavior.";
Expand All @@ -78,8 +80,8 @@ class ChannelPool extends ManagedChannel {
private final ChannelFactory channelFactory;
private final FixedExecutorProvider backgroundExecutorProvider;

private ScheduledFuture<?> refreshFuture = null;
private ScheduledFuture<?> resizeFuture = null;
private @Nullable ScheduledFuture<?> refreshFuture = null;
private @Nullable ScheduledFuture<?> resizeFuture = null;

private final Object entryWriteLock = new Object();
@VisibleForTesting final AtomicReference<ImmutableList<Entry>> entries = new AtomicReference<>();
Expand Down Expand Up @@ -621,7 +623,7 @@ public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(

/** ClientCall wrapper that makes sure to decrement the outstanding RPC count on completion. */
static class ReleasingClientCall<ReqT, RespT> extends SimpleForwardingClientCall<ReqT, RespT> {
@Nullable private CancellationException cancellationException;
private @Nullable CancellationException cancellationException;
final Entry entry;
private final AtomicBoolean wasClosed = new AtomicBoolean();
private final AtomicBoolean wasReleased = new AtomicBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import java.time.Duration;
import org.jspecify.annotations.NullMarked;

/**
* Settings to control {@link ChannelPool} behavior.
Expand All @@ -52,6 +53,7 @@
*
* <p>The settings in this class will be applied every minute.
*/
@NullMarked
@BetaApi("surface for channel pool sizing is not yet stable")
@AutoValue
public abstract class ChannelPoolSettings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@

import com.google.api.core.InternalApi;
import io.grpc.ManagedChannel;
import org.jspecify.annotations.NullMarked;

/**
* An interface to prepare a ManagedChannel for normal requests by priming the channel
*
* <p>This is public only for technical reasons, for advanced usage.
*/
@NullMarked
@InternalApi("For internal use by google-cloud-java clients only")
public interface ChannelPrimer {
void primeChannel(ManagedChannel managedChannel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@
import com.google.api.gax.rpc.StateCheckingResponseObserver;
import com.google.api.gax.rpc.StreamController;
import java.util.concurrent.CancellationException;
import org.jspecify.annotations.NullMarked;

/** Package-private for internal use. */
@NullMarked
class ExceptionResponseObserver<RequestT, ResponseT>
extends StateCheckingResponseObserver<ResponseT> {
private ResponseObserver<ResponseT> innerObserver;
private volatile CancellationException cancellationException;
private final GrpcApiExceptionFactory exceptionFactory;

public ExceptionResponseObserver(

Check warning on line 46 in sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/ExceptionResponseObserver.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

"cancellationException" is marked "@NullMarked at class level" but is not initialized in this constructor.

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AZ9sxsxPpAEM8k1u9lnK&open=AZ9sxsxPpAEM8k1u9lnK&pullRequest=13799
ResponseObserver<ResponseT> innerObserver, GrpcApiExceptionFactory exceptionFactory) {
this.innerObserver = innerObserver;
this.exceptionFactory = exceptionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import com.google.api.gax.core.GaxProperties;
import io.grpc.Channel;
import java.util.regex.Pattern;
import org.jspecify.annotations.NullMarked;

/** Provides properties of the GAX-GRPC library. */
@NullMarked
@InternalApi
public class GaxGrpcProperties {
private static final String GAX_GRPC_VERSION =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
import io.grpc.StatusException;
import io.grpc.StatusRuntimeException;
import java.util.Set;
import org.jspecify.annotations.NullMarked;

/**
* Core logic for transforming GRPC exceptions into {@link ApiException}s. This logic is shared
* amongst all the call types.
*
* <p>Package-private for internal use.
*/
@NullMarked
class GrpcApiExceptionFactory {

@VisibleForTesting static final String ERROR_DETAIL_KEY = "grpc-status-details-bin";
Expand Down Expand Up @@ -77,7 +79,7 @@
boolean canRetry = retryableCodes.contains(GrpcStatusCode.grpcCodeToStatusCode(statusCode));
GrpcStatusCode grpcStatusCode = GrpcStatusCode.of(statusCode);

if (metadata == null) {

Check warning on line 82 in sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcApiExceptionFactory.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

Change this condition so that it does not always evaluate to "false"

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AZ9sxssfpAEM8k1u9lm7&open=AZ9sxssfpAEM8k1u9lm7&pullRequest=13799
return ApiExceptionFactory.createException(throwable, grpcStatusCode, canRetry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
import java.util.Objects;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

/**
* GrpcCallContext encapsulates context data used to make a grpc call.
Expand All @@ -75,6 +76,7 @@
* #withTransportChannel}, return copies of the object, but with one field changed. The immutability
* and thread safety of the arguments solely depends on the arguments themselves.
*/
@NullMarked
@BetaApi("Reference ApiCallContext instead - this class is likely to experience breaking changes")
public final class GrpcCallContext implements ApiCallContext {
private static final GrpcStatusCode UNAUTHENTICATED_STATUS_CODE =
Expand All @@ -85,14 +87,14 @@ public final class GrpcCallContext implements ApiCallContext {
public static final CallOptions.Key<ApiTracer> TRACER_KEY = CallOptions.Key.create("gax.tracer");

private final Channel channel;
@Nullable private final Credentials credentials;
private final @Nullable Credentials credentials;
private final CallOptions callOptions;
@Nullable private final java.time.Duration timeout;
@Nullable private final java.time.Duration streamWaitTimeout;
@Nullable private final java.time.Duration streamIdleTimeout;
@Nullable private final Integer channelAffinity;
@Nullable private final RetrySettings retrySettings;
@Nullable private final ImmutableSet<StatusCode.Code> retryableCodes;
private final java.time.@Nullable Duration timeout;
private final java.time.@Nullable Duration streamWaitTimeout;
private final java.time.@Nullable Duration streamIdleTimeout;
private final @Nullable Integer channelAffinity;
private final @Nullable RetrySettings retrySettings;
private final @Nullable ImmutableSet<StatusCode.Code> retryableCodes;
private final ImmutableMap<String, List<String>> extraHeaders;
private final ApiCallContextOptions options;
private final EndpointContext endpointContext;
Expand Down Expand Up @@ -135,12 +137,12 @@ public static GrpcCallContext of(Channel channel, CallOptions callOptions) {
}

private GrpcCallContext(
Channel channel,
@Nullable Channel channel,
@Nullable Credentials credentials,
CallOptions callOptions,
@Nullable java.time.Duration timeout,
@Nullable java.time.Duration streamWaitTimeout,
@Nullable java.time.Duration streamIdleTimeout,
java.time.@Nullable Duration timeout,
java.time.@Nullable Duration streamWaitTimeout,
java.time.@Nullable Duration streamIdleTimeout,
@Nullable Integer channelAffinity,
ImmutableMap<String, List<String>> extraHeaders,
ApiCallContextOptions options,
Expand Down Expand Up @@ -257,12 +259,12 @@ public GrpcCallContext withEndpointContext(EndpointContext endpointContext) {
/** This method is obsolete. Use {@link #withTimeoutDuration(java.time.Duration)} instead. */
@Override
@ObsoleteApi("Use withTimeoutDuration(java.time.Duration) instead")
public GrpcCallContext withTimeout(@Nullable org.threeten.bp.Duration timeout) {
public GrpcCallContext withTimeout(org.threeten.bp.@Nullable Duration timeout) {
return withTimeoutDuration(toJavaTimeDuration(timeout));
}

@Override
public GrpcCallContext withTimeoutDuration(@Nullable java.time.Duration timeout) {
public GrpcCallContext withTimeoutDuration(java.time.@Nullable Duration timeout) {
// Default RetrySettings use 0 for RPC timeout. Treat that as disabled timeouts.
if (timeout != null && (timeout.isZero() || timeout.isNegative())) {
timeout = null;
Expand All @@ -289,17 +291,14 @@ public GrpcCallContext withTimeoutDuration(@Nullable java.time.Duration timeout)
isDirectPath);
}

/** This method is obsolete. Use {@link #getTimeoutDuration()} instead. */
@Nullable
@Override
@ObsoleteApi("Use getTimeoutDuration() instead")
public org.threeten.bp.Duration getTimeout() {
public org.threeten.bp.@Nullable Duration getTimeout() {
return toThreetenDuration(getTimeoutDuration());
}

@Nullable
@Override
public java.time.Duration getTimeoutDuration() {
public java.time.@Nullable Duration getTimeoutDuration() {
return timeout;
}

Expand All @@ -310,13 +309,13 @@ public java.time.Duration getTimeoutDuration() {
@Override
@ObsoleteApi("Use withStreamWaitTimeoutDuration(java.time.Duration) instead")
public GrpcCallContext withStreamWaitTimeout(
@Nullable org.threeten.bp.Duration streamWaitTimeout) {
org.threeten.bp.@Nullable Duration streamWaitTimeout) {
return withStreamWaitTimeoutDuration(toJavaTimeDuration(streamWaitTimeout));
}

@Override
public GrpcCallContext withStreamWaitTimeoutDuration(
@Nullable java.time.Duration streamWaitTimeout) {
java.time.@Nullable Duration streamWaitTimeout) {
if (streamWaitTimeout != null) {
Preconditions.checkArgument(
streamWaitTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s");
Expand Down Expand Up @@ -345,13 +344,13 @@ public GrpcCallContext withStreamWaitTimeoutDuration(
@Override
@ObsoleteApi("Use withStreamIdleTimeoutDuration(java.time.Duration) instead")
public GrpcCallContext withStreamIdleTimeout(
@Nullable org.threeten.bp.Duration streamIdleTimeout) {
org.threeten.bp.@Nullable Duration streamIdleTimeout) {
return withStreamIdleTimeoutDuration(toJavaTimeDuration(streamIdleTimeout));
}

@Override
public GrpcCallContext withStreamIdleTimeoutDuration(
@Nullable java.time.Duration streamIdleTimeout) {
java.time.@Nullable Duration streamIdleTimeout) {
if (streamIdleTimeout != null) {
Preconditions.checkArgument(
streamIdleTimeout.compareTo(java.time.Duration.ZERO) >= 0, "Invalid timeout: < 0 s");
Expand Down Expand Up @@ -573,9 +572,8 @@ public CallOptions getCallOptions() {

/** This method is obsolete. Use {@link #getStreamWaitTimeoutDuration()} instead. */
@Override
@Nullable
@ObsoleteApi("Use getStreamWaitTimeoutDuration() instead")
public org.threeten.bp.Duration getStreamWaitTimeout() {
public org.threeten.bp.@Nullable Duration getStreamWaitTimeout() {
return toThreetenDuration(getStreamWaitTimeoutDuration());
}

Expand All @@ -585,16 +583,14 @@ public org.threeten.bp.Duration getStreamWaitTimeout() {
* @see ApiCallContext#withStreamWaitTimeoutDuration(java.time.Duration)
*/
@Override
@Nullable
public java.time.Duration getStreamWaitTimeoutDuration() {
public java.time.@Nullable Duration getStreamWaitTimeoutDuration() {
return streamWaitTimeout;
}

/** This method is obsolete. Use {@link #getStreamIdleTimeoutDuration()} instead. */
@Override
@Nullable
@ObsoleteApi("Use getStreamIdleTimeoutDuration() instead")
public org.threeten.bp.Duration getStreamIdleTimeout() {
public org.threeten.bp.@Nullable Duration getStreamIdleTimeout() {
return toThreetenDuration(getStreamIdleTimeoutDuration());
}

Expand All @@ -604,14 +600,12 @@ public org.threeten.bp.Duration getStreamIdleTimeout() {
* @see ApiCallContext#withStreamIdleTimeoutDuration(java.time.Duration)
*/
@Override
@Nullable
public java.time.Duration getStreamIdleTimeoutDuration() {
public java.time.@Nullable Duration getStreamIdleTimeoutDuration() {
return streamIdleTimeout;
}

/** The channel affinity for this context. */
@Nullable
public Integer getChannelAffinity() {
public @Nullable Integer getChannelAffinity() {
return channelAffinity;
}

Expand Down Expand Up @@ -769,7 +763,7 @@ public int hashCode() {
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import com.google.api.gax.rpc.RequestParamsExtractor;
import com.google.api.gax.rpc.ResourceNameExtractor;
import io.grpc.MethodDescriptor;
import org.jspecify.annotations.NullMarked;

/** Grpc-specific settings for creating callables. */
@NullMarked
public class GrpcCallSettings<RequestT, ResponseT> {
private final MethodDescriptor<RequestT, ResponseT> methodDescriptor;
private final RequestParamsExtractor<RequestT> paramsExtractor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@
import com.google.longrunning.stub.OperationsStub;
import io.grpc.MethodDescriptor;
import javax.annotation.Nonnull;
import org.jspecify.annotations.NullMarked;

/** Class with utility methods to create grpc-based direct callables. */
@NullMarked
public class GrpcCallableFactory {

private GrpcCallableFactory() {}
Expand All @@ -82,7 +84,7 @@
GrpcRawCallableFactory.createUnaryCallable(
grpcCallSettings, callSettings.getRetryableCodes());

if (grpcCallSettings.getRequestMutator() != null) {

Check warning on line 87 in sdk-platform-java/gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallableFactory.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

Change this condition so that it does not always evaluate to "true"

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AZ9sxs04pAEM8k1u9lnh&open=AZ9sxs04pAEM8k1u9lnh&pullRequest=13799
callable =
Callables.retrying(
callable, callSettings, clientContext, grpcCallSettings.getRequestMutator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
import io.grpc.ClientInterceptor;
import io.grpc.MethodDescriptor;
import java.util.UUID;
import org.jspecify.annotations.NullMarked;

@NullMarked
class GrpcChannelUUIDInterceptor implements ClientInterceptor {
private final String uuid = UUID.randomUUID().toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jspecify.annotations.NullMarked;

/**
* {@code GrpcClientCalls} creates a new {@code ClientCall} from the given call context.
*
* <p>Package-private for internal use.
*/
@NullMarked
class GrpcClientCalls {
private static final Logger LOGGER = Logger.getLogger(GrpcDirectCallable.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.google.common.base.Preconditions;
import io.grpc.ClientCall;
import io.grpc.MethodDescriptor;
import org.jspecify.annotations.NullMarked;

/**
* {@code GrpcDirectBidiStreamingCallable} creates bidirectional streaming gRPC calls.
Expand All @@ -45,6 +46,7 @@
*
* <p>Package-private for internal use.
*/
@NullMarked
class GrpcDirectBidiStreamingCallable<RequestT, ResponseT>
extends BidiStreamingCallable<RequestT, ResponseT> {
private final MethodDescriptor<RequestT, ResponseT> descriptor;
Expand Down
Loading
Loading