mirror of
https://gitee.com/BDWare/agent-backend
synced 2025-01-10 09:54:11 +00:00
merge files
This commit is contained in:
commit
1a444240a0
@ -3,3 +3,9 @@
|
|||||||
## clientToAgentPlugins: client -> cluster 包括MasterClientFrameHandler
|
## clientToAgentPlugins: client -> cluster 包括MasterClientFrameHandler
|
||||||
## clientToClusterPlugins:[], client -> NodeCenterClientHandler
|
## clientToClusterPlugins:[], client -> NodeCenterClientHandler
|
||||||
## tcpPlugins:tcp 包括TcpserverFrameHandler
|
## tcpPlugins:tcp 包括TcpserverFrameHandler
|
||||||
|
|
||||||
|
# 配置说明
|
||||||
|
## 使用字符串分割,如需添加多项,在agent-backend/script/config.json.template里修改如:
|
||||||
|
``````
|
||||||
|
"wsPluginActions": "org.bdware.metering.MeteringAction"
|
||||||
|
``````
|
||||||
|
@ -12,4 +12,8 @@
|
|||||||
"enableEventPersistence": false,
|
"enableEventPersistence": false,
|
||||||
"enableSsl": "./ssl/chained.pem:./ssl/domain.pem",
|
"enableSsl": "./ssl/chained.pem:./ssl/domain.pem",
|
||||||
"textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv"
|
"textFileSuffixes": ".yjs,.json,.txt,.css,.js,.html,.md,.conf,.csv"
|
||||||
|
"wsPluginActions": "org.bdware.metering.MeteringAction"
|
||||||
|
"clientToAgentPlugins": ""
|
||||||
|
"clientToClusterPlugins": ""
|
||||||
|
"tcpPlugins": ""
|
||||||
}
|
}
|
@ -30,8 +30,11 @@ import org.bdware.sc.util.ExceptionUtil;
|
|||||||
import org.bdware.server.action.FileActions;
|
import org.bdware.server.action.FileActions;
|
||||||
import org.bdware.server.doip.ContractRepositoryMain;
|
import org.bdware.server.doip.ContractRepositoryMain;
|
||||||
import org.bdware.server.http.CMHttpHandler;
|
import org.bdware.server.http.CMHttpHandler;
|
||||||
|
import org.bdware.server.nodecenter.client.NodeCenterClientHandler;
|
||||||
|
import org.bdware.server.tcp.MasterClientFrameHandler;
|
||||||
import org.bdware.server.ws.ContractManagerFrameHandler;
|
import org.bdware.server.ws.ContractManagerFrameHandler;
|
||||||
import org.bdware.units.NetworkManager;
|
import org.bdware.units.NetworkManager;
|
||||||
|
import org.bdware.units.tcp.TCPClientFrameHandler;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -45,15 +48,19 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
public class CMHttpServer {
|
public class CMHttpServer {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(CMHttpServer.class);
|
private static final Logger LOGGER = LogManager.getLogger(CMHttpServer.class);
|
||||||
private static final String CONFIG_PATH = "cmconfig.json";
|
private static final String CONFIG_PATH = "cmconfig.json";
|
||||||
public static CMDConf cmdConf;
|
|
||||||
public static EventLoopGroup workerGroup = new NioEventLoopGroup();
|
public static EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
public static MultiIndexTimeRocksDBUtil nodeLogDB =
|
public static MultiIndexTimeRocksDBUtil nodeLogDB =
|
||||||
new MultiIndexTimeRocksDBUtil(
|
new MultiIndexTimeRocksDBUtil(
|
||||||
"./ContractManagerDB", CMTables.LocalNodeLogDB.toString());
|
"./ContractManagerDB", CMTables.LocalNodeLogDB.toString());
|
||||||
|
public static URLClassLoader pluginLoader;
|
||||||
private static SslContext sslContext = null;
|
private static SslContext sslContext = null;
|
||||||
final String PATH = "/SCIDE/SCExecutor";
|
final String PATH = "/SCIDE/SCExecutor";
|
||||||
private final int port;
|
private final int port;
|
||||||
|
|
||||||
|
private CMHttpServer(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
private static void parseConf(CMDConf cmdConf) throws IOException {
|
private static void parseConf(CMDConf cmdConf) throws IOException {
|
||||||
if (cmdConf.disableDoRepo) {
|
if (cmdConf.disableDoRepo) {
|
||||||
DoConfig.callContractUsingDOI = false;
|
DoConfig.callContractUsingDOI = false;
|
||||||
@ -114,12 +121,21 @@ public class CMHttpServer {
|
|||||||
LOGGER.debug(ExceptionUtil.exceptionToString(e));
|
LOGGER.debug(ExceptionUtil.exceptionToString(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cmi file
|
||||||
ContractClient.cmi = cmdConf.cmi;
|
ContractClient.cmi = cmdConf.cmi;
|
||||||
FileWriter fw = new FileWriter("CMI");
|
FileWriter fw = new FileWriter("CMI");
|
||||||
fw.write(ContractClient.cmi);
|
fw.write(ContractClient.cmi);
|
||||||
fw.close();
|
fw.close();
|
||||||
LOGGER.info("write CMI=" + ContractClient.cmi + " to ./CMI");
|
LOGGER.info("write CMI=" + ContractClient.cmi + " to ./CMI");
|
||||||
FileActions.setTextFileSuffixes(cmdConf.textFileSuffixes);
|
FileActions.setTextFileSuffixes(cmdConf.textFileSuffixes);
|
||||||
|
|
||||||
|
// plugins
|
||||||
|
CMHttpHandler.wsPluginActions = cmdConf.wsPluginActions.split(",");
|
||||||
|
MasterClientFrameHandler.clientToAgentPlugins = cmdConf.clientToAgentPlugins.split(",");
|
||||||
|
NodeCenterClientHandler.clientToClusterPlugins = cmdConf.clientToClusterPlugins.split(",");
|
||||||
|
TCPClientFrameHandler.tcpPlugins = cmdConf.tcpPlugins.split(",");
|
||||||
|
|
||||||
if (!cmdConf.debug.isEmpty()) {
|
if (!cmdConf.debug.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
String[] classes = cmdConf.debug.split(",");
|
String[] classes = cmdConf.debug.split(",");
|
||||||
@ -136,12 +152,6 @@ public class CMHttpServer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static URLClassLoader pluginLoader;
|
|
||||||
|
|
||||||
private CMHttpServer(int port) {
|
|
||||||
this.port = port;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addDirToPath(String s) {
|
private static void addDirToPath(String s) {
|
||||||
try {
|
try {
|
||||||
LOGGER.info("add to path: " + s);
|
LOGGER.info("add to path: " + s);
|
||||||
@ -170,7 +180,7 @@ public class CMHttpServer {
|
|||||||
if (!confFile.exists() && confTemplate.exists()) {
|
if (!confFile.exists() && confTemplate.exists()) {
|
||||||
FileUtils.copyFile(confTemplate, confFile);
|
FileUtils.copyFile(confTemplate, confFile);
|
||||||
}
|
}
|
||||||
cmdConf = CMDConf.parseConf(CONFIG_PATH);
|
CMDConf cmdConf = CMDConf.parseConf(CONFIG_PATH);
|
||||||
|
|
||||||
// addDirToPath(new File("./dynamicLibrary").getAbsolutePath());
|
// addDirToPath(new File("./dynamicLibrary").getAbsolutePath());
|
||||||
|
|
||||||
@ -239,26 +249,18 @@ public class CMHttpServer {
|
|||||||
// EpollServerSocketChannel
|
// EpollServerSocketChannel
|
||||||
// ContractManager.reconnectPort = (port - 18000) * 30 + 1630;
|
// ContractManager.reconnectPort = (port - 18000) * 30 + 1630;
|
||||||
// if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630;
|
// if (ContractManager.reconnectPort < 0) ContractManager.reconnectPort = 1630;
|
||||||
File[] pluginJar = new File("./pluginLib/").listFiles(new FileFilter() {
|
File[] pluginJar = new File("./pluginLib/")
|
||||||
@Override
|
.listFiles(pathname -> pathname.getName().endsWith(".jar"));
|
||||||
public boolean accept(File pathname) {
|
URL[] urls = new URL[pluginJar.length];
|
||||||
return pathname.getName().endsWith(".jar");
|
for (int i = 0; i < pluginJar.length; i++) {
|
||||||
|
try {
|
||||||
|
urls[i] = pluginJar[i].toURI().toURL();
|
||||||
|
LOGGER.info("add plugin:" + pluginJar[i].getName());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
if (pluginJar != null && pluginJar.length > 0) {
|
|
||||||
URL[] urls = new URL[pluginJar.length];
|
|
||||||
for (int i = 0; i < pluginJar.length; i++) {
|
|
||||||
try {
|
|
||||||
urls[i] = pluginJar[i].toURI().toURL();
|
|
||||||
LOGGER.info("add plugin:" + pluginJar[i].getName());
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pluginLoader = new URLClassLoader(urls, CMHttpServer.class.getClassLoader());
|
|
||||||
} else {
|
|
||||||
pluginLoader = new URLClassLoader(new URL[]{}, CMHttpServer.class.getClassLoader());
|
|
||||||
}
|
}
|
||||||
|
pluginLoader = new URLClassLoader(urls, CMHttpServer.class.getClassLoader());
|
||||||
if (port >= 18000 && port < 18100) {
|
if (port >= 18000 && port < 18100) {
|
||||||
ContractManager.cPort = new ContractPort(1615 + (port - 18000) * 30);
|
ContractManager.cPort = new ContractPort(1615 + (port - 18000) * 30);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1191,24 +1191,24 @@ public class FileActions {
|
|||||||
if (json.has("projectDOI"))
|
if (json.has("projectDOI"))
|
||||||
manifestFout.write(
|
manifestFout.write(
|
||||||
("{\n \"main\":\""
|
("{\n \"main\":\""
|
||||||
+ fileName
|
+ fileName
|
||||||
+ ".yjs\",\n"
|
+ ".yjs\",\n"
|
||||||
+ " \"doipFlag\":true,\n"
|
+ " \"doipFlag\":true,\n"
|
||||||
+ " \"doi\":\""
|
+ " \"doi\":\""
|
||||||
+ json.get("projectDOI").getAsString()
|
+ json.get("projectDOI").getAsString()
|
||||||
+ "\",\n"
|
+ "\",\n"
|
||||||
+ " \"authInfoPersistDOI\":\""
|
+ " \"authInfoPersistDOI\":\""
|
||||||
+ authInfoPersistDOI
|
+ authInfoPersistDOI
|
||||||
+ "\"\n}")
|
+ "\"\n}")
|
||||||
.getBytes());
|
.getBytes());
|
||||||
else
|
else
|
||||||
manifestFout.write(
|
manifestFout.write(
|
||||||
("{\n \"main\":\""
|
("{\n \"main\":\""
|
||||||
+ fileName
|
+ fileName
|
||||||
+ ".yjs\",\n"
|
+ ".yjs\",\n"
|
||||||
+ " \"authInfoPersistDOI\":\""
|
+ " \"authInfoPersistDOI\":\""
|
||||||
+ authInfoPersistDOI
|
+ authInfoPersistDOI
|
||||||
+ "\"\n}")
|
+ "\"\n}")
|
||||||
.getBytes());
|
.getBytes());
|
||||||
|
|
||||||
YJSPacker.unpack(
|
YJSPacker.unpack(
|
||||||
@ -1219,18 +1219,18 @@ public class FileActions {
|
|||||||
("import \"naiveDAC/naiveDAC.yjs\"\n\n").getBytes());
|
("import \"naiveDAC/naiveDAC.yjs\"\n\n").getBytes());
|
||||||
mainyjsFout.write(
|
mainyjsFout.write(
|
||||||
("contract "
|
("contract "
|
||||||
+ fileName
|
+ fileName
|
||||||
+ "{\n function onCreate(){\n initDAC(requester);\n }\n}")
|
+ "{\n function onCreate(){\n initDAC(requester);\n }\n}")
|
||||||
.getBytes());
|
.getBytes());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (json.has("projectDOI"))
|
if (json.has("projectDOI"))
|
||||||
manifestFout.write(
|
manifestFout.write(
|
||||||
("{\n \"main\":\""
|
("{\n \"main\":\""
|
||||||
+ fileName
|
+ fileName
|
||||||
+ ".yjs\",\n \"doipFlag\":true,\n \"doi\":\""
|
+ ".yjs\",\n \"doipFlag\":true,\n \"doi\":\""
|
||||||
+ json.get("projectDOI").getAsString()
|
+ json.get("projectDOI").getAsString()
|
||||||
+ "\"\n}")
|
+ "\"\n}")
|
||||||
.getBytes());
|
.getBytes());
|
||||||
else
|
else
|
||||||
manifestFout.write(
|
manifestFout.write(
|
||||||
|
@ -18,8 +18,6 @@ import org.bdware.sc.db.KeyValueDBUtil;
|
|||||||
import org.bdware.sc.db.TimeDBUtil;
|
import org.bdware.sc.db.TimeDBUtil;
|
||||||
import org.bdware.sc.util.ExceptionUtil;
|
import org.bdware.sc.util.ExceptionUtil;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.bdware.server.CMDConf;
|
|
||||||
import org.bdware.server.CMHttpServer;
|
|
||||||
import org.bdware.server.GRPCPool;
|
import org.bdware.server.GRPCPool;
|
||||||
import org.bdware.server.action.*;
|
import org.bdware.server.action.*;
|
||||||
import org.bdware.server.permission.Role;
|
import org.bdware.server.permission.Role;
|
||||||
@ -42,6 +40,7 @@ import static org.bdware.server.CMHttpServer.pluginLoader;
|
|||||||
public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
||||||
private static final String UNSUPPORTED_ACTION = "{\"msg\":\"unsupported action\"}";
|
private static final String UNSUPPORTED_ACTION = "{\"msg\":\"unsupported action\"}";
|
||||||
private static final Logger LOGGER = LogManager.getLogger(CMHttpHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(CMHttpHandler.class);
|
||||||
|
public static String[] wsPluginActions;
|
||||||
public final ActionExecutor<ResultCallback, JsonObject> actionExecutor;
|
public final ActionExecutor<ResultCallback, JsonObject> actionExecutor;
|
||||||
URIHandler uriHandlers;
|
URIHandler uriHandlers;
|
||||||
|
|
||||||
@ -117,11 +116,9 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (CMHttpServer.cmdConf.wsPluginActions != null){
|
for (String str : wsPluginActions) {
|
||||||
for (String str:CMHttpServer.cmdConf.wsPluginActions){
|
Object obj = createInstanceByClzName(str);
|
||||||
Object obj = createInstanceByClzName(str);
|
actionExecutor.appendHandler(obj);
|
||||||
actionExecutor.appendHandler(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uriHandlers = new URIHandler();
|
uriHandlers = new URIHandler();
|
||||||
@ -133,14 +130,16 @@ public class CMHttpHandler extends SimpleChannelInboundHandler<HttpObject> {
|
|||||||
uriHandlers.register(FileActions.class);
|
uriHandlers.register(FileActions.class);
|
||||||
uriHandlers.printURIHandlers();
|
uriHandlers.printURIHandlers();
|
||||||
}
|
}
|
||||||
private Object createInstanceByClzName(String clzName){
|
|
||||||
|
private Object createInstanceByClzName(String clzName) {
|
||||||
try {
|
try {
|
||||||
Class clz = Class.forName(clzName,true,pluginLoader);
|
Class<?> clz = Class.forName(clzName, true, pluginLoader);
|
||||||
return clz.newInstance();
|
return clz.newInstance();
|
||||||
}catch(Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||||
ctx.flush();
|
ctx.flush();
|
||||||
|
@ -12,8 +12,6 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.bdware.server.CMDConf;
|
|
||||||
import org.bdware.server.CMHttpServer;
|
|
||||||
import org.bdware.server.GlobalConf;
|
import org.bdware.server.GlobalConf;
|
||||||
import org.bdware.server.action.ActionExecutor;
|
import org.bdware.server.action.ActionExecutor;
|
||||||
import org.bdware.server.ws.ContractManagerFrameHandler;
|
import org.bdware.server.ws.ContractManagerFrameHandler;
|
||||||
@ -29,6 +27,7 @@ import static org.bdware.server.CMHttpServer.pluginLoader;
|
|||||||
@Sharable
|
@Sharable
|
||||||
public class NodeCenterClientHandler extends SimpleChannelInboundHandler<Object> {
|
public class NodeCenterClientHandler extends SimpleChannelInboundHandler<Object> {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(NodeCenterClientHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(NodeCenterClientHandler.class);
|
||||||
|
public static String[] clientToClusterPlugins;
|
||||||
public boolean hasPermission;
|
public boolean hasPermission;
|
||||||
public NodeCenterClientController controller;
|
public NodeCenterClientController controller;
|
||||||
public Map<String, ResultCallback> distributeReqMap = new ConcurrentHashMap<>();
|
public Map<String, ResultCallback> distributeReqMap = new ConcurrentHashMap<>();
|
||||||
@ -45,19 +44,17 @@ public class NodeCenterClientHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
ae = new ActionExecutor<>(ContractManagerFrameHandler.executorService, controller);
|
ae = new ActionExecutor<>(ContractManagerFrameHandler.executorService, controller);
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
hasPermission = false;
|
hasPermission = false;
|
||||||
if (CMHttpServer.cmdConf.clientToClusterPlugins != null){
|
for (String str : clientToClusterPlugins) {
|
||||||
for (String str:CMHttpServer.cmdConf.clientToAgentPlugins){
|
Object obj = createInstanceByClzName(str);
|
||||||
Object obj = createInstanceByClzName(str);
|
ae.appendHandler(obj);
|
||||||
ae.appendHandler(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object createInstanceByClzName(String clzName){
|
private Object createInstanceByClzName(String clzName) {
|
||||||
try {
|
try {
|
||||||
Class clz = Class.forName(clzName,true,pluginLoader);
|
Class<?> clz = Class.forName(clzName, true, pluginLoader);
|
||||||
return clz.newInstance();
|
return clz.newInstance();
|
||||||
}catch(Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,7 +91,7 @@ public class NodeCenterClientHandler extends SimpleChannelInboundHandler<Object>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
|
||||||
ByteBuf bb = (ByteBuf) msg;
|
ByteBuf bb = (ByteBuf) msg;
|
||||||
byte[] bytes = null;
|
byte[] bytes = null;
|
||||||
try {
|
try {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.bdware.server.tcp;
|
package org.bdware.server.tcp;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufInputStream;
|
import io.netty.buffer.ByteBufInputStream;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
@ -13,8 +12,6 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.bdware.server.CMDConf;
|
|
||||||
import org.bdware.server.CMHttpServer;
|
|
||||||
import org.bdware.server.CongestionControl;
|
import org.bdware.server.CongestionControl;
|
||||||
import org.bdware.server.action.ActionExecutor;
|
import org.bdware.server.action.ActionExecutor;
|
||||||
import org.bdware.server.action.p2p.MasterClientRecoverMechAction;
|
import org.bdware.server.action.p2p.MasterClientRecoverMechAction;
|
||||||
@ -33,7 +30,8 @@ import static org.bdware.server.CMHttpServer.pluginLoader;
|
|||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
public class MasterClientFrameHandler extends SimpleChannelInboundHandler<Object> {
|
public class MasterClientFrameHandler extends SimpleChannelInboundHandler<Object> {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MasterClientFrameHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(MasterClientFrameHandler.class);
|
||||||
static ExecutorService executorService = Executors.newFixedThreadPool(10);
|
private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||||
|
public static String[] clientToAgentPlugins;
|
||||||
public String pubKey;
|
public String pubKey;
|
||||||
public ActionExecutor<ResultCallback, JsonObject> ae;
|
public ActionExecutor<ResultCallback, JsonObject> ae;
|
||||||
MasterClientTCPAction actions;
|
MasterClientTCPAction actions;
|
||||||
@ -49,22 +47,19 @@ public class MasterClientFrameHandler extends SimpleChannelInboundHandler<Object
|
|||||||
actions = new MasterClientTCPAction(this, master);
|
actions = new MasterClientTCPAction(this, master);
|
||||||
recoverActions = new MasterClientRecoverMechAction(this, actions);
|
recoverActions = new MasterClientRecoverMechAction(this, actions);
|
||||||
transferActions = new MasterClientTransferAction(this, master, actions);
|
transferActions = new MasterClientTransferAction(this, master, actions);
|
||||||
ae =
|
ae = new ActionExecutor<>(
|
||||||
new ActionExecutor<ResultCallback, JsonObject>(
|
executorService, actions, recoverActions, transferActions);
|
||||||
executorService, actions, recoverActions, transferActions);
|
for (String str : clientToAgentPlugins) {
|
||||||
if (CMHttpServer.cmdConf.clientToAgentPlugins != null){
|
Object obj = createInstanceByClzName(str);
|
||||||
for (String str:CMHttpServer.cmdConf.clientToAgentPlugins){
|
ae.appendHandler(obj);
|
||||||
Object obj = createInstanceByClzName(str);
|
|
||||||
ae.appendHandler(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object createInstanceByClzName(String clzName){
|
private Object createInstanceByClzName(String clzName) {
|
||||||
try {
|
try {
|
||||||
Class clz = Class.forName(clzName,true,pluginLoader);
|
Class<?> clz = Class.forName(clzName, true, pluginLoader);
|
||||||
return clz.newInstance();
|
return clz.newInstance();
|
||||||
}catch(Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,15 +108,11 @@ public class MasterClientFrameHandler extends SimpleChannelInboundHandler<Object
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, Object frame) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, Object frame) {
|
||||||
ByteBuf bb = (ByteBuf) frame;
|
ByteBuf bb = (ByteBuf) frame;
|
||||||
JsonObject arg;
|
JsonObject arg;
|
||||||
try {
|
try {
|
||||||
arg =
|
arg = JsonUtil.parseObject(new InputStreamReader(new ByteBufInputStream(bb)));
|
||||||
new JsonParser()
|
|
||||||
.parse(new InputStreamReader(new ByteBufInputStream(bb)))
|
|
||||||
.getAsJsonObject();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Response response = new Response();
|
Response response = new Response();
|
||||||
@ -189,8 +180,7 @@ public class MasterClientFrameHandler extends SimpleChannelInboundHandler<Object
|
|||||||
}
|
}
|
||||||
if (isOpen()) {
|
if (isOpen()) {
|
||||||
try {
|
try {
|
||||||
JsonObject jo = new JsonParser().parse(json).getAsJsonObject();
|
JsonObject jo = JsonUtil.parseObject(json);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.out.println("============[MasterClientFrameHandler]JsonParse Error:" + json);
|
System.out.println("============[MasterClientFrameHandler]JsonParse Error:" + json);
|
||||||
|
@ -10,11 +10,11 @@ import org.apache.logging.log4j.LogManager;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
import org.bdware.sc.util.JsonUtil;
|
import org.bdware.sc.util.JsonUtil;
|
||||||
import org.bdware.server.CMDConf;
|
|
||||||
import org.bdware.server.CMHttpServer;
|
import org.bdware.server.CMHttpServer;
|
||||||
import org.bdware.server.CongestionControl;
|
import org.bdware.server.CongestionControl;
|
||||||
import org.bdware.server.GRPCPool;
|
import org.bdware.server.GRPCPool;
|
||||||
import org.bdware.server.action.*;
|
import org.bdware.server.action.*;
|
||||||
|
import org.bdware.server.http.CMHttpHandler;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
@ -100,19 +100,17 @@ public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<Web
|
|||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (CMHttpServer.cmdConf.wsPluginActions != null){
|
for (String str : CMHttpHandler.wsPluginActions) {
|
||||||
for (String str:CMHttpServer.cmdConf.wsPluginActions){
|
Object obj = createInstanceByClzName(str);
|
||||||
Object obj = createInstanceByClzName(str);
|
ae.appendHandler(obj);
|
||||||
ae.appendHandler(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object createInstanceByClzName(String clzName){
|
private Object createInstanceByClzName(String clzName) {
|
||||||
try {
|
try {
|
||||||
Class clz = Class.forName(clzName,true,pluginLoader);
|
Class<?> clz = Class.forName(clzName, true, pluginLoader);
|
||||||
return clz.newInstance();
|
return clz.newInstance();
|
||||||
}catch(Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,7 +185,6 @@ public class ContractManagerFrameHandler extends SimpleChannelInboundHandler<Web
|
|||||||
@Override
|
@Override
|
||||||
public void onResult(Map jo) {
|
public void onResult(Map jo) {
|
||||||
if (jmap.has("requestID")) {
|
if (jmap.has("requestID")) {
|
||||||
|
|
||||||
jo.put("responseID", jmap.get("requestID").getAsString());
|
jo.put("responseID", jmap.get("requestID").getAsString());
|
||||||
}
|
}
|
||||||
onResult(JsonUtil.toJson(jo));
|
onResult(JsonUtil.toJson(jo));
|
||||||
|
@ -10,7 +10,6 @@ import io.netty.handler.timeout.IdleStateEvent;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
import org.bdware.server.CMHttpServer;
|
|
||||||
import org.bdware.server.action.ActionExecutor;
|
import org.bdware.server.action.ActionExecutor;
|
||||||
import org.bdware.units.grpc.BDLedgerContract;
|
import org.bdware.units.grpc.BDLedgerContract;
|
||||||
import org.bdware.units.grpc.BDLedgerContract.UnitMessage;
|
import org.bdware.units.grpc.BDLedgerContract.UnitMessage;
|
||||||
@ -21,6 +20,7 @@ import static org.bdware.server.CMHttpServer.pluginLoader;
|
|||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
public class TCPClientFrameHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
public class TCPClientFrameHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(TCPClientFrameHandler.class);
|
private static final Logger LOGGER = LogManager.getLogger(TCPClientFrameHandler.class);
|
||||||
|
public static String[] tcpPlugins;
|
||||||
ActionExecutor<ResultCallback, JsonObject> ae;
|
ActionExecutor<ResultCallback, JsonObject> ae;
|
||||||
ChannelHandlerContext ctx;
|
ChannelHandlerContext ctx;
|
||||||
private Channel channel;
|
private Channel channel;
|
||||||
@ -30,19 +30,17 @@ public class TCPClientFrameHandler extends SimpleChannelInboundHandler<ByteBuf>
|
|||||||
public TCPClientFrameHandler(String peerId) {
|
public TCPClientFrameHandler(String peerId) {
|
||||||
peer = peerId;
|
peer = peerId;
|
||||||
// heartBeat = new HeartBeatProtocol(peer);
|
// heartBeat = new HeartBeatProtocol(peer);
|
||||||
if (CMHttpServer.cmdConf.tcpPlugins != null){
|
for (String str : tcpPlugins) {
|
||||||
for (String str:CMHttpServer.cmdConf.tcpPlugins){
|
Object obj = createInstanceByClzName(str);
|
||||||
Object obj = createInstanceByClzName(str);
|
ae.appendHandler(obj);
|
||||||
ae.appendHandler(obj);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object createInstanceByClzName(String clzName){
|
private Object createInstanceByClzName(String clzName) {
|
||||||
try {
|
try {
|
||||||
Class clz = Class.forName(clzName,true,pluginLoader);
|
Class<?> clz = Class.forName(clzName, true, pluginLoader);
|
||||||
return clz.newInstance();
|
return clz.newInstance();
|
||||||
}catch(Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +90,7 @@ public class TCPClientFrameHandler extends SimpleChannelInboundHandler<ByteBuf>
|
|||||||
bb.readBytes(bytes);
|
bb.readBytes(bytes);
|
||||||
unitMessage = UnitMessage.parseFrom(bytes);
|
unitMessage = UnitMessage.parseFrom(bytes);
|
||||||
} catch (InvalidProtocolBufferException e) {
|
} catch (InvalidProtocolBufferException e) {
|
||||||
LOGGER.error("[TCPClientFrameHandler] receive msg" + bb.toString());
|
LOGGER.error("receive msg " + bb);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user