com.ikasoa.rpc.handler.ProtocolHandlerFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ikasoa-rpc Show documentation
Show all versions of ikasoa-rpc Show documentation
ikasoa-rpc is a high performance RPC(Remote Procedure Call) framework.
package com.ikasoa.rpc.handler;
import lombok.SneakyThrows;
/**
* 转换协议处理器工厂
*
* @author Larry
* @version 0.1
*/
public class ProtocolHandlerFactory {
private static final String DEFAULT_PROTOCOL_HANDLER_CLASS_STRING = "com.ikasoa.rpc.handler.impl.JsonProtocolHandlerImpl";
public ProtocolHandler getProtocolHandler(ReturnData resultData) {
return getProtocolHandler(resultData, null);
}
@SneakyThrows
@SuppressWarnings({ "rawtypes", "unchecked" })
public ProtocolHandler getProtocolHandler(ReturnData resultData,
Class protocolHandlerClass) {
Class[] paramTypes = { ReturnData.class };
Object[] params = { resultData };
return protocolHandlerClass == null
? (ProtocolHandler) Class.forName(DEFAULT_PROTOCOL_HANDLER_CLASS_STRING)
.getConstructor(paramTypes).newInstance(params)
: (ProtocolHandler) protocolHandlerClass.getConstructor(paramTypes).newInstance(params);
}
}