mirror of https://github.com/grpc/grpc-java.git
core,netty: add a log id to the server and server transports
This commit is contained in:
parent
e9779d7c00
commit
209a32fd1a
|
|
@ -84,9 +84,10 @@ import javax.annotation.concurrent.GuardedBy;
|
||||||
* <p>Starting the server starts the underlying transport for servicing requests. Stopping the
|
* <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.
|
* 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 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()}. */
|
/** Executor for application processing. Safe to read after {@link #start()}. */
|
||||||
private Executor executor;
|
private Executor executor;
|
||||||
/** Safe to read after {@link #start()}. */
|
/** 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 {
|
private static class NoopListener implements ServerStreamListener {
|
||||||
@Override
|
@Override
|
||||||
public void messageRead(InputStream value) {
|
public void messageRead(InputStream value) {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ package io.grpc.internal;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
|
|
||||||
/** An inbound connection. */
|
/** 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
|
* 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
|
* eventually begin failing. New streams "eventually" begin failing because shutdown may need to
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ import io.grpc.ServerTransportFilter;
|
||||||
import io.grpc.ServiceDescriptor;
|
import io.grpc.ServiceDescriptor;
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
import io.grpc.StringMarshaller;
|
import io.grpc.StringMarshaller;
|
||||||
import io.grpc.internal.testing.CensusTestUtils.FakeCensusContextFactory;
|
|
||||||
import io.grpc.internal.testing.CensusTestUtils;
|
import io.grpc.internal.testing.CensusTestUtils;
|
||||||
|
import io.grpc.internal.testing.CensusTestUtils.FakeCensusContextFactory;
|
||||||
import io.grpc.util.MutableHandlerRegistry;
|
import io.grpc.util.MutableHandlerRegistry;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
|
|
@ -954,5 +954,10 @@ public class ServerImplTest {
|
||||||
public void shutdownNow(Status status) {
|
public void shutdownNow(Status status) {
|
||||||
listener.transportTerminated();
|
listener.transportTerminated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LogId getLogId() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ package io.grpc.netty;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import io.grpc.Status;
|
import io.grpc.Status;
|
||||||
|
import io.grpc.internal.LogId;
|
||||||
import io.grpc.internal.ServerTransport;
|
import io.grpc.internal.ServerTransport;
|
||||||
import io.grpc.internal.ServerTransportListener;
|
import io.grpc.internal.ServerTransportListener;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
|
|
@ -50,6 +51,7 @@ import java.util.logging.Logger;
|
||||||
class NettyServerTransport implements ServerTransport {
|
class NettyServerTransport implements ServerTransport {
|
||||||
private static final Logger log = Logger.getLogger(NettyServerTransport.class.getName());
|
private static final Logger log = Logger.getLogger(NettyServerTransport.class.getName());
|
||||||
|
|
||||||
|
private final LogId logId = LogId.allocate(getClass().getName());
|
||||||
private final Channel channel;
|
private final Channel channel;
|
||||||
private final ProtocolNegotiator protocolNegotiator;
|
private final ProtocolNegotiator protocolNegotiator;
|
||||||
private final int maxStreams;
|
private final int maxStreams;
|
||||||
|
|
@ -103,6 +105,11 @@ class NettyServerTransport implements ServerTransport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LogId getLogId() {
|
||||||
|
return logId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For testing purposes only.
|
* For testing purposes only.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue