diff --git a/Changelog.md b/Changelog.md
index c050e56d4..469a45f29 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,3 +1,27 @@
+### V1.2.2 (2018-08-29)
+
+* Updates
+
+1. 增加错误提示。
+2. 默认连接时间从3秒改到30秒。
+3. TestOk中的Future设置超时时间。
+4. 交易轮询线程池可以配置
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
### V1.2.1 (2018-07-02)
* Added
diff --git a/release_note.txt b/release_note.txt
index a994b388f..672859f71 100644
--- a/release_note.txt
+++ b/release_note.txt
@@ -1 +1 @@
-V1.2.1
+V1.2.2
diff --git a/src/main/java/org/bcos/channel/client/Service.java b/src/main/java/org/bcos/channel/client/Service.java
index 84b363f2a..a05d72184 100644
--- a/src/main/java/org/bcos/channel/client/Service.java
+++ b/src/main/java/org/bcos/channel/client/Service.java
@@ -239,7 +239,7 @@ public void run() throws Exception {
{
logger.error("connectSeconds = " + connectSeconds);
logger.error("init ChannelService fail!");
- throw new Exception();
+ throw new Exception("Init ChannelService fail!Please Refer To Link Below:https://github.com/FISCO-BCOS/web3sdk/wiki/web3sdk-debug");
}
}
}
@@ -489,7 +489,7 @@ public void run(Timeout timeout) throws Exception {
EthereumResponse response = new EthereumResponse();
response.setErrorCode(-1);
- response.setErrorMessage("system error");
+ response.setErrorMessage(e.getMessage()+"Please Refer To Link Below:https://github.com/FISCO-BCOS/web3sdk/wiki/web3sdk-debug");
response.setContent("");
response.setMessageID(request.getMessageID());
@@ -905,7 +905,7 @@ public void setThreadPool(ThreadPoolTaskExecutor threadPool) {
this.threadPool = threadPool;
}
- private Integer connectSeconds = 3;
+ private Integer connectSeconds = 30;
private Integer connectSleepPerMillis = 1;
private String orgID;
private ConcurrentHashMap allChannelConnections;
diff --git a/src/main/java/org/bcos/web3j/protocol/channel/ChannelEthereumService.java b/src/main/java/org/bcos/web3j/protocol/channel/ChannelEthereumService.java
index 5571196ad..5d352aec5 100644
--- a/src/main/java/org/bcos/web3j/protocol/channel/ChannelEthereumService.java
+++ b/src/main/java/org/bcos/web3j/protocol/channel/ChannelEthereumService.java
@@ -1,7 +1,5 @@
package org.bcos.web3j.protocol.channel;
-import java.io.IOException;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -12,6 +10,8 @@
import org.bcos.web3j.protocol.core.Request;
import org.bcos.web3j.protocol.core.Response;
+import java.io.IOException;
+
/**
* Channel implementation of our services API.
*/
@@ -52,8 +52,23 @@ public T send(
logger.debug("Ethereum Request:{} {}", ethereumRequest.getMessageID(), objectMapper.writeValueAsString(request));
logger.debug("Ethereum Response:{} {} {}", ethereumRequest.getMessageID(), response.getErrorCode(), response.getContent());
-
- return objectMapper.readValue(response.getContent(), responseType);
+ if(response.getErrorCode() == 0)
+ {
+ try {
+ T t = objectMapper.readValue(response.getContent(), responseType);
+ if (t.getError() != null)
+ {
+ throw new IOException(t.getError().getMessage());
+ }
+ return t;
+ }
+ catch(Exception e) {
+ throw new IOException(response.getContent());
+ }
+ }
+ else {
+ throw new IOException(response.getErrorMessage());
+ }
}
public org.bcos.channel.client.Service getChannelService() {
diff --git a/src/main/java/org/bcos/web3j/protocol/core/JsonRpc2_0Web3j.java b/src/main/java/org/bcos/web3j/protocol/core/JsonRpc2_0Web3j.java
index bb5342235..d2a6cf2a5 100644
--- a/src/main/java/org/bcos/web3j/protocol/core/JsonRpc2_0Web3j.java
+++ b/src/main/java/org/bcos/web3j/protocol/core/JsonRpc2_0Web3j.java
@@ -10,6 +10,8 @@
import org.bcos.web3j.protocol.core.methods.request.ProofMerkle;
import org.bcos.web3j.protocol.core.methods.response.*;
+import org.bcos.web3j.utils.BlockLimit;
+import org.bcos.web3j.utils.Web3AsyncThreadPoolSize;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.Observable;
@@ -108,7 +110,8 @@ public JsonRpc2_0Web3j(
this.web3jService = web3jService;
this.web3jRx = new JsonRpc2_0Rx(this, scheduledExecutorService);
this.blockTime = pollingInterval;
- ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
+ ExecutorService cachedThreadPool = Executors.newFixedThreadPool(Web3AsyncThreadPoolSize.web3AsyncPoolSize);
+
cachedThreadPool.execute(new Runnable() {
public void run() {
while (true) {
@@ -135,7 +138,7 @@ public BigInteger getBlockNumberCache() {
logger.error("Exception: " + e);
}
}
- return getBlockNumber().add(new BigInteger("500"));
+ return getBlockNumber().add(new BigInteger(BlockLimit.blockLimit.toString()));
}
@Override
diff --git a/src/main/java/org/bcos/web3j/utils/Async.java b/src/main/java/org/bcos/web3j/utils/Async.java
index bcf13cd3a..a763db0dc 100644
--- a/src/main/java/org/bcos/web3j/utils/Async.java
+++ b/src/main/java/org/bcos/web3j/utils/Async.java
@@ -1,5 +1,11 @@
package org.bcos.web3j.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.stereotype.Component;
+
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
@@ -9,9 +15,15 @@
/**
* Async task facilitation.
*/
+@Component
public class Async {
-
- private static final Executor executor = Executors.newCachedThreadPool();
+ static Logger logger = LoggerFactory.getLogger(Async.class);
+ private static Executor executor = Executors.newFixedThreadPool(Web3AsyncThreadPoolSize.web3AsyncPoolSize);
+ ;
+ public Async(ThreadPoolTaskExecutor pool){
+ logger.info("Async:ThreadPoolTaskExecutor getCorePoolSize " + pool.getCorePoolSize() + " getMaxPoolSize " + pool.getMaxPoolSize());
+ Async.executor = pool;
+ }
public static CompletableFuture run(Callable callable) {
CompletableFuture result = new CompletableFuture<>();
@@ -23,7 +35,7 @@ public static CompletableFuture run(Callable callable) {
} catch (Throwable e) {
result.completeExceptionally(e);
}
- }, executor);
+ }, Async.executor);
return result;
}
diff --git a/src/main/java/org/bcos/web3j/utils/BlockLimit.java b/src/main/java/org/bcos/web3j/utils/BlockLimit.java
new file mode 100644
index 000000000..eb74e1b70
--- /dev/null
+++ b/src/main/java/org/bcos/web3j/utils/BlockLimit.java
@@ -0,0 +1,19 @@
+package org.bcos.web3j.utils;
+
+/**
+ * Created by mingzhenliu on 2018/8/24.
+ */
+public class BlockLimit {
+ public static Integer blockLimit = 500;
+ public BlockLimit(int blockLimit){
+ this.blockLimit = blockLimit;
+ }
+ public int getBlockLimit() {
+ return blockLimit;
+ }
+
+ public void setBlockLimit(int blockLimit) {
+ BlockLimit.blockLimit = blockLimit;
+ }
+}
+
diff --git a/src/main/java/org/bcos/web3j/utils/Web3AsyncThreadPoolSize.java b/src/main/java/org/bcos/web3j/utils/Web3AsyncThreadPoolSize.java
new file mode 100644
index 000000000..1dff0b138
--- /dev/null
+++ b/src/main/java/org/bcos/web3j/utils/Web3AsyncThreadPoolSize.java
@@ -0,0 +1,14 @@
+package org.bcos.web3j.utils;
+
+/**
+ * Created by mingzhenliu on 2018/8/24.
+ */
+public class Web3AsyncThreadPoolSize {
+ public static Integer web3AsyncPoolSize = 100;
+ public static Integer web3AsyncCorePoolSize = 50;
+ public Web3AsyncThreadPoolSize(int web3AsyncPoolSize,int web3AsyncCorePoolSize){
+ this.web3AsyncPoolSize = web3AsyncPoolSize;
+ this.web3AsyncCorePoolSize = web3AsyncCorePoolSize;
+ }
+}
+
diff --git a/src/test/java/org/bcos/channel/test/Ethereum.java b/src/test/java/org/bcos/channel/test/Ethereum.java
index fa15e1dc3..db7ffe209 100644
--- a/src/test/java/org/bcos/channel/test/Ethereum.java
+++ b/src/test/java/org/bcos/channel/test/Ethereum.java
@@ -30,7 +30,6 @@ public static void main(String[] args) throws Exception {
Service service = context.getBean(Service.class);
service.run();
- Thread.sleep(3000);
System.out.println("start...");
System.out.println("===================================================================");
diff --git a/src/test/java/org/bcos/channel/test/TestOk.java b/src/test/java/org/bcos/channel/test/TestOk.java
index 649a81eb3..bb25a8427 100644
--- a/src/test/java/org/bcos/channel/test/TestOk.java
+++ b/src/test/java/org/bcos/channel/test/TestOk.java
@@ -20,6 +20,7 @@
import java.math.BigInteger;
import java.security.KeyPair;
import java.util.UUID;
+import java.util.concurrent.TimeUnit;
import static java.lang.System.exit;
import static java.lang.System.mapLibraryName;
@@ -44,19 +45,27 @@ public static void main(String[] args) throws Exception {
java.math.BigInteger gasPrice = new BigInteger("300000000");
java.math.BigInteger gasLimit = new BigInteger("300000000");
java.math.BigInteger initialWeiValue = new BigInteger("0");
- Ok okDemo = Ok.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get();
- if (okDemo != null) {
- while (true) {
- System.out.println("####contract address is: " + okDemo.getContractAddress());
- TransactionReceipt receipt = okDemo.trans(new Uint256(4)).get();
- System.out.println("###callback trans success");
- Uint256 toBalance = okDemo.get().get();
- System.out.println("============to balance:" + toBalance.getValue());
- Thread.sleep(1000);
+ while (true){
+ try {
+ Ok okDemo = Ok.deploy(web3, credentials, gasPrice, gasLimit, initialWeiValue).get(60000, TimeUnit.MILLISECONDS);
+ if (okDemo != null) {
+ while (true) {
+ System.out.println("####contract address is: " + okDemo.getContractAddress());
+ TransactionReceipt receipt = okDemo.trans(new Uint256(4)).get(60000, TimeUnit.MILLISECONDS);
+ System.out.println("###callback trans success");
+ Uint256 toBalance = okDemo.get().get(60000, TimeUnit.MILLISECONDS);
+ System.out.println("============to balance:" + toBalance.getValue());
+ Thread.sleep(1000);
+ }
+ } else {
+ System.out.println("deploy Ok contract failed");
+ //exit(1);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("Execute testok failed");
}
- } else {
- System.out.println("deploy Ok contract failed");
- exit(1);
}
} else {
System.out.println("create Credentials failed");