Skip to content

Commit e231c87

Browse files
authored
Remove JSR-305 ThreadSafe annotation and replace with JavaDoc (#12762)
For non-final public classes and interfaces only, this PR removes JSR-305 ThreadSafe annotations but instead of replacing with ErrorProne's ThreadSafe, sticks to adding a JavaDoc comment. This should basically keep things inline with what JSR-305 ThreadSafe affords. Adding ErrorProne's ThreadSafe can be considered in the future, as it expects more things than JSR-305. Removing the JSR-305 dependency here allows Java applications that have moved away from javax to compile and avoids a bug in Immutables and Lombok (and possibly other annotation processors) from failing when JSR-305 is not present.
1 parent 039ad77 commit e231c87

25 files changed

Lines changed: 63 additions & 61 deletions

api/src/main/java/io/grpc/Channel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package io.grpc;
1818

19-
import javax.annotation.concurrent.ThreadSafe;
2019

2120
/**
2221
* A virtual connection to a conceptual endpoint, to perform RPCs. A channel is free to have zero or
@@ -29,8 +28,9 @@
2928
* implementations using {@link ClientInterceptor}. It is expected that most application
3029
* code will not use this class directly but rather work with stubs that have been bound to a
3130
* Channel that was decorated during application initialization.
31+
*
32+
* <p>This class is thread-safe.
3233
*/
33-
@ThreadSafe
3434
public abstract class Channel {
3535
/**
3636
* Create a {@link ClientCall} to the remote operation specified by the given

api/src/main/java/io/grpc/ChannelLogger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
package io.grpc;
1818

19-
import javax.annotation.concurrent.ThreadSafe;
2019

2120
/**
2221
* A Channel-specific logger provided by GRPC library to {@link LoadBalancer} implementations.
2322
* Information logged here goes to <strong>Channelz</strong>, and to the Java logger of this class
2423
* as well.
24+
*
25+
* <p>This class is thread-safe.
2526
*/
2627
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/5029")
27-
@ThreadSafe
2828
public abstract class ChannelLogger {
2929
/**
3030
* Log levels. See the table below for the mapping from the ChannelLogger levels to Channelz

api/src/main/java/io/grpc/ClientInterceptor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package io.grpc;
1818

19-
import javax.annotation.concurrent.ThreadSafe;
2019

2120
/**
2221
* Interface for intercepting outgoing calls before they are dispatched by a {@link Channel}.
@@ -37,8 +36,10 @@
3736
* without completing the previous ones first. Refer to the
3837
* {@link io.grpc.ClientCall.Listener ClientCall.Listener} docs for more details regarding thread
3938
* safety of the returned listener.
39+
*
40+
* <p>This is thread-safe and should be considered
41+
* for the errorprone ThreadSafe annotation in the future.
4042
*/
41-
@ThreadSafe
4243
public interface ClientInterceptor {
4344
/**
4445
* Intercept {@link ClientCall} creation by the {@code next} {@link Channel}.

api/src/main/java/io/grpc/ClientStreamTracer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
import static com.google.common.base.Preconditions.checkNotNull;
2020

2121
import com.google.common.base.MoreObjects;
22-
import javax.annotation.concurrent.ThreadSafe;
2322

2423
/**
2524
* {@link StreamTracer} for the client-side.
25+
*
26+
* <p>This class is thread-safe.
2627
*/
2728
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/2861")
28-
@ThreadSafe
2929
public abstract class ClientStreamTracer extends StreamTracer {
3030
/**
3131
* Indicates how long the call was delayed, in nanoseconds, due to waiting for name resolution

api/src/main/java/io/grpc/HandlerRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import java.util.Collections;
2020
import java.util.List;
2121
import javax.annotation.Nullable;
22-
import javax.annotation.concurrent.ThreadSafe;
2322

2423
/**
2524
* Registry of services and their methods used by servers to dispatching incoming calls.
25+
*
26+
* <p>This class is thread-safe.
2627
*/
27-
@ThreadSafe
2828
public abstract class HandlerRegistry {
2929

3030
/**

api/src/main/java/io/grpc/LoadBalancer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import javax.annotation.Nullable;
3333
import javax.annotation.concurrent.Immutable;
3434
import javax.annotation.concurrent.NotThreadSafe;
35-
import javax.annotation.concurrent.ThreadSafe;
3635

3736
/**
3837
* A pluggable component that receives resolved addresses from {@link NameResolver} and provides the
@@ -64,7 +63,7 @@
6463
* allows implementations to schedule tasks to be run in the same Synchronization Context, with or
6564
* without a delay, thus those tasks don't need to worry about synchronizing with the balancer
6665
* methods.
67-
*
66+
*
6867
* <p>However, the actual running thread may be the network thread, thus the following rules must be
6968
* followed to prevent blocking or even dead-locking in a network:
7069
*
@@ -417,7 +416,7 @@ public void handleSubchannelState(
417416
*
418417
* <p>This method should always return a constant value. It's not specified when this will be
419418
* called.
420-
*
419+
*
421420
* <p>Note that this method is only called when implementing {@code handleResolvedAddresses()}
422421
* instead of {@code acceptResolvedAddresses()}.
423422
*
@@ -450,7 +449,6 @@ public void requestConnection() {}
450449
*
451450
* @since 1.2.0
452451
*/
453-
@ThreadSafe
454452
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
455453
public abstract static class SubchannelPicker {
456454
/**
@@ -640,7 +638,7 @@ private PickResult(
640638
* stream is created at all in some cases.
641639
* @since 1.3.0
642640
*/
643-
// TODO(shivaspeaks): Need to deprecate old APIs and create new ones,
641+
// TODO(shivaspeaks): Need to deprecate old APIs and create new ones,
644642
// per https://github.com/grpc/grpc-java/issues/12662.
645643
public static PickResult withSubchannel(
646644
Subchannel subchannel, @Nullable ClientStreamTracer.Factory streamTracerFactory) {
@@ -1030,9 +1028,10 @@ public String toString() {
10301028
/**
10311029
* Provides essentials for LoadBalancer implementations.
10321030
*
1031+
* <p>This class is thread-safe.
1032+
*
10331033
* @since 1.2.0
10341034
*/
1035-
@ThreadSafe
10361035
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
10371036
public abstract static class Helper {
10381037
/**
@@ -1332,7 +1331,7 @@ public MetricRecorder getMetricRecorder() {
13321331
}
13331332

13341333
/**
1335-
* A logical connection to a server, or a group of equivalent servers represented by an {@link
1334+
* A logical connection to a server, or a group of equivalent servers represented by an {@link
13361335
* EquivalentAddressGroup}.
13371336
*
13381337
* <p>It maintains at most one physical connection (aka transport) for sending new RPCs, while
@@ -1551,9 +1550,10 @@ public interface SubchannelStateListener {
15511550
/**
15521551
* Factory to create {@link LoadBalancer} instance.
15531552
*
1553+
* <p>This class is thread-safe.
1554+
*
15541555
* @since 1.2.0
15551556
*/
1556-
@ThreadSafe
15571557
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1771")
15581558
public abstract static class Factory {
15591559
/**

api/src/main/java/io/grpc/ManagedChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package io.grpc;
1818

1919
import java.util.concurrent.TimeUnit;
20-
import javax.annotation.concurrent.ThreadSafe;
2120

2221
/**
2322
* A {@link Channel} that provides lifecycle management.
23+
*
24+
* <p>This class is thread-safe.
2425
*/
25-
@ThreadSafe
2626
public abstract class ManagedChannel extends Channel {
2727
/**
2828
* Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately

api/src/main/java/io/grpc/NameResolver.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import java.util.concurrent.ScheduledExecutorService;
3636
import javax.annotation.Nullable;
3737
import javax.annotation.concurrent.Immutable;
38-
import javax.annotation.concurrent.ThreadSafe;
3938

4039
/**
4140
* A pluggable component that resolves a target {@link URI} and return addresses to the caller.
@@ -78,7 +77,7 @@ public abstract class NameResolver {
7877
* Starts the resolution. The method is not supposed to throw any exceptions. That might cause the
7978
* Channel that the name resolver is serving to crash. Errors should be propagated
8079
* through {@link Listener#onError}.
81-
*
80+
*
8281
* <p>An instance may not be started more than once, by any overload of this method, even after
8382
* an intervening call to {@link #shutdown}.
8483
*
@@ -114,7 +113,7 @@ public void onResult(ResolutionResult resolutionResult) {
114113
* Starts the resolution. The method is not supposed to throw any exceptions. That might cause the
115114
* Channel that the name resolver is serving to crash. Errors should be propagated
116115
* through {@link Listener2#onError}.
117-
*
116+
*
118117
* <p>An instance may not be started more than once, by any overload of this method, even after
119118
* an intervening call to {@link #shutdown}.
120119
*
@@ -215,10 +214,11 @@ public NameResolver newNameResolver(Uri targetUri, final Args args) {
215214
*
216215
* <p>All methods are expected to return quickly.
217216
*
217+
* <p>This interface is thread-safe.
218+
*
218219
* @since 1.0.0
219220
*/
220221
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1770")
221-
@ThreadSafe
222222
public interface Listener {
223223
/**
224224
* Handles updates on resolved addresses and attributes.

api/src/main/java/io/grpc/Server.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
import java.util.Collections;
2222
import java.util.List;
2323
import java.util.concurrent.TimeUnit;
24-
import javax.annotation.concurrent.ThreadSafe;
2524

2625
/**
2726
* Server for listening for and dispatching incoming calls. It is not expected to be implemented by
2827
* application code or interceptors.
28+
*
29+
* <p>This class is thread-safe.
2930
*/
30-
@ThreadSafe
3131
public abstract class Server {
3232

3333
/**

api/src/main/java/io/grpc/ServerCallHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616

1717
package io.grpc;
1818

19-
import javax.annotation.concurrent.ThreadSafe;
20-
2119
/**
2220
* Interface to initiate processing of incoming remote calls. Advanced applications and generated
2321
* code will implement this interface to allows {@link Server}s to invoke service methods.
22+
*
23+
* <p>This interface is thread-safe.
2424
*/
25-
@ThreadSafe
2625
public interface ServerCallHandler<RequestT, ResponseT> {
2726
/**
2827
* Starts asynchronous processing of an incoming call.

0 commit comments

Comments
 (0)