Skip to content

Commit

Permalink
Merge "FAB-4241 maintaining stream"
Browse files Browse the repository at this point in the history
  • Loading branch information
jimthematrix authored and Gerrit Code Review committed May 31, 2017
2 parents b1bd712 + edf315b commit fd04683
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
21 changes: 15 additions & 6 deletions src/main/java/org/hyperledger/fabric/sdk/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> cnCache = Collections.synchronizedMap(new HashMap<>());

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<?>, Class<?>> WRAPPERS_TO_PRIM
= new ImmutableMap.Builder<Class<?>, Class<?>>()
.put(Boolean.class, boolean.class)
Expand All @@ -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<Object, Object> es : props.entrySet()) {

Object methodprop = es.getKey();
Expand Down Expand Up @@ -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;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/hyperledger/fabric/sdk/HFClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public Channel newChannel(String name, Orderer orderer, ChannelConfiguration cha
* hostname verifications during TLS handshake.
* </li>
* <li>
* grpc.ManagedChannelBuilderOption.&lt;methodName&gt; where methodName is any method on
* grpc.NettyChannelBuilderOption.&lt;methodName&gt; 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.
* </li>
Expand Down Expand Up @@ -296,7 +296,7 @@ public void setUserContext(User userContext) throws InvalidArgumentException {
* hostname verifications during TLS handshake.
* </li>
* <li>
* grpc.ManagedChannelBuilderOption.&lt;methodName&gt; where methodName is any method on
* grpc.NettyChannelBuilderOption.&lt;methodName&gt; 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.
* </li>
Expand Down Expand Up @@ -357,7 +357,7 @@ public Orderer newOrderer(String name, String grpcURL) throws InvalidArgumentExc
* hostname verifications during TLS handshake.
* </li>
* <li>
* grpc.ManagedChannelBuilderOption.&lt;methodName&gt; where methodName is any method on
* grpc.NettyChannelBuilderOption.&lt;methodName&gt; 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.
* </li>
Expand Down
13 changes: 10 additions & 3 deletions src/test/java/org/hyperledger/fabric/sdkintegration/End2endIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,15 @@ private Channel constructChannel(String name, HFClient client, SampleOrg sampleO
Collection<Orderer> 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.
Expand All @@ -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);
Expand Down

0 comments on commit fd04683

Please sign in to comment.