HessianSkeleton是Hessian server端的核心类,主要功能是接收网络输入流(被包装为AbstractHessianInput),反序列化输入流得到methodName和参数,然后调用服务端的服务,得到结果后序列化为输出流,返回给客户端,主要流程如下图所示:
HessianSkeleton的核心代码如下所示:
public void invoke(Object service, AbstractHessianInput in, AbstractHessianOutput out) throws Exception { ...... String methodName = in.readMethod(); Method method = getMethod(methodName); ...... Class []args = method.getParameterTypes(); Object []values = new Object[args.length]; for (int i = 0; i < args.length; i++) { values[i] = in.readObject(args[i]); } Object result = null; try { result = method.invoke(service, values); } catch (Throwable e) { ...... } // The complete call needs to be after the invoke to handle a // trailing InputStream in.completeCall(); out.startReply(); out.writeObject(result); out.completeReply(); out.close(); }
主流程代码非常清晰,不需要太多解释,关键的地方在于对网络流的序列化和反序列化,我会在hessian io分析的部分中进行详细阐述