|
|
@ -5,6 +5,10 @@ import io.netty.channel.ChannelInboundHandlerAdapter; |
|
|
|
import io.netty.handler.timeout.IdleStateEvent; |
|
|
|
import io.netty.handler.timeout.IdleStateEvent; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.remote.rpc.common.RpcRequest; |
|
|
|
import org.apache.dolphinscheduler.remote.rpc.common.RpcRequest; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.remote.rpc.common.RpcResponse; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
@ -36,11 +40,28 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void channelRead(ChannelHandlerContext ctx, Object msg) { |
|
|
|
public void channelRead(ChannelHandlerContext ctx, Object msg) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { |
|
|
|
logger.info("server read msg"); |
|
|
|
logger.info("server read msg"); |
|
|
|
System.out.println("收到消息"); |
|
|
|
System.out.println("收到消息"); |
|
|
|
RpcRequest req= (RpcRequest) msg; |
|
|
|
RpcRequest req= (RpcRequest) msg; |
|
|
|
System.out.println(req.getRequestId()); |
|
|
|
System.out.println(req.getRequestId()); |
|
|
|
|
|
|
|
RpcResponse response=new RpcResponse(); |
|
|
|
|
|
|
|
response.setMsg("llll"); |
|
|
|
|
|
|
|
response.setRequestId(req.getRequestId()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Class<?> handlerClass = req.getClass(); |
|
|
|
|
|
|
|
System.out.println(req.getMethodName()); |
|
|
|
|
|
|
|
System.out.println(req.getClassName()); |
|
|
|
|
|
|
|
String methodName = req.getMethodName(); |
|
|
|
|
|
|
|
Class<?>[] parameterTypes = req.getParameterTypes(); |
|
|
|
|
|
|
|
Object[] parameters = req.getParameters(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// JDK reflect
|
|
|
|
|
|
|
|
Method method = handlerClass.getMethod(methodName, parameterTypes); |
|
|
|
|
|
|
|
method.setAccessible(true); |
|
|
|
|
|
|
|
Object result = method.invoke(req.getClassName(), parameters); |
|
|
|
|
|
|
|
response.setResult(result); |
|
|
|
|
|
|
|
ctx.writeAndFlush(response); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|