Skip to content

Commit ce9bc06

Browse files
authored
binder: Remove redundant ServerInbound.serverTransport field (#12734)
1 parent 53461b6 commit ce9bc06

4 files changed

Lines changed: 24 additions & 25 deletions

File tree

binder/src/main/java/io/grpc/binder/internal/BinderClientTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public synchronized ClientStream newStream(
279279
}
280280

281281
@Override
282-
protected void unregisterInbound(Inbound<?> inbound) {
282+
protected void unregisterInbound(Inbound<?, ?> inbound) {
283283
if (inbound.countsForInUse() && numInUseStreams.decrementAndGet() == 0) {
284284
clientTransportListener.transportInUse(false);
285285
}

binder/src/main/java/io/grpc/binder/internal/BinderServerTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public synchronized void shutdownNow(Status reason) {
146146
@Override
147147
@Nullable
148148
@GuardedBy("this")
149-
protected Inbound<?> createInbound(int callId) {
149+
protected Inbound<?, ?> createInbound(int callId) {
150150
return new Inbound.ServerInbound(this, attributes, callId);
151151
}
152152

binder/src/main/java/io/grpc/binder/internal/BinderTransport.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ protected enum TransportState {
163163
@GuardedBy("this")
164164
private final LeakSafeOneWayBinder incomingBinder;
165165

166-
protected final ConcurrentHashMap<Integer, Inbound<?>> ongoingCalls;
166+
protected final ConcurrentHashMap<Integer, Inbound<?, ?>> ongoingCalls;
167167
protected final OneWayBinderProxy.Decorator binderDecorator;
168168

169169
@GuardedBy("this")
@@ -318,13 +318,13 @@ final void shutdownInternal(Status shutdownStatus, boolean forceTerminate) {
318318
incomingBinder.detach();
319319
setState(TransportState.SHUTDOWN_TERMINATED);
320320
sendShutdownTransaction();
321-
ArrayList<Inbound<?>> calls = new ArrayList<>(ongoingCalls.values());
321+
ArrayList<Inbound<?, ?>> calls = new ArrayList<>(ongoingCalls.values());
322322
ongoingCalls.clear();
323323
ArrayList<Future<?>> futuresToCancel = new ArrayList<>(ownedFutures);
324324
ownedFutures.clear();
325325
scheduledExecutorService.execute(
326326
() -> {
327-
for (Inbound<?> inbound : calls) {
327+
for (Inbound<?, ?> inbound : calls) {
328328
synchronized (inbound) {
329329
inbound.closeAbnormal(shutdownStatus);
330330
}
@@ -392,7 +392,7 @@ protected synchronized void sendPing(int id) throws StatusException {
392392
}
393393
}
394394

395-
protected void unregisterInbound(Inbound<?> inbound) {
395+
protected void unregisterInbound(Inbound<?, ?> inbound) {
396396
unregisterCall(inbound.callId);
397397
}
398398

@@ -481,13 +481,13 @@ private boolean handleTransactionInternal(int code, Parcel parcel) {
481481
}
482482
} else {
483483
int size = parcel.dataSize();
484-
Inbound<?> inbound = ongoingCalls.get(code);
484+
Inbound<?, ?> inbound = ongoingCalls.get(code);
485485
if (inbound == null) {
486486
synchronized (this) {
487487
if (!isShutdown()) {
488488
inbound = createInbound(code);
489489
if (inbound != null) {
490-
Inbound<?> existing = ongoingCalls.put(code, inbound);
490+
Inbound<?, ?> existing = ongoingCalls.put(code, inbound);
491491
// Can't happen as only one invocation of handleTransaction() is running at a time.
492492
Verify.verify(existing == null, "impossible appearance of %s", existing);
493493
}
@@ -519,7 +519,7 @@ protected void restrictIncomingBinderToCallsFrom(int allowedCallingUid) {
519519

520520
@Nullable
521521
@GuardedBy("this")
522-
protected Inbound<?> createInbound(int callId) {
522+
protected Inbound<?, ?> createInbound(int callId) {
523523
return null;
524524
}
525525

@@ -566,7 +566,7 @@ final void handleAcknowledgedBytes(long numBytes) {
566566

567567
Iterator<Integer> i = callIdsToNotifyWhenReady.iterator();
568568
while (isReady() && i.hasNext()) {
569-
Inbound<?> inbound = ongoingCalls.get(i.next());
569+
Inbound<?, ?> inbound = ongoingCalls.get(i.next());
570570
i.remove();
571571
if (inbound != null) { // Calls can be removed out from under us.
572572
inbound.onTransportReady();
@@ -598,7 +598,7 @@ private static void checkTransition(TransportState current, TransportState next)
598598
}
599599

600600
@VisibleForTesting
601-
Map<Integer, Inbound<?>> getOngoingCalls() {
601+
Map<Integer, Inbound<?, ?>> getOngoingCalls() {
602602
return ongoingCalls;
603603
}
604604

binder/src/main/java/io/grpc/binder/internal/Inbound.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@
4242
*
4343
* <p>Out-of-order messages are reassembled into their correct order.
4444
*/
45-
abstract class Inbound<L extends StreamListener> implements StreamListener.MessageProducer {
45+
abstract class Inbound<L extends StreamListener, T extends BinderTransport>
46+
implements StreamListener.MessageProducer {
4647

47-
protected final BinderTransport transport;
48+
protected final T transport;
4849
protected final Attributes attributes;
4950
final int callId;
5051

@@ -145,7 +146,7 @@ enum State {
145146
@GuardedBy("this")
146147
private boolean producingMessages;
147148

148-
private Inbound(BinderTransport transport, Attributes attributes, int callId) {
149+
private Inbound(T transport, Attributes attributes, int callId) {
149150
this.transport = transport;
150151
this.attributes = attributes;
151152
this.callId = callId;
@@ -558,7 +559,7 @@ public synchronized String toString() {
558559

559560
// ======================================
560561
// Client-side inbound transactions.
561-
static final class ClientInbound extends Inbound<ClientStreamListener> {
562+
static final class ClientInbound extends Inbound<ClientStreamListener, BinderClientTransport> {
562563

563564
private final boolean countsForInUse;
564565

@@ -571,7 +572,10 @@ static final class ClientInbound extends Inbound<ClientStreamListener> {
571572
private Metadata trailers;
572573

573574
ClientInbound(
574-
BinderTransport transport, Attributes attributes, int callId, boolean countsForInUse) {
575+
BinderClientTransport transport,
576+
Attributes attributes,
577+
int callId,
578+
boolean countsForInUse) {
575579
super(transport, attributes, callId);
576580
this.countsForInUse = countsForInUse;
577581
}
@@ -615,13 +619,9 @@ protected void deliverCloseAbnormal(Status status) {
615619

616620
// ======================================
617621
// Server-side inbound transactions.
618-
static final class ServerInbound extends Inbound<ServerStreamListener> {
619-
620-
private final BinderServerTransport serverTransport;
621-
622+
static final class ServerInbound extends Inbound<ServerStreamListener, BinderServerTransport> {
622623
ServerInbound(BinderServerTransport transport, Attributes attributes, int callId) {
623624
super(transport, attributes, callId);
624-
this.serverTransport = transport;
625625
}
626626

627627
@GuardedBy("this")
@@ -630,17 +630,16 @@ protected void handlePrefix(int flags, Parcel parcel) throws StatusException {
630630
String methodName = parcel.readString();
631631
Metadata headers = MetadataHelper.readMetadata(parcel, attributes);
632632

633-
StatsTraceContext statsTraceContext =
634-
serverTransport.createStatsTraceContext(methodName, headers);
633+
StatsTraceContext statsTraceContext = transport.createStatsTraceContext(methodName, headers);
635634
Outbound.ServerOutbound outbound =
636-
new Outbound.ServerOutbound(serverTransport, callId, statsTraceContext);
635+
new Outbound.ServerOutbound(transport, callId, statsTraceContext);
637636
ServerStream stream;
638637
if ((flags & TransactionUtils.FLAG_EXPECT_SINGLE_MESSAGE) != 0) {
639638
stream = new SingleMessageServerStream(this, outbound, attributes);
640639
} else {
641640
stream = new MultiMessageServerStream(this, outbound, attributes);
642641
}
643-
Status status = serverTransport.startStream(stream, methodName, headers);
642+
Status status = transport.startStream(stream, methodName, headers);
644643
if (status.isOk()) {
645644
checkNotNull(listener); // Is it ok to assume this will happen synchronously?
646645
if (transport.isReady()) {

0 commit comments

Comments
 (0)