2828import java .util .Set ;
2929import java .util .concurrent .ExecutorService ;
3030import java .util .concurrent .Executors ;
31+ import java .util .concurrent .SynchronousQueue ;
32+ import java .util .concurrent .ThreadFactory ;
33+ import java .util .concurrent .ThreadPoolExecutor ;
34+ import java .util .concurrent .TimeUnit ;
3135import java .util .logging .Level ;
3236import java .util .logging .Logger ;
3337
3943import org .hyperledger .fabric .sdk .exception .NetworkConfigurationException ;
4044import org .hyperledger .fabric .sdk .exception .ProposalException ;
4145import org .hyperledger .fabric .sdk .exception .TransactionException ;
46+ import org .hyperledger .fabric .sdk .helper .Config ;
4247import org .hyperledger .fabric .sdk .helper .Utils ;
4348import org .hyperledger .fabric .sdk .security .CryptoSuite ;
4449
4550import static java .lang .String .format ;
4651import static org .hyperledger .fabric .sdk .User .userContextCheck ;
4752
4853public class HFClient {
54+ private static final Config config = Config .getConfig ();
4955
5056 private CryptoSuite cryptoSuite ;
57+ protected final ExecutorService executorService ;
5158
5259 static {
5360
@@ -59,11 +66,6 @@ public class HFClient {
5966 }
6067 }
6168
62- private final ExecutorService executorService = Executors .newCachedThreadPool (r -> {
63- Thread t = Executors .defaultThreadFactory ().newThread (r );
64- t .setDaemon (true );
65- return t ;
66- });
6769
6870 ExecutorService getExecutorService () {
6971 return executorService ;
@@ -79,8 +81,24 @@ public User getUserContext() {
7981
8082 private User userContext ;
8183
84+ protected final ThreadFactory threadFactory = Executors .defaultThreadFactory ();
85+
86+ private static final int CLIENT_THREAD_EXECUTOR_COREPOOLSIZE = config .getClientThreadExecutorCorePoolSize ();
87+ private static final int CLIENT_THREAD_EXECUTOR_MAXIMUMPOOLSIZE = config .getClientThreadExecutorMaxiumPoolSize ();
88+ private static final long CLIENT_THREAD_EXECUTOR_KEEPALIVETIME = config .getClientThreadExecutorKeepAliveTime ();
89+ private static final TimeUnit CLIENT_THREAD_EXECUTOR_KEEPALIVETIMEUNIT = config .getClientThreadExecutorKeepAliveTimeUnit ();
90+
8291 private HFClient () {
8392
93+ executorService = new ThreadPoolExecutor (CLIENT_THREAD_EXECUTOR_COREPOOLSIZE , CLIENT_THREAD_EXECUTOR_MAXIMUMPOOLSIZE ,
94+ CLIENT_THREAD_EXECUTOR_KEEPALIVETIME , CLIENT_THREAD_EXECUTOR_KEEPALIVETIMEUNIT ,
95+ new SynchronousQueue <Runnable >(),
96+ r -> {
97+ Thread t = threadFactory .newThread (r );
98+ t .setDaemon (true );
99+ return t ;
100+ });
101+
84102 }
85103
86104 public CryptoSuite getCryptoSuite () {
@@ -120,7 +138,7 @@ public static HFClient createNewInstance() {
120138 * Configures a channel based on information loaded from a Network Config file.
121139 * Note that it is up to the caller to initialize the returned channel.
122140 *
123- * @param channelName The name of the channel to be configured
141+ * @param channelName The name of the channel to be configured
124142 * @param networkConfig The network configuration to use to configure the channel
125143 * @return The configured channel, or null if the channel is not defined in the configuration
126144 * @throws InvalidArgumentException
@@ -144,7 +162,6 @@ public Channel loadChannelFromConfig(String channelName, NetworkConfig networkCo
144162 return networkConfig .loadChannel (this , channelName );
145163 }
146164
147-
148165 /**
149166 * newChannel - already configured channel.
150167 *
@@ -188,7 +205,7 @@ public Channel newChannel(String name) throws InvalidArgumentException {
188205 */
189206
190207 public Channel newChannel (String name , Orderer orderer , ChannelConfiguration channelConfiguration ,
191- byte []... channelConfigurationSignatures ) throws TransactionException , InvalidArgumentException {
208+ byte []... channelConfigurationSignatures ) throws TransactionException , InvalidArgumentException {
192209
193210 clientCheck ();
194211 if (Utils .isNullOrEmpty (name )) {
@@ -620,7 +637,7 @@ public byte[] getChannelConfigurationSignature(ChannelConfiguration channelConfi
620637 */
621638
622639 public byte [] getUpdateChannelConfigurationSignature (UpdateChannelConfiguration updateChannelConfiguration ,
623- User signer ) throws InvalidArgumentException {
640+ User signer ) throws InvalidArgumentException {
624641
625642 clientCheck ();
626643
@@ -640,7 +657,7 @@ public byte[] getUpdateChannelConfigurationSignature(UpdateChannelConfiguration
640657 */
641658
642659 public Collection <ProposalResponse > sendInstallProposal (InstallProposalRequest installProposalRequest ,
643- Collection <Peer > peers ) throws ProposalException , InvalidArgumentException {
660+ Collection <Peer > peers ) throws ProposalException , InvalidArgumentException {
644661
645662 clientCheck ();
646663
@@ -651,7 +668,6 @@ public Collection<ProposalResponse> sendInstallProposal(InstallProposalRequest i
651668
652669 }
653670
654-
655671 private void clientCheck () throws InvalidArgumentException {
656672
657673 if (null == cryptoSuite ) {
0 commit comments