Skip to content

Commit

Permalink
core: support user-agent in InProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
jyane committed Dec 10, 2017
1 parent 8bcb5cf commit 01828c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public ConnectionClientTransport newClientTransport(
if (closed) {
throw new IllegalStateException("The transport factory is closed.");
}
return new InProcessTransport(name, authority);
return new InProcessTransport(name, authority, userAgent);
}

@Override
Expand Down
12 changes: 9 additions & 3 deletions core/src/main/java/io/grpc/inprocess/InProcessTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.grpc.internal.ClientStream;
import io.grpc.internal.ClientStreamListener;
import io.grpc.internal.ConnectionClientTransport;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.ManagedClientTransport;
import io.grpc.internal.NoopClientStream;
import io.grpc.internal.ObjectPool;
Expand Down Expand Up @@ -66,6 +67,7 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
private final InternalLogId logId = InternalLogId.allocate(getClass().getName());
private final String name;
private final String authority;
private final String userAgent;
private ObjectPool<ScheduledExecutorService> serverSchedulerPool;
private ScheduledExecutorService serverScheduler;
private ServerTransportListener serverTransportListener;
Expand All @@ -82,9 +84,10 @@ final class InProcessTransport implements ServerTransport, ConnectionClientTrans
@GuardedBy("this")
private List<ServerStreamTracer.Factory> serverStreamTracerFactories;

public InProcessTransport(String name, String authority) {
public InProcessTransport(String name, String authority, String userAgent) {
this.name = name;
this.authority = authority;
this.userAgent = userAgent;
}

@CheckReturnValue
Expand Down Expand Up @@ -143,7 +146,7 @@ public void start(ClientStreamListener listener) {
}
};
}
return new InProcessStream(method, headers, callOptions, authority).clientStream;
return new InProcessStream(method, headers, callOptions, authority, userAgent).clientStream;
}

@Override
Expand Down Expand Up @@ -259,9 +262,12 @@ private class InProcessStream {

private InProcessStream(
MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions,
String authority) {
String authority, String userAgent) {
this.method = checkNotNull(method, "method");
this.headers = checkNotNull(headers, "headers");
headers.put(
GrpcUtil.USER_AGENT_KEY,
GrpcUtil.getGrpcUserAgent("inprocess", userAgent));
this.authority = authority;
this.clientStream = new InProcessClientStream(callOptions, headers);
this.serverStream = new InProcessServerStream(method, headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
public class InProcessTransportTest extends AbstractTransportTest {
private static final String TRANSPORT_NAME = "perfect-for-testing";
private static final String AUTHORITY = "a-testing-authority";
private static final String USER_AGENT = "a-testing-user-agent";

@Override
protected InternalServer newServer(List<ServerStreamTracer.Factory> streamTracerFactories) {
Expand All @@ -49,7 +50,7 @@ protected String testAuthority(InternalServer server) {

@Override
protected ManagedClientTransport newClientTransport(InternalServer server) {
return new InProcessTransport(TRANSPORT_NAME, testAuthority(server));
return new InProcessTransport(TRANSPORT_NAME, testAuthority(server), USER_AGENT);
}

@Override
Expand Down

0 comments on commit 01828c2

Please sign in to comment.