后台任务插件开发
Public interface nc.bs.pub.taskcenter. IBackgroundWorkPlugin { /** * 任务插件执行体 * @param context 执行环境 * @throws BusinessException */ PreAlertObject executeTask(BgWorkingContext context) throws BusinessException; } |
参数BgWorkingContext包含了后台任务插件类的上下文环境,主要的属性值如表格所示:
/** 当前登录日期 */ private UFDate loginDate = null; /** 备份数据源 */ private String datasource = null; /** 具体一些阈值的实参.对应结构为 key: 阈值字段名,value: 真实的值*/ private LinkedHashMap<String, Object> keyMap = new LinkedHashMap<String, Object>(); private String groupId = null; //集团 /** 当前用户,即部署任务的用户*/ private String pk_user; private String preAlertTypeName;//后台任务类型名称 private String registryName;//条目名称; private String registryFileName;//条目的后台任务文件名;对应后台任务则为任务描述; private int preAlertMode ;//后台任务模式--登录/触发点/按钮 see definition in the AlertMethod /** * 插件自己解析的数据. 适用于代码级直接调用时传递 */ private Object userData = null;
private String logString = null; //插件需要的日志信息(持久化到数据库) /**条目的PK*/ private String pk_registry; |
返回值是PreAlertObject类型,定义如下:
public class PreAlertObject { //默认预警消息标题,即消息中心看到的“默认主题”,如果预警条目中未设置消息标题,则取该属性值 private String msgTitle = null; //返回类型 //返回值,根据返回值类型(PreAlertReturnType)的不同,要求返回值对应如下: // 1 PreAlertReturnType.RETURNMESSAGE——>String (固定字符串类型) // 2 PreAlertReturnType.RETURNOBJECT——>Object (对象类型) // 若需支持消息模板功能,返回值类型必须是后两种 // 3 PreAlertReturnType.RETURNFORMATMSG——>IAlertMessage (格式化消息,可转换成打印模板数据源) // 4 PreAlertReturnType.RETURNDATASOURCE——>IDataSource (打印模板数据源) private PreAlertReturnType returnType = null; private Object returnObj = null; } |
其中,PreAlertReturnType为枚举类型,标记返回值的类型。
public enum PreAlertReturnType { RETURNMESSAGE, RETURNOBJECT, RETURNFORMATMSG, RETURNDATASOURCE;
public String toString() { switch (this) { case RETURNMESSAGE: return "插件返回字符串"; case RETURNFORMATMSG: return "插件返回格式化字符串"; case RETURNOBJECT: return "插件返回对象"; case RETURNDATASOURCE: return "消息模板数据源"; default: return null; } }} |
---------------------------
任务的业务插件的实现接口如下图所示:
插件类示例:
nc.bs.pub.pa.SamplePreAlertPlugin
public class SampleBackgroundPlugin implements IBackgroundWorkPlugin {
public PreAlertObject executeTask(BgWorkingContext bgwc) throws BusinessException { HashMap<String, Object> km = bgwc.getKeyMap(); Set<Entry<String, Object>> name = km.entrySet(); for (Entry<String, Object> entry : name) { System.out.print(entry.getKey() + "="); System.out.print(entry.getValue() + "\n"); } // leijun+ // longtimeWork(50000);//hzg-- PreAlertObject retObj = new PreAlertObject(); retObj.setReturnObj("业务插件成功执行完毕."); retObj.setReturnType(PreAlertReturnType.RETURNMESSAGE); return retObj; } |
文档代码下载链接:https://download.csdn.net/download/d_c_hao/10910994