use of org.bcos.channel.dto.EthereumResponse in project web3sdk by FISCO-BCOS.
the class EthereumResponseCallback method onTimeout.
public void onTimeout() {
logger.error("处理Ethereum消息超时:{}");
EthereumResponse response = new EthereumResponse();
response.setErrorCode(102);
response.setErrorMessage("处理Ethereum消息超时");
response.setContent("");
onResponse(response);
}
use of org.bcos.channel.dto.EthereumResponse in project web3sdk by FISCO-BCOS.
the class Service method sendEthereumMessage.
public EthereumResponse sendEthereumMessage(EthereumRequest request) {
class Callback extends EthereumResponseCallback {
Callback() {
try {
semaphore.acquire(1);
} catch (InterruptedException e) {
logger.error("错误:", e);
}
}
@Override
public void onResponse(EthereumResponse response) {
ethereumResponse = response;
if (ethereumResponse != null && ethereumResponse.getContent() != null) {
logger.debug("收到响应: {}", response.getContent());
} else {
logger.error("ethereum错误");
}
semaphore.release();
}
public EthereumResponse ethereumResponse;
public Semaphore semaphore = new Semaphore(1, true);
}
;
Callback callback = new Callback();
asyncSendEthereumMessage(request, callback);
try {
callback.semaphore.acquire(1);
} catch (InterruptedException e) {
logger.error("系统错误:", e);
}
return callback.ethereumResponse;
}
use of org.bcos.channel.dto.EthereumResponse in project web3sdk by FISCO-BCOS.
the class Service method onReceiveEthereumMessage.
public void onReceiveEthereumMessage(ChannelHandlerContext ctx, EthereumMessage message) {
EthereumResponseCallback callback = (EthereumResponseCallback) seq2Callback.get(message.getSeq());
logger.debug("收到ethereum消息 seq:{}", message.getSeq());
if (callback != null) {
logger.debug("已找到callback ethereum回包消息");
if (callback.getTimeout() != null) {
callback.getTimeout().cancel();
}
EthereumResponse response = new EthereumResponse();
if (message.getResult() != 0) {
response.setErrorMessage("回包错误");
}
response.setErrorCode(message.getResult());
response.setMessageID(message.getSeq());
response.setContent(new String(message.getData()));
callback.onResponse(response);
seq2Callback.remove(message.getSeq());
} else {
logger.debug("无callback push消息");
}
}
Aggregations