Skip to content

Commit

Permalink
get rid of public ServerImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
dapengzhang0 committed Aug 13, 2018
1 parent 2b60ccb commit ef44f10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
19 changes: 2 additions & 17 deletions core/src/main/java/io/grpc/internal/ServerImpl.java
Expand Up @@ -114,16 +114,14 @@ public final class ServerImpl extends io.grpc.Server implements Instrumented<Ser
private final Channelz channelz;
private final CallTracer serverCallTracer;

private ServerListener serverListener;

/**
* Construct a server.
*
* @param builder builder with configuration for server
* @param transportServer transport server that will create new incoming transports
* @param rootContext context that callbacks for new RPCs should be derived from
*/
public ServerImpl(
ServerImpl(
AbstractServerImplBuilder<?> builder,
InternalServer transportServer,
Context rootContext) {
Expand Down Expand Up @@ -162,26 +160,13 @@ public ServerImpl start() throws IOException {
checkState(!started, "Already started");
checkState(!shutdown, "Shutting down");
// Start and wait for any port to actually be bound.
serverListener = new ServerListenerImpl();
transportServer.start(serverListener);
transportServer.start(new ServerListenerImpl());
executor = Preconditions.checkNotNull(executorPool.getObject(), "executor");
started = true;
return this;
}
}

/**
* Returns the ServerListener that the server started with. Never null.
*
* @throws IllegalStateException if called before {@line #start()} is done.
*/
public ServerListener getServerListener() {
synchronized (lock) {
checkState(started, "Not started");
}
return serverListener;
}

@Override
public int getPort() {
synchronized (lock) {
Expand Down
11 changes: 6 additions & 5 deletions servlet/src/main/java/io/grpc/servlet/ServerBuilder.java
Expand Up @@ -29,7 +29,6 @@
import io.grpc.internal.Instrumented;
import io.grpc.internal.InternalServer;
import io.grpc.internal.LogId;
import io.grpc.internal.ServerImpl;
import io.grpc.internal.ServerListener;
import io.grpc.internal.ServerTransport;
import io.grpc.internal.ServerTransportListener;
Expand All @@ -50,6 +49,7 @@ public final class ServerBuilder extends AbstractServerImplBuilder<ServerBuilder
private ScheduledExecutorService scheduledExecutorService;
private boolean internalCaller;
private boolean usingCustomScheduler;
private ServerListener serverListener;

/**
* Builds a gRPC server that can run as a servlet.
Expand All @@ -69,10 +69,9 @@ public Server build() {
}

ServerTransportListener buildAndStart() {
ServerImpl server;
try {
internalCaller = true;
server = (ServerImpl) build().start();
build().start();
internalCaller = false;
} catch (IOException e) {
// actually this should never happen
Expand All @@ -88,12 +87,14 @@ ServerTransportListener buildAndStart() {
// container does.
ServerTransportImpl serverTransport =
new ServerTransportImpl(scheduledExecutorService, usingCustomScheduler);
return server.getServerListener().transportCreated(serverTransport);
return serverListener.transportCreated(serverTransport);
}

@Override
protected InternalServer buildTransportServer(List<Factory> streamTracerFactories) {
return new InternalServerImpl();
InternalServerImpl internalServer = new InternalServerImpl();
serverListener = internalServer.serverListener;
return internalServer;
}

@Override
Expand Down

0 comments on commit ef44f10

Please sign in to comment.