First attempt at supporting builds with Java 11
Includes:
- Bump protobuf to 3.8.0 and grpc-java to 1.21.0 (along with transitive
dependencies such as Netty)
- Add jaxb_api at compile time when needed (removed in JDK 11)
- Bump Bnd to 4.1 (adds support for Java 11)
To build with JDK 11, uncomment lines in .bazelrc.
Tested with Bazel 0.26.0.
Change-Id: Ib8e0c7310eacf97328762606e57c01e4834e5565
diff --git a/protocols/grpc/ctl/BUILD b/protocols/grpc/ctl/BUILD
index 16676c5..77239e4 100644
--- a/protocols/grpc/ctl/BUILD
+++ b/protocols/grpc/ctl/BUILD
@@ -1,6 +1,7 @@
COMPILE_DEPS = CORE_DEPS + [
"//protocols/grpc/api:onos-protocols-grpc-api",
- "//lib:io_grpc_grpc_core_context",
+ "//lib:io_grpc_grpc_api_context",
+ "//lib:io_grpc_grpc_core_internal",
"//lib:io_grpc_grpc_netty",
"//lib:io_grpc_grpc_protobuf_lite",
"//lib:com_google_protobuf_protobuf_java",
diff --git a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcChannelControllerImpl.java b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcChannelControllerImpl.java
index 3be7706..9e2321e 100644
--- a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcChannelControllerImpl.java
+++ b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcChannelControllerImpl.java
@@ -17,8 +17,12 @@
package org.onosproject.grpc.ctl;
import com.google.common.util.concurrent.Striped;
+import io.grpc.LoadBalancerRegistry;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
+import io.grpc.NameResolverRegistry;
+import io.grpc.internal.DnsNameResolverProvider;
+import io.grpc.internal.PickFirstLoadBalancerProvider;
import io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.NettyChannelBuilder;
import io.netty.handler.ssl.SslContext;
@@ -68,6 +72,11 @@
private static final int DEFAULT_MAX_INBOUND_MSG_SIZE = 256; // Megabytes.
private static final int MEGABYTES = 1024 * 1024;
+ private static final PickFirstLoadBalancerProvider PICK_FIRST_LOAD_BALANCER_PROVIDER =
+ new PickFirstLoadBalancerProvider();
+ private static final DnsNameResolverProvider DNS_NAME_RESOLVER_PROVIDER =
+ new DnsNameResolverProvider();
+
@Reference(cardinality = ReferenceCardinality.MANDATORY)
protected ComponentConfigService componentConfigService;
@@ -89,6 +98,10 @@
componentConfigService.registerProperties(getClass());
channels = new ConcurrentHashMap<>();
interceptors = new ConcurrentHashMap<>();
+ LoadBalancerRegistry.getDefaultRegistry()
+ .register(PICK_FIRST_LOAD_BALANCER_PROVIDER);
+ NameResolverRegistry.getDefaultRegistry()
+ .register(DNS_NAME_RESOLVER_PROVIDER);
log.info("Started");
}
@@ -105,6 +118,10 @@
@Deactivate
public void deactivate() {
+ LoadBalancerRegistry.getDefaultRegistry()
+ .deregister(PICK_FIRST_LOAD_BALANCER_PROVIDER);
+ NameResolverRegistry.getDefaultRegistry()
+ .register(DNS_NAME_RESOLVER_PROVIDER);
componentConfigService.unregisterProperties(getClass(), false);
channels.values().forEach(ManagedChannel::shutdownNow);
channels.clear();
@@ -162,9 +179,12 @@
final boolean useTls = channelUri.getScheme().equals(GRPCS);
final NettyChannelBuilder channelBuilder = NettyChannelBuilder
- .forAddress(channelUri.getHost(),
- channelUri.getPort())
- .maxInboundMessageSize(DEFAULT_MAX_INBOUND_MSG_SIZE * MEGABYTES);
+ .forAddress(channelUri.getHost(), channelUri.getPort())
+ .nameResolverFactory(DNS_NAME_RESOLVER_PROVIDER)
+ .defaultLoadBalancingPolicy(
+ PICK_FIRST_LOAD_BALANCER_PROVIDER.getPolicyName())
+ .maxInboundMessageSize(
+ DEFAULT_MAX_INBOUND_MSG_SIZE * MEGABYTES);
if (useTls) {
try {