core,netty: add a log id to the server and server transports

This commit is contained in:
Carl Mastrangelo 2016-12-05 09:47:35 -08:00 committed by GitHub
parent e9779d7c00
commit 209a32fd1a
4 changed files with 21 additions and 3 deletions

View File

@ -84,9 +84,10 @@ import javax.annotation.concurrent.GuardedBy;
* <p>Starting the server starts the underlying transport for servicing requests. Stopping the
* server stops servicing new requests and waits for all connections to terminate.
*/
public final class ServerImpl extends io.grpc.Server {
public final class ServerImpl extends io.grpc.Server implements WithLogId {
private static final ServerStreamListener NOOP_LISTENER = new NoopListener();
private final LogId logId = LogId.allocate(getClass().getName());
/** Executor for application processing. Safe to read after {@link #start()}. */
private Executor executor;
/** Safe to read after {@link #start()}. */
@ -483,6 +484,11 @@ public final class ServerImpl extends io.grpc.Server {
}
}
@Override
public LogId getLogId() {
return logId;
}
private static class NoopListener implements ServerStreamListener {
@Override
public void messageRead(InputStream value) {

View File

@ -34,7 +34,7 @@ package io.grpc.internal;
import io.grpc.Status;
/** An inbound connection. */
public interface ServerTransport {
public interface ServerTransport extends WithLogId {
/**
* Initiates an orderly shutdown of the transport. Existing streams continue, but new streams will
* eventually begin failing. New streams "eventually" begin failing because shutdown may need to

View File

@ -77,8 +77,8 @@ import io.grpc.ServerTransportFilter;
import io.grpc.ServiceDescriptor;
import io.grpc.Status;
import io.grpc.StringMarshaller;
import io.grpc.internal.testing.CensusTestUtils.FakeCensusContextFactory;
import io.grpc.internal.testing.CensusTestUtils;
import io.grpc.internal.testing.CensusTestUtils.FakeCensusContextFactory;
import io.grpc.util.MutableHandlerRegistry;
import org.junit.After;
@ -954,5 +954,10 @@ public class ServerImplTest {
public void shutdownNow(Status status) {
listener.transportTerminated();
}
@Override
public LogId getLogId() {
throw new UnsupportedOperationException();
}
}
}

View File

@ -34,6 +34,7 @@ package io.grpc.netty;
import com.google.common.base.Preconditions;
import io.grpc.Status;
import io.grpc.internal.LogId;
import io.grpc.internal.ServerTransport;
import io.grpc.internal.ServerTransportListener;
import io.netty.channel.Channel;
@ -50,6 +51,7 @@ import java.util.logging.Logger;
class NettyServerTransport implements ServerTransport {
private static final Logger log = Logger.getLogger(NettyServerTransport.class.getName());
private final LogId logId = LogId.allocate(getClass().getName());
private final Channel channel;
private final ProtocolNegotiator protocolNegotiator;
private final int maxStreams;
@ -103,6 +105,11 @@ class NettyServerTransport implements ServerTransport {
}
}
@Override
public LogId getLogId() {
return logId;
}
/**
* For testing purposes only.
*/