|
16 | 16 |
|
17 | 17 | import java.util.ArrayList;
|
18 | 18 | import java.util.List;
|
| 19 | +import java.util.Properties; |
19 | 20 | import java.util.concurrent.CountDownLatch;
|
20 | 21 | import java.util.concurrent.TimeUnit;
|
21 | 22 |
|
|
37 | 38 | * Sample client code that makes gRPC calls to the server.
|
38 | 39 | */
|
39 | 40 | class OrdererClient {
|
| 41 | + private static final long ORDERER_WAIT_TIME = 2000L; |
40 | 42 | private final String channelName;
|
41 | 43 | private final ManagedChannelBuilder channelBuilder;
|
42 | 44 | private boolean shutdown = false;
|
43 | 45 | private static final Log logger = LogFactory.getLog(OrdererClient.class);
|
44 | 46 | private ManagedChannel managedChannel = null;
|
45 | 47 | private final String name;
|
46 | 48 | private final String url;
|
| 49 | + private final long ordererWaitTimeMilliSecs; |
47 | 50 |
|
48 | 51 | /**
|
49 | 52 | * Construct client for accessing Orderer server using the existing managedChannel.
|
50 | 53 | */
|
51 |
| - OrdererClient(Orderer orderer, ManagedChannelBuilder<?> channelBuilder) { |
| 54 | + OrdererClient(Orderer orderer, ManagedChannelBuilder<?> channelBuilder, Properties properties) { |
52 | 55 |
|
53 | 56 | this.channelBuilder = channelBuilder;
|
54 | 57 | name = orderer.getName();
|
55 | 58 | url = orderer.getUrl();
|
56 | 59 | 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 | + |
57 | 74 | }
|
58 | 75 |
|
59 | 76 | synchronized void shutdown(boolean force) {
|
@@ -141,20 +158,19 @@ public void onCompleted() {
|
141 | 158 |
|
142 | 159 | nso.onNext(envelope);
|
143 | 160 |
|
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]); |
158 | 174 |
|
159 | 175 | } catch (InterruptedException e) {
|
160 | 176 | logger.error(e);
|
@@ -254,7 +270,7 @@ public void onCompleted() {
|
254 | 270 | //nso.onCompleted();
|
255 | 271 |
|
256 | 272 | try {
|
257 |
| - if (!finishLatch.await(2, TimeUnit.MINUTES)) { |
| 273 | + if (!finishLatch.await(ordererWaitTimeMilliSecs, TimeUnit.MILLISECONDS)) { |
258 | 274 | TransactionException ex = new TransactionException("sendDeliver time exceeded for orderer");
|
259 | 275 | logger.error(ex.getMessage(), ex);
|
260 | 276 | throw ex;
|
|
0 commit comments