背景介绍
在某些项目中会使用插件化技术实现一些动态“插拔”或热更新的功能。一般的做法是,定义一个标准接口,然后将实现分离进行独立部署或更新。
现在有个场景,系统希望引入一些特殊的业务“函数”,并支持热更新。来看看我们是怎么实现的。
业务函数接口:IFunction.java
/** 业务函数接口 **/ public interface IFunction { /** 函数名称 **/ public String getName(); /** 函数描述 **/ public String getDesc(); /** 函数运行异常时返回默认值 **/ public Object getDefVal(); /** 调用函数 **/ public Object process(Object... args) throws Exception; /** 检查入参是否为空 **/ default boolean checkArgsIsEmpty(Object... args) { System.out.println(">> args=" + Arrays.toString(args)); return args == null || args.length == 0; } }