feat: support @RouteInfo byFunc
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package org.bdware.consistency.plugin.sharding;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
@@ -7,6 +8,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bdware.consistency.plugin.common.AbstractContextContractExecutor;
|
||||
import org.bdware.sc.ComponedContractResult;
|
||||
import org.bdware.sc.ContractClient;
|
||||
import org.bdware.sc.ContractMeta;
|
||||
import org.bdware.sc.ContractResult;
|
||||
import org.bdware.sc.bean.*;
|
||||
@@ -20,10 +22,7 @@ import org.bdware.sc.util.JsonUtil;
|
||||
import org.bdware.server.trustedmodel.MultiReqSeq;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -123,6 +122,31 @@ public class MultiPointCooperationExecutor extends AbstractContextContractExecut
|
||||
val = val + members.length;
|
||||
}
|
||||
return new String[]{members[val]};
|
||||
case byFunc:
|
||||
ContractClient client = cmActions.getManager().getClient(req.getContractID());
|
||||
|
||||
JsonArray membersArr = new JsonArray(members.length);
|
||||
for (String member : members) {
|
||||
membersArr.add(member);
|
||||
}
|
||||
|
||||
JsonObject arg = new JsonObject();
|
||||
arg.addProperty("funcName", routeInfo.funcName);
|
||||
// func myFunc (currentNode, members, membersCount, sourceArg)
|
||||
JsonArray funcArgs = new JsonArray();
|
||||
funcArgs.add(globalConf.getNodeID());
|
||||
funcArgs.add(membersArr);
|
||||
funcArgs.add(membersArr.size());
|
||||
funcArgs.add(req.getArg());
|
||||
arg.add("funcArgs", funcArgs);
|
||||
|
||||
String routeResultStr = client.executeMethod("", "invokeFunctionWithoutLimit", arg.toString());
|
||||
JsonObject routeResult = JsonUtil.parseString(routeResultStr).getAsJsonObject();
|
||||
List<String> nodes = new ArrayList<>();
|
||||
for (String key: routeResult.keySet()) {
|
||||
nodes.add(routeResult.get(key).getAsString());
|
||||
}
|
||||
return nodes.toArray(new String[]{});
|
||||
default:
|
||||
return members;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user