Skip to content

Commit f197934

Browse files
committed
binder: Remove redundant ServerInbound.serverTransport field
1 parent b16da37 commit f197934

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;
@@ -551,7 +552,7 @@ public synchronized String toString() {
551552

552553
// ======================================
553554
// Client-side inbound transactions.
554-
static final class ClientInbound extends Inbound<ClientStreamListener> {
555+
static final class ClientInbound extends Inbound<ClientStreamListener, BinderClientTransport> {
555556

556557
private final boolean countsForInUse;
557558

@@ -564,7 +565,10 @@ static final class ClientInbound extends Inbound<ClientStreamListener> {
564565
private Metadata trailers;
565566

566567
ClientInbound(
567-
BinderTransport transport, Attributes attributes, int callId, boolean countsForInUse) {
568+
BinderClientTransport transport,
569+
Attributes attributes,
570+
int callId,
571+
boolean countsForInUse) {
568572
super(transport, attributes, callId);
569573
this.countsForInUse = countsForInUse;
570574
}
@@ -608,13 +612,9 @@ protected void deliverCloseAbnormal(Status status) {
608612

609613
// ======================================
610614
// Server-side inbound transactions.
611-
static final class ServerInbound extends Inbound<ServerStreamListener> {
612-
613-
private final BinderServerTransport serverTransport;
614-
615+
static final class ServerInbound extends Inbound<ServerStreamListener, BinderServerTransport> {
615616
ServerInbound(BinderServerTransport transport, Attributes attributes, int callId) {
616617
super(transport, attributes, callId);
617-
this.serverTransport = transport;
618618
}
619619

620620
@GuardedBy("this")
@@ -623,17 +623,16 @@ protected void handlePrefix(int flags, Parcel parcel) throws StatusException {
623623
String methodName = parcel.readString();
624624
Metadata headers = MetadataHelper.readMetadata(parcel, attributes);
625625

626-
StatsTraceContext statsTraceContext =
627-
serverTransport.createStatsTraceContext(methodName, headers);
626+
StatsTraceContext statsTraceContext = transport.createStatsTraceContext(methodName, headers);
628627
Outbound.ServerOutbound outbound =
629-
new Outbound.ServerOutbound(serverTransport, callId, statsTraceContext);
628+
new Outbound.ServerOutbound(transport, callId, statsTraceContext);
630629
ServerStream stream;
631630
if ((flags & TransactionUtils.FLAG_EXPECT_SINGLE_MESSAGE) != 0) {
632631
stream = new SingleMessageServerStream(this, outbound, attributes);
633632
} else {
634633
stream = new MultiMessageServerStream(this, outbound, attributes);
635634
}
636-
Status status = serverTransport.startStream(stream, methodName, headers);
635+
Status status = transport.startStream(stream, methodName, headers);
637636
if (status.isOk()) {
638637
checkNotNull(listener); // Is it ok to assume this will happen synchronously?
639638
if (transport.isReady()) {

0 commit comments

Comments
 (0)