Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/grpc/grpc-java into fix-r…
Browse files Browse the repository at this point in the history
…ls-data
  • Loading branch information
dapengzhang0 committed Nov 18, 2021
2 parents 9f3db23 + 5a3b8e2 commit d0931c7
Show file tree
Hide file tree
Showing 80 changed files with 1,906 additions and 1,424 deletions.
7 changes: 4 additions & 3 deletions MAINTAINERS.md
Expand Up @@ -8,23 +8,24 @@ See [CONTRIBUTING.md](https://github.com/grpc/grpc-community/blob/master/CONTRIB
for general contribution guidelines.

## Maintainers (in alphabetical order)

- [dapengzhang0](https://github.com/dapengzhang0), Google LLC
- [ejona86](https://github.com/ejona86), Google LLC
- [ericgribkoff](https://github.com/ericgribkoff), Google LLC
- [ran-su](https://github.com/ran-su), Google LLC
- [sanjaypujare](https://github.com/sanjaypujare), Google LLC
- [sergiitk](https://github.com/sergiitk), Google LLC
- [srini100](https://github.com/srini100), Google LLC
- [voidzcy](https://github.com/voidzcy), Google LLC
- [temawi](https://github.com/temawi), Google LLC
- [YifeiZhuang](https://github.com/YifeiZhuang), Google LLC
- [zhangkun83](https://github.com/zhangkun83), Google LLC

## Emeritus Maintainers (in alphabetical order)
- [carl-mastrangelo](https://github.com/carl-mastrangelo), Google LLC
- [creamsoup](https://github.com/creamsoup), Google LLC
- [ericgribkoff](https://github.com/ericgribkoff), Google LLC
- [jiangtaoli2016](https://github.com/jiangtaoli2016), Google LLC
- [jtattermusch](https://github.com/jtattermusch), Google LLC
- [louiscryan](https://github.com/louiscryan), Google LLC
- [nicolasnoble](https://github.com/nicolasnoble), Google LLC
- [nmittler](https://github.com/nmittler), Google LLC
- [voidzcy](https://github.com/voidzcy), Google LLC
- [zpencer](https://github.com/zpencer), Google LLC
36 changes: 18 additions & 18 deletions README.md
Expand Up @@ -31,8 +31,8 @@ For a guided tour, take a look at the [quick start
guide](https://grpc.io/docs/languages/java/quickstart) or the more explanatory [gRPC
basics](https://grpc.io/docs/languages/java/basics).

The [examples](https://github.com/grpc/grpc-java/tree/v1.41.0/examples) and the
[Android example](https://github.com/grpc/grpc-java/tree/v1.41.0/examples/android)
The [examples](https://github.com/grpc/grpc-java/tree/v1.42.1/examples) and the
[Android example](https://github.com/grpc/grpc-java/tree/v1.42.1/examples/android)
are standalone projects that showcase the usage of gRPC.

Download
Expand All @@ -43,17 +43,17 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`:
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.41.0</version>
<version>1.42.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.41.0</version>
<version>1.42.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.41.0</version>
<version>1.42.1</version>
</dependency>
<dependency> <!-- necessary for Java 9+ -->
<groupId>org.apache.tomcat</groupId>
Expand All @@ -65,23 +65,23 @@ Download [the JARs][]. Or for Maven with non-Android, add to your `pom.xml`:

Or for Gradle with non-Android, add to your dependencies:
```gradle
implementation 'io.grpc:grpc-netty-shaded:1.41.0'
implementation 'io.grpc:grpc-protobuf:1.41.0'
implementation 'io.grpc:grpc-stub:1.41.0'
implementation 'io.grpc:grpc-netty-shaded:1.42.1'
implementation 'io.grpc:grpc-protobuf:1.42.1'
implementation 'io.grpc:grpc-stub:1.42.1'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+
```

For Android client, use `grpc-okhttp` instead of `grpc-netty-shaded` and
`grpc-protobuf-lite` instead of `grpc-protobuf`:
```gradle
implementation 'io.grpc:grpc-okhttp:1.41.0'
implementation 'io.grpc:grpc-protobuf-lite:1.41.0'
implementation 'io.grpc:grpc-stub:1.41.0'
implementation 'io.grpc:grpc-okhttp:1.42.1'
implementation 'io.grpc:grpc-protobuf-lite:1.42.1'
implementation 'io.grpc:grpc-stub:1.42.1'
compileOnly 'org.apache.tomcat:annotations-api:6.0.53' // necessary for Java 9+
```

[the JARs]:
https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.41.0
https://search.maven.org/search?q=g:io.grpc%20AND%20v:1.42.1

Development snapshots are available in [Sonatypes's snapshot
repository](https://oss.sonatype.org/content/repositories/snapshots/).
Expand Down Expand Up @@ -111,9 +111,9 @@ For protobuf-based codegen integrated with the Maven build system, you can use
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.17.3:exe:${os.detected.classifier}</protocArtifact>
<protocArtifact>com.google.protobuf:protoc:3.17.2:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.41.0:exe:${os.detected.classifier}</pluginArtifact>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.42.1:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
Expand All @@ -139,11 +139,11 @@ plugins {
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.17.3"
artifact = "com.google.protobuf:protoc:3.17.2"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.41.0'
artifact = 'io.grpc:protoc-gen-grpc-java:1.42.1'
}
}
generateProtoTasks {
Expand Down Expand Up @@ -172,11 +172,11 @@ plugins {
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.17.3"
artifact = "com.google.protobuf:protoc:3.17.2"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.41.0'
artifact = 'io.grpc:protoc-gen-grpc-java:1.42.1'
}
}
generateProtoTasks {
Expand Down
13 changes: 0 additions & 13 deletions RELEASING.md
Expand Up @@ -10,19 +10,6 @@ We deploy GRPC to Maven Central under the following systems:

Other systems may also work, but we haven't verified them.

Prerequisites
-------------

### Set Up OSSRH Account

If you haven't deployed artifacts to Maven Central before, you need to setup
your OSSRH (OSS Repository Hosting) account.
- Follow the instructions on [this
page](https://central.sonatype.org/pages/ossrh-guide.html) to set up an
account with OSSRH.
- You only need to create the account, not set up a new project
- Contact a gRPC maintainer to add your account after you have created it.

Common Variables
----------------
Many of the following commands expect release-specific variables to be set. Set
Expand Down
Expand Up @@ -44,30 +44,65 @@ private GoogleDefaultChannelCredentials() {}
* as fallback.
*/
public static ChannelCredentials create() {
ChannelCredentials nettyCredentials =
InternalNettyChannelCredentials.create(createClientFactory());
CallCredentials callCredentials;
try {
callCredentials = MoreCallCredentials.from(GoogleCredentials.getApplicationDefault());
} catch (IOException e) {
callCredentials = new FailingCallCredentials(
Status.UNAUTHENTICATED
.withDescription("Failed to get Google default credentials")
.withCause(e));
}
return CompositeChannelCredentials.create(nettyCredentials, callCredentials);
return newBuilder().build();
}

private static InternalProtocolNegotiator.ClientFactory createClientFactory() {
SslContext sslContext;
try {
sslContext = GrpcSslContexts.forClient().build();
} catch (SSLException e) {
throw new RuntimeException(e);
/**
* Returns a new instance of {@link Builder}.
*
* @since 1.42.0
*/
public static Builder newBuilder() {
return new Builder();
}

/**
* Builder for {@link GoogleDefaultChannelCredentials} instances.
*
* @since 1.42.0
*/
public static final class Builder {
private CallCredentials callCredentials;

private Builder() {}

/** Constructs GoogleDefaultChannelCredentials with a given call credential. */
public Builder callCredentials(CallCredentials callCreds) {
callCredentials = callCreds;
return this;
}

/** Builds a GoogleDefaultChannelCredentials instance. */
public ChannelCredentials build() {
ChannelCredentials nettyCredentials =
InternalNettyChannelCredentials.create(createClientFactory());
if (callCredentials != null) {
return CompositeChannelCredentials.create(nettyCredentials, callCredentials);
}
CallCredentials callCreds;
try {
callCreds = MoreCallCredentials.from(GoogleCredentials.getApplicationDefault());
} catch (IOException e) {
callCreds =
new FailingCallCredentials(
Status.UNAUTHENTICATED
.withDescription("Failed to get Google default credentials")
.withCause(e));
}
return CompositeChannelCredentials.create(nettyCredentials, callCreds);
}

private static InternalProtocolNegotiator.ClientFactory createClientFactory() {
SslContext sslContext;
try {
sslContext = GrpcSslContexts.forClient().build();
} catch (SSLException e) {
throw new RuntimeException(e);
}
return new GoogleDefaultProtocolNegotiatorFactory(
/* targetServiceAccounts= */ ImmutableList.<String>of(),
SharedResourcePool.forResource(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL),
sslContext);
}
return new GoogleDefaultProtocolNegotiatorFactory(
/* targetServiceAccounts= */ ImmutableList.<String>of(),
SharedResourcePool.forResource(HandshakerServiceChannel.SHARED_HANDSHAKER_CHANNEL),
sslContext);
}
}
Expand Up @@ -36,11 +36,13 @@
import io.grpc.ManagedChannel;
import io.grpc.Metadata;
import io.grpc.MethodDescriptor;
import io.grpc.NameResolverRegistry;
import io.grpc.Server;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptors;
import io.grpc.ServerServiceDefinition;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.testing.FakeNameResolverProvider;
import io.grpc.stub.ClientCalls;
import io.grpc.stub.ServerCalls;
import io.grpc.stub.StreamObserver;
Expand All @@ -66,6 +68,7 @@ public final class BinderChannelSmokeTest {

private static final int SLIGHTLY_MORE_THAN_ONE_BLOCK = 16 * 1024 + 100;
private static final String MSG = "Some text which will be repeated many many times";
private static final String SERVER_TARGET_URI = "fake://server";

final MethodDescriptor<String, String> method =
MethodDescriptor.newBuilder(StringMarshaller.INSTANCE, StringMarshaller.INSTANCE)
Expand All @@ -85,7 +88,7 @@ public final class BinderChannelSmokeTest {
.setType(MethodDescriptor.MethodType.BIDI_STREAMING)
.build();

AndroidComponentAddress serverAddress;
FakeNameResolverProvider fakeNameResolverProvider;
ManagedChannel channel;
AtomicReference<Metadata> headersCapture = new AtomicReference<>();

Expand Down Expand Up @@ -118,6 +121,8 @@ public void setUp() throws Exception {
TestUtils.recordRequestHeadersInterceptor(headersCapture));

AndroidComponentAddress serverAddress = HostServices.allocateService(appContext);
fakeNameResolverProvider = new FakeNameResolverProvider(SERVER_TARGET_URI, serverAddress);
NameResolverRegistry.getDefaultRegistry().register(fakeNameResolverProvider);
HostServices.configureService(serverAddress,
HostServices.serviceParamsBuilder()
.setServerFactory((service, receiver) ->
Expand All @@ -132,6 +137,7 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
channel.shutdownNow();
NameResolverRegistry.getDefaultRegistry().deregister(fakeNameResolverProvider);
HostServices.awaitServiceShutdown();
}

Expand Down Expand Up @@ -192,6 +198,12 @@ public void testStreamingCallOptionHeaders() throws Exception {
assertThat(headersCapture.get().get(GrpcUtil.TIMEOUT_KEY)).isGreaterThan(0);
}

@Test
public void testConnectViaTargetUri() throws Exception {
channel = BinderChannelBuilder.forTarget(SERVER_TARGET_URI, appContext).build();
assertThat(doCall("Hello").get()).isEqualTo("Hello");
}

private static String createLargeString(int size) {
StringBuilder sb = new StringBuilder();
while (sb.length() < size) {
Expand Down
56 changes: 44 additions & 12 deletions binder/src/main/java/io/grpc/binder/BinderChannelBuilder.java
Expand Up @@ -67,13 +67,35 @@ public final class BinderChannelBuilder
* <p>You the caller are responsible for managing the lifecycle of any channels built by the
* resulting builder. They will not be shut down automatically.
*
* @param targetAddress the {@link AndroidComponentAddress} referencing the service to bind to.
* @param directAddress the {@link AndroidComponentAddress} referencing the service to bind to.
* @param sourceContext the context to bind from (e.g. The current Activity or Application).
* @return a new builder
*/
public static BinderChannelBuilder forAddress(
AndroidComponentAddress targetAddress, Context sourceContext) {
return new BinderChannelBuilder(targetAddress, sourceContext);
AndroidComponentAddress directAddress, Context sourceContext) {
return new BinderChannelBuilder(
checkNotNull(directAddress, "directAddress"), null, sourceContext);
}

/**
* Creates a channel builder that will bind to a remote Android service, via a string
* target name which will be resolved.
*
* <p>The underlying Android binding will be torn down when the channel becomes idle. This happens
* after 30 minutes without use by default but can be configured via {@link
* ManagedChannelBuilder#idleTimeout(long, TimeUnit)} or triggered manually with {@link
* ManagedChannel#enterIdle()}.
*
* <p>You the caller are responsible for managing the lifecycle of any channels built by the
* resulting builder. They will not be shut down automatically.
*
* @param target A target uri which should resolve into an {@link AndroidComponentAddress}
* referencing the service to bind to.
* @param sourceContext the context to bind from (e.g. The current Activity or Application).
* @return a new builder
*/
public static BinderChannelBuilder forTarget(String target, Context sourceContext) {
return new BinderChannelBuilder(null, checkNotNull(target, "target"), sourceContext);
}

/**
Expand All @@ -88,7 +110,7 @@ public static BinderChannelBuilder forAddress(String name, int port) {
/**
* Always fails. Call {@link #forAddress(AndroidComponentAddress, Context)} instead.
*/
@DoNotCall("Unsupported. Use forAddress(AndroidComponentAddress, Context) instead")
@DoNotCall("Unsupported. Use forTarget(String, Context) instead")
public static BinderChannelBuilder forTarget(String target) {
throw new UnsupportedOperationException(
"call forAddress(AndroidComponentAddress, Context) instead");
Expand All @@ -104,9 +126,11 @@ public static BinderChannelBuilder forTarget(String target) {
private BindServiceFlags bindServiceFlags;

private BinderChannelBuilder(
AndroidComponentAddress targetAddress,
@Nullable AndroidComponentAddress directAddress,
@Nullable String target,
Context sourceContext) {
mainThreadExecutor = ContextCompat.getMainExecutor(sourceContext);
mainThreadExecutor =
ContextCompat.getMainExecutor(checkNotNull(sourceContext, "sourceContext"));
securityPolicy = SecurityPolicies.internalOnly();
inboundParcelablePolicy = InboundParcelablePolicy.DEFAULT;
bindServiceFlags = BindServiceFlags.DEFAULTS;
Expand All @@ -126,12 +150,20 @@ public ClientTransportFactory buildClientTransportFactory() {
}
}

managedChannelImplBuilder =
new ManagedChannelImplBuilder(
targetAddress,
targetAddress.getAuthority(),
new BinderChannelTransportFactoryBuilder(),
null);
if (directAddress != null) {
managedChannelImplBuilder =
new ManagedChannelImplBuilder(
directAddress,
directAddress.getAuthority(),
new BinderChannelTransportFactoryBuilder(),
null);
} else {
managedChannelImplBuilder =
new ManagedChannelImplBuilder(
target,
new BinderChannelTransportFactoryBuilder(),
null);
}
}

@Override
Expand Down

0 comments on commit d0931c7

Please sign in to comment.