Skip to content
This repository was archived by the owner on Apr 22, 2025. It is now read-only.

Commit 6431a0a

Browse files
committed
FAB-4869 remove hardcode orderer wait
Change-Id: I1e880f53c8970e2aa9193a738e7271a235303ddb Signed-off-by: rickr <cr22rc@gmail.com>
1 parent bc0e3fa commit 6431a0a

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

src/main/java/org/hyperledger/fabric/sdk/HFClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ public Orderer newOrderer(String name, String grpcURL) throws InvalidArgumentExc
353353
* grpc ManagedChannelBuilder. If more than one argument to the method is needed then the
354354
* parameters need to be supplied in an array of Objects.
355355
* </li>
356+
* <li>
357+
* ordererWaitTimeMilliSecs Time to wait in milliseconds for the
358+
* Orderer to accept requests before timing out. The default is two seconds.
359+
* </li>
356360
* </ul>
357361
* @return The orderer.
358362
* @throws InvalidArgumentException

src/main/java/org/hyperledger/fabric/sdk/Orderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Ab.BroadcastResponse sendTransaction(Common.Envelope transaction) throws Excepti
124124
OrdererClient localOrdererClient = ordererClient;
125125

126126
if (localOrdererClient == null || !localOrdererClient.isChannelActive()) {
127-
ordererClient = new OrdererClient(this, new Endpoint(url, properties).getChannelBuilder());
127+
ordererClient = new OrdererClient(this, new Endpoint(url, properties).getChannelBuilder(), properties);
128128
localOrdererClient = ordererClient;
129129
}
130130

@@ -156,7 +156,7 @@ DeliverResponse[] sendDeliver(Common.Envelope transaction) throws TransactionExc
156156

157157
logger.debug(format("Order.sendDeliver name: %s, url: %s", name, url));
158158
if (localOrdererClient == null || !localOrdererClient.isChannelActive()) {
159-
localOrdererClient = new OrdererClient(this, new Endpoint(url, properties).getChannelBuilder());
159+
localOrdererClient = new OrdererClient(this, new Endpoint(url, properties).getChannelBuilder(), properties);
160160
ordererClient = localOrdererClient;
161161
}
162162

src/main/java/org/hyperledger/fabric/sdk/OrdererClient.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.util.ArrayList;
1818
import java.util.List;
19+
import java.util.Properties;
1920
import java.util.concurrent.CountDownLatch;
2021
import java.util.concurrent.TimeUnit;
2122

@@ -37,23 +38,39 @@
3738
* Sample client code that makes gRPC calls to the server.
3839
*/
3940
class OrdererClient {
41+
private static final long ORDERER_WAIT_TIME = 2000L;
4042
private final String channelName;
4143
private final ManagedChannelBuilder channelBuilder;
4244
private boolean shutdown = false;
4345
private static final Log logger = LogFactory.getLog(OrdererClient.class);
4446
private ManagedChannel managedChannel = null;
4547
private final String name;
4648
private final String url;
49+
private final long ordererWaitTimeMilliSecs;
4750

4851
/**
4952
* Construct client for accessing Orderer server using the existing managedChannel.
5053
*/
51-
OrdererClient(Orderer orderer, ManagedChannelBuilder<?> channelBuilder) {
54+
OrdererClient(Orderer orderer, ManagedChannelBuilder<?> channelBuilder, Properties properties) {
5255

5356
this.channelBuilder = channelBuilder;
5457
name = orderer.getName();
5558
url = orderer.getUrl();
5659
channelName = orderer.getChannel().getName();
60+
61+
if (null == properties) {
62+
63+
ordererWaitTimeMilliSecs = ORDERER_WAIT_TIME;
64+
65+
} else {
66+
67+
String ordererWaitTimeMilliSecsString = properties.getProperty("ordererWaitTimeMilliSecs", Long.toString(ORDERER_WAIT_TIME));
68+
69+
ordererWaitTimeMilliSecs = Long.getLong(ordererWaitTimeMilliSecsString, ORDERER_WAIT_TIME);
70+
71+
}
72+
73+
5774
}
5875

5976
synchronized void shutdown(boolean force) {
@@ -141,20 +158,19 @@ public void onCompleted() {
141158

142159
nso.onNext(envelope);
143160

144-
try {
145-
if (!finishLatch.await(2, TimeUnit.MINUTES)) {
146-
TransactionException ste = new TransactionException("Send transactions failed. Reason: timeout");
147-
logger.error("sendTransaction error " + ste.getMessage(), ste);
148-
throw ste;
149-
}
150-
151-
if (throwable[0] != null) {
152-
//get full stack trace
153-
TransactionException ste = new TransactionException("Send transactions failed. Reason: " + throwable[0].getMessage(), throwable[0]);
154-
logger.error("sendTransaction error " + ste.getMessage(), ste);
155-
throw ste;
156-
}
157-
logger.debug("Done waiting for reply! Got:" + ret[0]);
161+
try {
162+
if (!finishLatch.await(ordererWaitTimeMilliSecs, TimeUnit.MILLISECONDS)) {
163+
TransactionException ste = new TransactionException("Send transactions failed. Reason: timeout");
164+
logger.error("sendTransaction error " + ste.getMessage(), ste);
165+
throw ste;
166+
}
167+
if (throwable[0] != null) {
168+
//get full stack trace
169+
TransactionException ste = new TransactionException("Send transactions failed. Reason: " + throwable[0].getMessage(), throwable[0]);
170+
logger.error("sendTransaction error " + ste.getMessage(), ste);
171+
throw ste;
172+
}
173+
logger.debug("Done waiting for reply! Got:" + ret[0]);
158174

159175
} catch (InterruptedException e) {
160176
logger.error(e);
@@ -254,7 +270,7 @@ public void onCompleted() {
254270
//nso.onCompleted();
255271

256272
try {
257-
if (!finishLatch.await(2, TimeUnit.MINUTES)) {
273+
if (!finishLatch.await(ordererWaitTimeMilliSecs, TimeUnit.MILLISECONDS)) {
258274
TransactionException ex = new TransactionException("sendDeliver time exceeded for orderer");
259275
logger.error(ex.getMessage(), ex);
260276
throw ex;

0 commit comments

Comments
 (0)