mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 01:44:14 +00:00
feat: update ContractExecutor and implementation classes
use default function of interface to update ContractExecutor; add TODO logs in SelfAdaptiveShardingExecutor
This commit is contained in:
parent
d6979118fc
commit
801c1a93f5
@ -80,8 +80,8 @@ public class MasterClientTCPAction {
|
|||||||
request.get("verifiedPubKey").getAsString(), client.getContractID());
|
request.get("verifiedPubKey").getAsString(), client.getContractID());
|
||||||
MultiContractMeta cei =
|
MultiContractMeta cei =
|
||||||
CMActions.manager.multiContractRecorder.getMultiContractMeta(client.getContractID());
|
CMActions.manager.multiContractRecorder.getMultiContractMeta(client.getContractID());
|
||||||
if (null != cei && cei.contractExecutor instanceof SelfAdaptiveShardingExecutor) {
|
if (null != cei) {
|
||||||
((SelfAdaptiveShardingExecutor) cei.contractExecutor).close();
|
cei.contractExecutor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
|
|||||||
TimeUnit.SECONDS);
|
TimeUnit.SECONDS);
|
||||||
ContractManager.threadPool.submit(() -> {
|
ContractManager.threadPool.submit(() -> {
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"[SelfAdaptiveShardingExecutor " + meta.getContractID() + "] starting service...");
|
"[SelfAdaptiveShardingExecutor " + meta.getContractID() + "] starting service..." + running);
|
||||||
while (running) {
|
while (running) {
|
||||||
LOGGER.info("checking blocks to be executed, latest block=" +
|
LOGGER.info("checking blocks to be executed, latest block=" +
|
||||||
this.b.prevHash + ", to be executed size=" + toExecuted.size());
|
this.b.prevHash + ", to be executed size=" + toExecuted.size());
|
||||||
@ -75,12 +75,6 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
|
||||||
this.future.cancel(false);
|
|
||||||
this.running = false;
|
|
||||||
LOGGER.info("destruct executor of contract " + meta.getContractID());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(String requestID, ResultCallback rc, ContractRequest req) {
|
public void execute(String requestID, ResultCallback rc, ContractRequest req) {
|
||||||
if (executedTxs.containsKey(requestID)) {
|
if (executedTxs.containsKey(requestID)) {
|
||||||
@ -100,6 +94,13 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
this.future.cancel(false);
|
||||||
|
this.running = false;
|
||||||
|
LOGGER.info("destruct executor of contract " + meta.getContractID());
|
||||||
|
}
|
||||||
|
|
||||||
public void execute(String blockStr) {
|
public void execute(String blockStr) {
|
||||||
Block block = JsonUtil.fromJson(blockStr, Block.class);
|
Block block = JsonUtil.fromJson(blockStr, Block.class);
|
||||||
if (!toExecuted.containsKey(block.prevHash) &&
|
if (!toExecuted.containsKey(block.prevHash) &&
|
||||||
@ -129,6 +130,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO check status
|
||||||
for (ContractRequest request : block.requests) {
|
for (ContractRequest request : block.requests) {
|
||||||
String ret = ContractManager.instance.executeLocally(request, null);
|
String ret = ContractManager.instance.executeLocally(request, null);
|
||||||
LOGGER.debug("result of request " + request.getRequestID() + ": " + ret);
|
LOGGER.debug("result of request " + request.getRequestID() + ": " + ret);
|
||||||
@ -139,6 +141,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
|
|||||||
meta.getContractID(),
|
meta.getContractID(),
|
||||||
block.requests.length,
|
block.requests.length,
|
||||||
block.hash));
|
block.hash));
|
||||||
|
// TODO create check point
|
||||||
this.b = new Block(block.hash);
|
this.b = new Block(block.hash);
|
||||||
executedBlocks.add(block.hash);
|
executedBlocks.add(block.hash);
|
||||||
}
|
}
|
||||||
@ -211,7 +214,6 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
|
|||||||
this.body);
|
this.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private String merkle(ContractRequest[] requests) {
|
private String merkle(ContractRequest[] requests) {
|
||||||
if (requests.length == 0) {
|
if (requests.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user