feat: update ContractExecutor and implementation classes

use default function of interface to update ContractExecutor; add TODO logs in SelfAdaptiveShardingExecutor
This commit is contained in:
Frank.R.Wu 2021-11-18 13:47:04 +08:00
parent d6979118fc
commit 801c1a93f5
2 changed files with 12 additions and 10 deletions

View File

@ -80,8 +80,8 @@ public class MasterClientTCPAction {
request.get("verifiedPubKey").getAsString(), client.getContractID());
MultiContractMeta cei =
CMActions.manager.multiContractRecorder.getMultiContractMeta(client.getContractID());
if (null != cei && cei.contractExecutor instanceof SelfAdaptiveShardingExecutor) {
((SelfAdaptiveShardingExecutor) cei.contractExecutor).close();
if (null != cei) {
cei.contractExecutor.close();
}
}
}

View File

@ -48,7 +48,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
TimeUnit.SECONDS);
ContractManager.threadPool.submit(() -> {
LOGGER.info(
"[SelfAdaptiveShardingExecutor " + meta.getContractID() + "] starting service...");
"[SelfAdaptiveShardingExecutor " + meta.getContractID() + "] starting service..." + running);
while (running) {
LOGGER.info("checking blocks to be executed, latest block=" +
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
public void execute(String requestID, ResultCallback rc, ContractRequest req) {
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) {
Block block = JsonUtil.fromJson(blockStr, Block.class);
if (!toExecuted.containsKey(block.prevHash) &&
@ -129,6 +130,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
return;
}
}
// TODO check status
for (ContractRequest request : block.requests) {
String ret = ContractManager.instance.executeLocally(request, null);
LOGGER.debug("result of request " + request.getRequestID() + ": " + ret);
@ -139,6 +141,7 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
meta.getContractID(),
block.requests.length,
block.hash));
// TODO create check point
this.b = new Block(block.hash);
executedBlocks.add(block.hash);
}
@ -211,7 +214,6 @@ public class SelfAdaptiveShardingExecutor implements ContractExecutor {
this.body);
}
private String merkle(ContractRequest[] requests) {
if (requests.length == 0) {
return null;