Skip to content

Commit 096c4d9

Browse files
authored
Javadoc and rename BinderServerTransport's init method. (#12427)
Call this `start()` to match the other transports and so readers know this is way more than a setter.
1 parent 7ea4744 commit 096c4d9

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public synchronized boolean handleTransaction(int code, Parcel parcel) {
185185
streamTracerFactories,
186186
OneWayBinderProxy.IDENTITY_DECORATOR,
187187
callbackBinder);
188-
transport.setServerTransportListener(listener.transportCreated(transport));
188+
transport.start(listener.transportCreated(transport));
189189
return true;
190190
}
191191
}

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
*/
1616
package io.grpc.binder.internal;
1717

18+
import static com.google.common.base.Preconditions.checkNotNull;
19+
import static com.google.common.base.Preconditions.checkState;
20+
1821
import android.os.IBinder;
1922
import com.google.errorprone.annotations.concurrent.GuardedBy;
2023
import io.grpc.Attributes;
@@ -57,9 +60,17 @@ public BinderServerTransport(
5760
setOutgoingBinder(OneWayBinderProxy.wrap(callbackBinder, getScheduledExecutorService()));
5861
}
5962

60-
public synchronized void setServerTransportListener(
61-
ServerTransportListener serverTransportListener) {
62-
this.serverTransportListener = serverTransportListener;
63+
/**
64+
* Initializes this transport instance.
65+
*
66+
* <p>Must be called exactly once, even if {@link #shutdown} or {@link #shutdownNow} was called
67+
* first.
68+
*
69+
* @param serverTransportListener where this transport will report events
70+
*/
71+
public synchronized void start(ServerTransportListener serverTransportListener) {
72+
checkState(this.serverTransportListener == null, "Already started!");
73+
this.serverTransportListener = checkNotNull(serverTransportListener, "serverTransportListener");
6374
if (isShutdown()) {
6475
setState(TransportState.SHUTDOWN_TERMINATED);
6576
notifyTerminated();

binder/src/test/java/io/grpc/binder/internal/BinderServerTransportTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void setUp() throws Exception {
7474
public void testSetupTransactionFailureCausesMultipleShutdowns_b153460678() throws Exception {
7575
// Make the binder fail the setup transaction.
7676
when(mockBinder.transact(anyInt(), any(Parcel.class), isNull(), anyInt())).thenReturn(false);
77-
transport.setServerTransportListener(transportListener);
77+
transport.start(transportListener);
7878

7979
// Now shut it down.
8080
transport.shutdownNow(Status.UNKNOWN.withDescription("reasons"));

0 commit comments

Comments
 (0)