mirror of
https://gitee.com/BDWare/cm
synced 2025-01-10 09:54:03 +00:00
merge dengshuang-feature
refactor: NetworkManager
This commit is contained in:
parent
ca20ea58f5
commit
6bf6343c50
@ -3,11 +3,11 @@ package org.bdware.sc;
|
||||
import org.bdware.sc.bean.ContractRequest;
|
||||
import org.bdware.sc.conn.ResultCallback;
|
||||
|
||||
public interface MasterStub {
|
||||
public interface AgentPeerManagerIntf {
|
||||
|
||||
void transferToOtherNode(String pubKey, String contractID);
|
||||
|
||||
void executeByOtherNodeAsync(String pubKey, ContractRequest c, ResultCallback cb);
|
||||
|
||||
boolean hasConnection(String pubKey);
|
||||
boolean hasAgentConnection(String pubKey);
|
||||
}
|
@ -144,15 +144,13 @@ public class ContractClient {
|
||||
new TypeToken<Set<String>>() {
|
||||
}.getType());
|
||||
// LOGGER.info("initProps ---- position-----4");
|
||||
contractMeta.exportedFunctions = new HashMap<>();
|
||||
List<FunctionDesp> exportedFunctions =
|
||||
contractMeta.exportedFunctions =
|
||||
JsonUtil.fromJson(
|
||||
get.syncGet("", "getExportedFunctions", ""),
|
||||
new TypeToken<List<FunctionDesp>>() {
|
||||
}.getType());
|
||||
contractMeta.logDetail = new HashMap<>();
|
||||
for (FunctionDesp func : exportedFunctions) {
|
||||
contractMeta.exportedFunctions.put(func.functionName, func);
|
||||
for (FunctionDesp func : contractMeta.exportedFunctions) {
|
||||
StringBuilder str = new StringBuilder();
|
||||
for (AnnotationNode anno : func.annotations) {
|
||||
if (anno.getType().equals("LogType")) {
|
||||
|
@ -93,7 +93,7 @@ public class ContractManager {
|
||||
|
||||
protected final EventBroker eventBroker;
|
||||
public NodeCenterConn nodeCenterConn;
|
||||
public MasterStub masterStub;
|
||||
public AgentPeerManagerIntf masterStub;
|
||||
public ChainOpener chainOpener;
|
||||
public ContractStatusRecorder statusRecorder;
|
||||
public MultiContractRecorder multiContractRecorder;
|
||||
@ -1297,23 +1297,22 @@ public class ContractManager {
|
||||
if (client.contractMeta.sigRequired) {
|
||||
if (!request.verifySignature()) {
|
||||
cr = new ContractResult(Status.Error, new JsonPrimitive("sign verified failed"));
|
||||
rcb.onResult(JsonUtil.parseObject(cr));
|
||||
rcb.onResult(JsonUtil.parseObjectAsJsonObject(cr));
|
||||
return;
|
||||
}
|
||||
}
|
||||
client.times++;
|
||||
client.contractStatus = ContractStatus.Executing;
|
||||
ResultCallback acb;
|
||||
// TODO acb bu dei jin
|
||||
//use to write to chian
|
||||
acb =
|
||||
new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(String result) {
|
||||
//TODO????
|
||||
client.traffic += result.length();
|
||||
client.contractStatus = ContractStatus.Executed;
|
||||
|
||||
JsonObject finalRet = JsonUtil.parseString(result);
|
||||
JsonObject finalRet = JsonUtil.parseStringAsJsonObject(result);
|
||||
|
||||
rcb.onResult(finalRet);
|
||||
if (finalRet != null) {
|
||||
@ -1368,7 +1367,7 @@ public class ContractManager {
|
||||
client.traffic += result.length();
|
||||
|
||||
if (client.getContractCopies() == 1) {
|
||||
extractEventsFromContractResult(ocb, JsonUtil.parseString(result), client, request, start);
|
||||
extractEventsFromContractResult(ocb, JsonUtil.parseStringAsJsonObject(result), client, request, start);
|
||||
}
|
||||
chainOpener.writeContractResultToLocalAndLedger(
|
||||
result, client, request, ocb, start, System.currentTimeMillis() - start);
|
||||
@ -1463,15 +1462,19 @@ public class ContractManager {
|
||||
long start = System.currentTimeMillis();
|
||||
ResultCallback eventExtractor = new ResultCallback() {
|
||||
@Override
|
||||
public void onResult(String ret) {
|
||||
JsonObject result = JsonUtil.parseString(ret);
|
||||
public void onResult(String ret){
|
||||
JsonObject result = JsonUtil.parseStringAsJsonObject(ret);
|
||||
this.onResult(result);
|
||||
}
|
||||
@Override
|
||||
public void onResult(JsonObject result) {
|
||||
ContractManager.instance.extractEventsFromContractResult(
|
||||
null, result, client, cr, start);
|
||||
LOGGER.debug(
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||
.format(new Date(System.currentTimeMillis()))
|
||||
+ meta.contractExecutor + " 结果是 "
|
||||
+ ret
|
||||
+ result.toString()
|
||||
+ "\n");
|
||||
rcb.onResult(result);
|
||||
}
|
||||
@ -1505,7 +1508,7 @@ public class ContractManager {
|
||||
|
||||
// LOGGER.info("查看合约 " + cr.getContractID() + " 的master为 " + pubKey);
|
||||
|
||||
if (!masterStub.hasConnection(pubKey)) {
|
||||
if (!masterStub.hasAgentConnection(pubKey)) {
|
||||
pubKey = nodeCenterConn.reRouteContract(cr.getContractID());
|
||||
LOGGER.info("查看合约 " + cr.getContractID() + " 的master为 " + pubKey);
|
||||
}
|
||||
@ -1541,7 +1544,7 @@ public class ContractManager {
|
||||
new JsonPrimitive(
|
||||
"Contract " + cr.getContractID() + " doesn't exists!!"));
|
||||
}
|
||||
rcb.onResult(JsonUtil.parseObject(result));
|
||||
rcb.onResult(JsonUtil.parseObjectAsJsonObject(result));
|
||||
}
|
||||
|
||||
|
||||
@ -2159,7 +2162,7 @@ public class ContractManager {
|
||||
if (null != client) {
|
||||
try {
|
||||
String ret = client.get.syncGet("", "suicide", "");
|
||||
JsonObject jo = JsonUtil.parseString(ret);
|
||||
JsonObject jo = JsonUtil.parseStringAsJsonObject(ret);
|
||||
if (jo.has("cleanSub")) {
|
||||
REvent msg =
|
||||
new REvent(
|
||||
|
@ -9,7 +9,10 @@ import org.bdware.sc.node.YjsType;
|
||||
import org.bdware.server.trustedmodel.ContractExecutor;
|
||||
import org.bdware.server.trustedmodel.SingleNodeExecutor;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ContractMeta implements IDSerializable {
|
||||
public Contract contract;
|
||||
@ -18,7 +21,7 @@ public class ContractMeta implements IDSerializable {
|
||||
String id;
|
||||
boolean isDebug;
|
||||
Map<String, REvent.REventSemantics> declaredEvents;
|
||||
Map<String, FunctionDesp> exportedFunctions;
|
||||
List<FunctionDesp> exportedFunctions;
|
||||
Map<String, String> logDetail;
|
||||
List<AnnotationNode> annotations;
|
||||
Set<String> dependentContracts;
|
||||
@ -59,8 +62,8 @@ public class ContractMeta implements IDSerializable {
|
||||
return annotations;
|
||||
}
|
||||
|
||||
public Collection<FunctionDesp> getExportedFunctions() {
|
||||
return null == exportedFunctions ? null : exportedFunctions.values();
|
||||
public List<FunctionDesp> getExportedFunctions() {
|
||||
return exportedFunctions;
|
||||
}
|
||||
|
||||
public Set<String> getDependentContracts() {
|
||||
@ -98,22 +101,19 @@ public class ContractMeta implements IDSerializable {
|
||||
}
|
||||
|
||||
public FunctionDesp getExportedFunction(String action) {
|
||||
if (funCache == null) {
|
||||
funCache = new HashMap<>();
|
||||
}
|
||||
if (funCache == null) funCache = new HashMap<>();
|
||||
FunctionDesp desp = funCache.get(action);
|
||||
if (desp != null) {
|
||||
return desp;
|
||||
}
|
||||
if (desp != null) return desp;
|
||||
desp = seekFunction(action);
|
||||
if (null != desp) {
|
||||
funCache.put(action, desp);
|
||||
}
|
||||
if (desp != null) funCache.put(action, desp);
|
||||
return desp;
|
||||
}
|
||||
|
||||
public FunctionDesp seekFunction(String action) {
|
||||
return null == exportedFunctions ? null : exportedFunctions.get(action);
|
||||
private FunctionDesp seekFunction(String action) {
|
||||
for (FunctionDesp desp : exportedFunctions) {
|
||||
if (desp != null && desp.functionName.equals(action)) return desp;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setContract(Contract c) {
|
||||
|
@ -6,4 +6,5 @@ import org.bdware.sc.conn.ResultCallback;
|
||||
|
||||
public interface ContractExecutor {
|
||||
void execute(String requestID, ContractRequest req, ResultCallback rcb, OnHashCallback hcb);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user