From edf315b889648e76a2ebefb7cbc875685544f66f Mon Sep 17 00:00:00 2001 From: rickr Date: Tue, 30 May 2017 22:55:35 -0400 Subject: [PATCH] FAB-4241 maintaining stream java SDK - maintaining stream b/w SDK and peer Enable http/2 keepalive Change-Id: Iaf418df7d0be7726c1403807af818765ff0a8ab7 Signed-off-by: rickr --- .../org/hyperledger/fabric/sdk/Endpoint.java | 21 +++++++++++++------ .../org/hyperledger/fabric/sdk/HFClient.java | 6 +++--- .../fabric/sdkintegration/End2endIT.java | 13 +++++++++--- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/hyperledger/fabric/sdk/Endpoint.java b/src/main/java/org/hyperledger/fabric/sdk/Endpoint.java index f6bc017c..11a02961 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/Endpoint.java +++ b/src/main/java/org/hyperledger/fabric/sdk/Endpoint.java @@ -56,7 +56,7 @@ class Endpoint { private final String addr; private final int port; private final String url; - private ManagedChannelBuilder channelBuilder = null; + private NettyChannelBuilder channelBuilder = null; private final static Map cnCache = Collections.synchronizedMap(new HashMap<>()); @@ -129,13 +129,13 @@ class Endpoint { try { if (protocol.equalsIgnoreCase("grpc")) { - this.channelBuilder = ManagedChannelBuilder.forAddress(addr, port) + this.channelBuilder = NettyChannelBuilder.forAddress(addr, port) .usePlaintext(true); addNettyBuilderProps(channelBuilder, properties); } else if (protocol.equalsIgnoreCase("grpcs")) { if (Utils.isNullOrEmpty(pem)) { // use root certificate - this.channelBuilder = ManagedChannelBuilder.forAddress(addr, port); + this.channelBuilder = NettyChannelBuilder.forAddress(addr, port); addNettyBuilderProps(channelBuilder, properties); } else { try { @@ -171,7 +171,7 @@ class Endpoint { } - private final static Pattern methodPat = Pattern.compile("grpc\\.ManagedChannelBuilderOption\\.([^.]*)$"); + private final static Pattern methodPat = Pattern.compile("grpc\\.NettyChannelBuilderOption\\.([^.]*)$"); private final static Map, Class> WRAPPERS_TO_PRIM = new ImmutableMap.Builder, Class>() .put(Boolean.class, boolean.class) @@ -185,12 +185,13 @@ class Endpoint { .put(Void.class, void.class) .build(); - private void addNettyBuilderProps(ManagedChannelBuilder channelBuilder, Properties props) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { + private void addNettyBuilderProps(NettyChannelBuilder channelBuilder, Properties props) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { if (props == null) { return; } + for (Map.Entry es : props.entrySet()) { Object methodprop = es.getKey(); @@ -235,7 +236,15 @@ private void addNettyBuilderProps(ManagedChannelBuilder channelBuilder, Prope if (null != unwrapped) { classParms[i] = unwrapped; } else { - classParms[i] = oparm.getClass(); + + Class clz = oparm.getClass(); + + Class ecz = clz.getEnclosingClass(); + if (null != ecz && ecz.isEnum()) { + clz = ecz; + } + + classParms[i] = clz; } } diff --git a/src/main/java/org/hyperledger/fabric/sdk/HFClient.java b/src/main/java/org/hyperledger/fabric/sdk/HFClient.java index 833b361d..d074c677 100644 --- a/src/main/java/org/hyperledger/fabric/sdk/HFClient.java +++ b/src/main/java/org/hyperledger/fabric/sdk/HFClient.java @@ -152,7 +152,7 @@ public Channel newChannel(String name, Orderer orderer, ChannelConfiguration cha * hostname verifications during TLS handshake. * *
  • - * grpc.ManagedChannelBuilderOption.<methodName> where methodName is any method on + * grpc.NettyChannelBuilderOption.<methodName> where methodName is any method on * grpc ManagedChannelBuilder. If more than one argument to the method is needed then the * parameters need to be supplied in an array of Objects. *
  • @@ -296,7 +296,7 @@ public void setUserContext(User userContext) throws InvalidArgumentException { * hostname verifications during TLS handshake. * *
  • - * grpc.ManagedChannelBuilderOption.<methodName> where methodName is any method on + * grpc.NettyChannelBuilderOption.<methodName> where methodName is any method on * grpc ManagedChannelBuilder. If more than one argument to the method is needed then the * parameters need to be supplied in an array of Objects. *
  • @@ -357,7 +357,7 @@ public Orderer newOrderer(String name, String grpcURL) throws InvalidArgumentExc * hostname verifications during TLS handshake. * *
  • - * grpc.ManagedChannelBuilderOption.<methodName> where methodName is any method on + * grpc.NettyChannelBuilderOption.<methodName> where methodName is any method on * grpc ManagedChannelBuilder. If more than one argument to the method is needed then the * parameters need to be supplied in an array of Objects. *
  • diff --git a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java index a5a734b0..438680d2 100644 --- a/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java +++ b/src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java @@ -545,8 +545,15 @@ private Channel constructChannel(String name, HFClient client, SampleOrg sampleO Collection orderers = new LinkedList<>(); for (String orderName : sampleOrg.getOrdererNames()) { + + Properties ordererProperties = testConfig.getOrdererProperties(orderName); + + //example of setting keepAlive to avoid timeouts on inactive http2 connections. + //calls: NettyChannelBuilder.enableKeepAlive(true, 1, TimeUnit.SECONDS, 1, TimeUnit.SECONDS); + ordererProperties.put("grpc.NettyChannelBuilderOption.enableKeepAlive", new Object[] {true, 1L, TimeUnit.SECONDS, 1L, TimeUnit.SECONDS}); + orderers.add(client.newOrderer(orderName, sampleOrg.getOrdererLocation(orderName), - testConfig.getOrdererProperties(orderName))); + ordererProperties)); } //Just pick the first orderer in the list to create the channel. @@ -571,8 +578,8 @@ private Channel constructChannel(String name, HFClient client, SampleOrg sampleO if (peerProperties == null) { peerProperties = new Properties(); } - //Example of setting specific options on grpc's ManagedChannelBuilder - peerProperties.put("grpc.ManagedChannelBuilderOption.maxInboundMessageSize", 9000000); + //Example of setting specific options on grpc's NettyChannelBuilder + peerProperties.put("grpc.NettyChannelBuilderOption.maxInboundMessageSize", 9000000); Peer peer = client.newPeer(peerName, peerLocation, peerProperties); newChannel.joinPeer(peer);