Skip to content

Commit 572f433

Browse files
Remove Trailers
1 parent 3c924fd commit 572f433

40 files changed

+135
-142
lines changed

auth/src/test/java/io/grpc/auth/ClientAuthInterceptorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void testCredentialsThrows() throws IOException {
134134
Metadata.Headers headers = new Metadata.Headers();
135135
interceptedCall.start(listener, headers);
136136
ArgumentCaptor<Status> statusCaptor = ArgumentCaptor.forClass(Status.class);
137-
Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.Trailers.class));
137+
Mockito.verify(listener).onClose(statusCaptor.capture(), isA(Metadata.class));
138138
Assert.assertNull(headers.getAll(AUTHORIZATION));
139139
Mockito.verify(call, never()).start(listener, headers);
140140
Assert.assertEquals(Status.Code.UNAUTHENTICATED, statusCaptor.getValue().getCode());

benchmarks/src/jmh/java/io/grpc/benchmarks/netty/AbstractBenchmark.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void onMessage(ByteBuf message) {
254254

255255
@Override
256256
public void onHalfClose() {
257-
call.close(Status.OK, new Metadata.Trailers());
257+
call.close(Status.OK, new Metadata());
258258
}
259259

260260
@Override
@@ -287,7 +287,7 @@ public void onMessage(ByteBuf message) {
287287

288288
@Override
289289
public void onHalfClose() {
290-
call.close(Status.OK, new Metadata.Trailers());
290+
call.close(Status.OK, new Metadata());
291291
}
292292

293293
@Override
@@ -323,7 +323,7 @@ public void onMessage(ByteBuf message) {
323323

324324
@Override
325325
public void onHalfClose() {
326-
call.close(Status.OK, new Metadata.Trailers());
326+
call.close(Status.OK, new Metadata());
327327
}
328328

329329
@Override

core/src/main/java/io/grpc/ChannelImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ private InactiveTransport(Status s) {
475475
@Override
476476
public ClientStream newStream(
477477
MethodDescriptor<?, ?> method, Headers headers, ClientStreamListener listener) {
478-
listener.closed(shutdownStatus, new Metadata.Trailers());
478+
listener.closed(shutdownStatus, new Metadata());
479479
return new ClientCallImpl.NoopClientStream();
480480
}
481481

core/src/main/java/io/grpc/ClientCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public abstract static class Listener<T> {
9191
* @param status the result of the remote call.
9292
* @param trailers metadata provided at call completion.
9393
*/
94-
public abstract void onClose(Status status, Metadata.Trailers trailers);
94+
public abstract void onClose(Status status, Metadata trailers);
9595

9696
/**
9797
* This indicates that the ClientCall is now capable of sending additional messages (via

core/src/main/java/io/grpc/ClientCallImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public boolean isReady() {
201201
private void closeCallPrematurely(ClientStreamListener listener, Status status) {
202202
Preconditions.checkState(stream == null, "Stream already created");
203203
stream = new NoopClientStream();
204-
listener.closed(status, new Metadata.Trailers());
204+
listener.closed(status, new Metadata());
205205
}
206206

207207
private ScheduledFuture<?> startDeadlineTimer(long timeoutMicros) {
@@ -267,7 +267,7 @@ public void run() {
267267
}
268268

269269
@Override
270-
public void closed(Status status, Metadata.Trailers trailers) {
270+
public void closed(Status status, Metadata trailers) {
271271
if (status.getCode() == Status.Code.CANCELLED && deadlineNanoTime != null) {
272272
// When the server's deadline expires, it can only reset the stream with CANCEL and no
273273
// description. Since our timer may be delayed in firing, we double-check the deadline and
@@ -276,11 +276,11 @@ public void closed(Status status, Metadata.Trailers trailers) {
276276
if (deadlineNanoTime <= System.nanoTime()) {
277277
status = Status.DEADLINE_EXCEEDED;
278278
// Replace trailers to prevent mixing sources of status and trailers.
279-
trailers = new Metadata.Trailers();
279+
trailers = new Metadata();
280280
}
281281
}
282282
final Status savedStatus = status;
283-
final Metadata.Trailers savedTrailers = trailers;
283+
final Metadata savedTrailers = trailers;
284284
callExecutor.execute(new Runnable() {
285285
@Override
286286
public void run() {

core/src/main/java/io/grpc/ClientInterceptors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public final void start(Listener<RespT> responseListener, Metadata.Headers heade
164164
// to a NO-OP one to prevent the IllegalStateException. The user will finally get notified
165165
// about the error through the listener.
166166
delegate = (ClientCall<ReqT, RespT>) NOOP_CALL;
167-
responseListener.onClose(Status.fromThrowable(e), new Metadata.Trailers());
167+
responseListener.onClose(Status.fromThrowable(e), new Metadata());
168168
}
169169
}
170170
}

core/src/main/java/io/grpc/ForwardingClientCallListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void onMessage(RespT message) {
5252
}
5353

5454
@Override
55-
public void onClose(Status status, Metadata.Trailers trailers) {
55+
public void onClose(Status status, Metadata trailers) {
5656
delegate().onClose(status, trailers);
5757
}
5858

core/src/main/java/io/grpc/ForwardingServerCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public boolean isReady() {
6161
}
6262

6363
@Override
64-
public void close(Status status, Metadata.Trailers trailers) {
64+
public void close(Status status, Metadata trailers) {
6565
delegate().close(status, trailers);
6666
}
6767

core/src/main/java/io/grpc/Metadata.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
* </p>
5757
*/
5858
@NotThreadSafe
59-
public abstract class Metadata {
59+
public class Metadata {
6060

6161
/**
6262
* All binary headers should have this suffix in their names. Vice versa.
@@ -108,7 +108,7 @@ public Integer parseAsciiString(String serialized) {
108108
* Constructor called by the transport layer when it receives binary metadata.
109109
*/
110110
// TODO(louiscryan): Convert to use ByteString so we can cache transformations
111-
private Metadata(byte[]... binaryValues) {
111+
public Metadata(byte[]... binaryValues) {
112112
for (int i = 0; i < binaryValues.length; i++) {
113113
String name = new String(binaryValues[i], US_ASCII);
114114
storeAdd(name, new MetadataEntry(name.endsWith(BINARY_HEADER_SUFFIX), binaryValues[++i]));
@@ -118,7 +118,7 @@ private Metadata(byte[]... binaryValues) {
118118
/**
119119
* Constructor called by the application layer when it wants to send metadata.
120120
*/
121-
private Metadata() {}
121+
public Metadata() {}
122122

123123
private void storeAdd(String name, MetadataEntry value) {
124124
List<MetadataEntry> values = store.get(name);
@@ -286,6 +286,11 @@ public void merge(Metadata other, Set<Key<?>> keys) {
286286
}
287287
}
288288

289+
@Override
290+
public String toString() {
291+
return "Metadata(" + toStringInternal() + ")";
292+
}
293+
289294
private String toStringInternal() {
290295
return store.toString();
291296
}
@@ -375,31 +380,19 @@ public String toString() {
375380
/**
376381
* Concrete instance for metadata attached to the end of the call. Only provided by
377382
* servers.
383+
*
384+
* @deprecated use Metadata instead.
378385
*/
386+
@Deprecated
379387
public static class Trailers extends Metadata {
380-
/**
381-
* Called by the transport layer to create trailers from their binary serialized values.
382-
*
383-
* <p>This method does not copy the provided byte arrays. The byte arrays must not be mutated.
384-
*/
385-
public Trailers(byte[]... headers) {
386-
super(headers);
387-
}
388-
389388
/**
390389
* Called by the application layer to construct trailers prior to passing them to the
391390
* transport for serialization.
392391
*/
393392
public Trailers() {
394393
}
395-
396-
@Override
397-
public String toString() {
398-
return "Trailers(" + super.toStringInternal() + ")";
399-
}
400394
}
401395

402-
403396
/**
404397
* Marshaller for metadata values that are serialized into raw binary.
405398
*/

core/src/main/java/io/grpc/ServerCall.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ public boolean isReady() {
149149
* status} is not equal to {@link Status#OK}, then the call is said to have failed.
150150
*
151151
* <p>If {@code status} is not {@link Status#CANCELLED} and no errors or cancellations are known
152-
* to have occured, then a {@link Listener#onComplete} notification should be expected.
152+
* to have occurred, then a {@link Listener#onComplete} notification should be expected.
153153
* Otherwise {@link Listener#onCancel} has been or will be called.
154154
*
155155
* @throws IllegalStateException if call is already {@code close}d
156156
*/
157-
public abstract void close(Status status, Metadata.Trailers trailers);
157+
public abstract void close(Status status, Metadata trailers);
158158

159159
/**
160160
* Returns {@code true} when the call is cancelled and the server is encouraged to abort

0 commit comments

Comments
 (0)