From 29f81e582ac3e60f4b2942b731496ab267b23c80 Mon Sep 17 00:00:00 2001 From: "haoeliu@foxmail.com" Date: Tue, 14 Feb 2023 20:57:55 +0800 Subject: [PATCH] feat: add joinInfo update logic --- .../bdware/sc/server/DoipClusterServer.java | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/bdware/sc/server/DoipClusterServer.java b/src/main/java/org/bdware/sc/server/DoipClusterServer.java index e202388..b1560c2 100644 --- a/src/main/java/org/bdware/sc/server/DoipClusterServer.java +++ b/src/main/java/org/bdware/sc/server/DoipClusterServer.java @@ -15,6 +15,7 @@ import org.bdware.irp.exception.IrpClientException; import org.bdware.irp.stateinfo.StateInfoBase; import org.bdware.sc.ContractProcess; import org.bdware.sc.bean.Contract; +import org.bdware.sc.bean.JoinInfo; import org.bdware.sc.bean.RouteInfo; import org.bdware.sc.handler.DOOPRequestHandler; import org.bdware.sc.node.ContractNode; @@ -96,15 +97,19 @@ public class DoipClusterServer extends DoipServerImpl { // doipOperationName和对应的routeFunctionName的对应关系,存储方式为doipOperationName: routeFunctionName JsonObject methodRouteInfoMap = new JsonObject(); + // doipOperationName和对应的routeFunctionName的对应关系,存储方式为doipOperationName: routeFunctionName + JsonObject methodJoinInfoMap = new JsonObject(); + // 所有Router中用得到的函数(例如Route函数和Route函数依赖的相关函数) JsonObject functions = new JsonObject(); // 维护RouteInfo,将RouteInfo和doipOperationName的映射关系,以及所有Router中用得到的函数都维护好 - maintainRouteInfo(cn, methodRouteInfoMap, functions); + maintainRouteJoinInfo(cn, methodRouteInfoMap, methodJoinInfoMap, functions); if(clusterInfo != null) repoHandleValues.add("clusterInfo", clusterInfo); if(!functions.equals(new JsonObject())) repoHandleValues.add("functions", functions); if(!methodRouteInfoMap.equals(new JsonObject())) repoHandleValues.add("routeInfo", methodRouteInfoMap); + if(!methodJoinInfoMap.equals(new JsonObject())) repoHandleValues.add("joinInfo", methodJoinInfoMap); repoInfo.handleValues.addProperty("cluster", repoHandleValues.toString()); String updateRepoInfoRes = repoIrpClient.reRegister(repoInfo); @@ -117,7 +122,7 @@ public class DoipClusterServer extends DoipServerImpl { } } - public void maintainRouteInfo(ContractNode cn, JsonObject methodRouteInfoMap, JsonObject functions) { + public void maintainRouteJoinInfo(ContractNode cn, JsonObject methodRouteInfoMap, JsonObject methodJoinInfoMap, JsonObject functions) { // all functions存了ContractNode中,所有的FunctionNode List allFunctions = cn.getFunctions(); // gson是Gson工具类昂!!! @@ -128,25 +133,41 @@ public class DoipClusterServer extends DoipServerImpl { String doipOperationName = doipFunctionNodes.getKey(); FunctionNode doipFunctionNode = doipFunctionNodes.getValue(); RouteInfo doipFunctionRouteInfo = doipFunctionNode.getRouteInfo(); + JoinInfo doipFunctionJoinInfo = doipFunctionNode.getJoinInfo(); - // 对于routerInfo进行处理,对于routeInfo进行维护 + // 对于RouterInfo进行维护 if(doipFunctionRouteInfo != null) { + // 建立method和RouteInfo的映射 methodRouteInfoMap.addProperty(doipOperationName, gson.toJson(doipFunctionRouteInfo)); if(doipFunctionRouteInfo.funcName != null) { String routeFunctionName = doipFunctionRouteInfo.funcName; - for(FunctionNode functionNode : allFunctions) { - // find Route Function - if(functionNode.functionName.equals(routeFunctionName)) { - functions.addProperty(functionNode.functionName, functionNode.plainText()); + packSourceFunctionAndDependentFunctions(allFunctions, routeFunctionName, functions); + } + } - // add all dependentFunction to the "functions" struct - for (String dependentFunctionName : functionNode.getDependentFunctions()) { - for (FunctionNode f : cn.getFunctions()) { - if(f.functionName.equals(dependentFunctionName) && !functions.has(dependentFunctionName)) { - functions.addProperty(dependentFunctionName, f.plainText()); - } - } - } + // 对于JoinInfo进行维护 + if(doipFunctionJoinInfo != null) { + // 建立method和RouteInfo的映射 + methodJoinInfoMap.addProperty(doipOperationName, gson.toJson(doipFunctionJoinInfo)); + if(doipFunctionJoinInfo.joinFuncName != null) { + String joinFunctionName = doipFunctionJoinInfo.joinFuncName; + packSourceFunctionAndDependentFunctions(allFunctions, joinFunctionName, functions); + } + } + } + } + + public void packSourceFunctionAndDependentFunctions(List allFunctions, String sourceFunctionName, JsonObject functions) { + for(FunctionNode functionNode : allFunctions) { + // add sourceFunction + if(functionNode.functionName.equals(sourceFunctionName)) { + functions.addProperty(functionNode.functionName, functionNode.plainText()); + + // find all dependent functions to the "functions" struct + for (String dependentFunctionName : functionNode.getDependentFunctions()) { + for (FunctionNode f : allFunctions) { + if(f.functionName.equals(dependentFunctionName) && !functions.has(dependentFunctionName)) { + functions.addProperty(dependentFunctionName, f.plainText()); } } }