From da1f524a06bfb1a05753145bcd1f765ea4a42e81 Mon Sep 17 00:00:00 2001 From: garvey-wong Date: Tue, 3 May 2022 15:01:46 +0800 Subject: [PATCH] feat: sharding executor exec locally --- .../java/org/bdware/server/SDKContext.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/org/bdware/server/SDKContext.java b/src/main/java/org/bdware/server/SDKContext.java index e741176..3a7c6aa 100644 --- a/src/main/java/org/bdware/server/SDKContext.java +++ b/src/main/java/org/bdware/server/SDKContext.java @@ -1,5 +1,6 @@ package org.bdware.server; +import com.google.gson.JsonObject; import org.bdware.sc.ContractManager; import org.bdware.sc.conn.ResultCallback; import org.bdware.sc.units.RecoverFlag; @@ -7,6 +8,7 @@ import org.bdware.sc.units.RequestCache; import org.bdware.sdk.consistency.api.context.*; import org.bdware.server.action.CMActions; import org.bdware.server.action.SyncResult; +import org.bdware.server.action.p2p.MasterClientTCPAction; import org.bdware.server.action.p2p.MasterServerRecoverMechAction; import org.bdware.server.action.p2p.MasterServerTCPAction; import org.bdware.server.trustedmodel.ResultCollector; @@ -14,10 +16,14 @@ import org.bdware.units.NetworkManager; import org.zz.gmhelper.SM2KeyPair; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; public class SDKContext implements ISDKContext { IMasterServerTCPAction masterServerTCPActionProxy = new MasterServerTCPActionProxy(); + IMasterClientTCPAction masterClientTCPAction = new MasterClientTCPActionProxy(); + INetworkManager networkManagerProxy = new NetworkManagerProxy(); ICMActions cmActionsProxy = new CMActionsProxy(); @@ -26,6 +32,11 @@ public class SDKContext implements ISDKContext { IGlobalConf globalConfProxy = new GlobalProxy(); + @Override + public IMasterClientTCPAction getMasterClientTCPAction() { + return masterClientTCPAction; + } + @Override public IMasterServerTCPAction getMasterServerTCPAction() { return masterServerTCPActionProxy; @@ -63,6 +74,19 @@ public class SDKContext implements ISDKContext { } } + public static class MasterClientTCPActionProxy implements IMasterClientTCPAction { + private final ExecutorService executorService = Executors.newFixedThreadPool(10); + + private final MasterClientTCPAction _masterClientTCPAction = new MasterClientTCPAction(); + + @Override + public void asyncExecuteContractLocally(JsonObject jo, ResultCallback rc) { + executorService.execute( + () -> _masterClientTCPAction.executeContractLocally(jo, rc) + ); + } + } + public static class NetworkManagerProxy implements INetworkManager { @Override public void sendToAgent(String pubkey, String content) {