@@ -151,6 +151,26 @@ public static HFClient createNewInstance() {
151151 return new HFClient ();
152152 }
153153
154+ /**
155+ * Set sensible default grpc properties for newPeer and newOrderer. Only sets values
156+ * if they don't already exist.
157+ * @param props The properties object to apply defaults to
158+ */
159+ private void setDefaultProperties (Properties props ) {
160+ if (!props .containsKey ("grpc.NettyChannelBuilderOption.keepAliveTime" )) {
161+ props .put ("grpc.NettyChannelBuilderOption.keepAliveTime" , new Object [] {2L , TimeUnit .MINUTES });
162+ }
163+ if (!props .containsKey ("grpc.NettyChannelBuilderOption.keepAliveTimeout" )) {
164+ props .put ("grpc.NettyChannelBuilderOption.keepAliveTimeout" , new Object [] {20L , TimeUnit .SECONDS });
165+ }
166+ if (!props .containsKey ("grpc.NettyChannelBuilderOption.keepAliveTime" )) {
167+ props .put ("grpc.NettyChannelBuilderOption.keepAliveTime" , new Object [] {2L , TimeUnit .MINUTES });
168+ }
169+ if (!props .containsKey ("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls" )) {
170+ props .put ("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls" , new Object [] {true });
171+ }
172+ }
173+
154174 /**
155175 * Configures a channel based on information loaded from a Network Config file.
156176 * Note that it is up to the caller to initialize the returned channel.
@@ -394,6 +414,7 @@ public Channel deSerializeChannel(byte[] channelBytes)
394414
395415 public Peer newPeer (String name , String grpcURL , Properties properties ) throws InvalidArgumentException {
396416 clientCheck ();
417+ setDefaultProperties (properties );
397418 return Peer .createNewInstance (name , grpcURL , properties );
398419 }
399420
@@ -408,7 +429,7 @@ public Peer newPeer(String name, String grpcURL, Properties properties) throws I
408429
409430 public Peer newPeer (String name , String grpcURL ) throws InvalidArgumentException {
410431 clientCheck ();
411- return Peer .createNewInstance (name , grpcURL , null );
432+ return Peer .createNewInstance (name , grpcURL , new Properties () );
412433 }
413434
414435 /**
@@ -696,7 +717,7 @@ public User setUserContext(User userContext) throws InvalidArgumentException {
696717
697718 public Orderer newOrderer (String name , String grpcURL ) throws InvalidArgumentException {
698719 clientCheck ();
699- return newOrderer (name , grpcURL , null );
720+ return newOrderer (name , grpcURL , new Properties () );
700721 }
701722
702723 /**
@@ -745,6 +766,7 @@ public Orderer newOrderer(String name, String grpcURL) throws InvalidArgumentExc
745766
746767 public Orderer newOrderer (String name , String grpcURL , Properties properties ) throws InvalidArgumentException {
747768 clientCheck ();
769+ setDefaultProperties (properties );
748770 return Orderer .createNewInstance (name , grpcURL , properties );
749771 }
750772
0 commit comments