Skip to content

Commit

Permalink
Merge pull request #76 from FISCO-BCOS/opt-0815
Browse files Browse the repository at this point in the history
V1.2.2
  • Loading branch information
wheatli authored Aug 29, 2018
2 parents 35aadd2 + 59abe32 commit f7d51e1
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 26 deletions.
24 changes: 24 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
### V1.2.2 (2018-08-29)

* Updates

1. 增加错误提示。
2. 默认连接时间从3秒改到30秒。
3. TestOk中的Future设置超时时间。
4. 交易轮询线程池可以配置
```
<bean id="async" class="org.bcos.web3j.utils.Async">
<constructor-arg type="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" ref="pool" />
</bean>
<bean id="pool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="50" />
<property name="maxPoolSize" value="100" />
<property name="queueCapacity" value="500" />
<property name="keepAliveSeconds" value="60" />
<property name="rejectedExecutionHandler">
<bean class="java.util.concurrent.ThreadPoolExecutor.AbortPolicy" />
</property>
</bean>
```

### V1.2.1 (2018-07-02)

* Added
Expand Down
2 changes: 1 addition & 1 deletion release_note.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
V1.2.1
V1.2.2
6 changes: 3 additions & 3 deletions src/main/java/org/bcos/channel/client/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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<String, ChannelConnections> allChannelConnections;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.bcos.web3j.protocol.channel;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -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.
*/
Expand Down Expand Up @@ -52,8 +52,23 @@ public <T extends Response> 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/org/bcos/web3j/utils/Async.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 <T> CompletableFuture<T> run(Callable<T> callable) {
CompletableFuture<T> result = new CompletableFuture<>();
Expand All @@ -23,7 +35,7 @@ public static <T> CompletableFuture<T> run(Callable<T> callable) {
} catch (Throwable e) {
result.completeExceptionally(e);
}
}, executor);
}, Async.executor);
return result;
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/bcos/web3j/utils/BlockLimit.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

14 changes: 14 additions & 0 deletions src/main/java/org/bcos/web3j/utils/Web3AsyncThreadPoolSize.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

1 change: 0 additions & 1 deletion src/test/java/org/bcos/channel/test/Ethereum.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("===================================================================");

Expand Down
33 changes: 21 additions & 12 deletions src/test/java/org/bcos/channel/test/TestOk.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit f7d51e1

Please sign in to comment.