| package com.dy.rtuMw.server.msCenter; | 
|   | 
| import com.dy.common.mw.UnitAdapterInterface; | 
| import com.dy.common.mw.UnitCallbackInterface; | 
| import com.dy.common.mw.UnitInterface; | 
|   | 
| /** | 
|  * @Author: liurunyu | 
|  * @Date: 2025/2/12 13:55 | 
|  * @Description | 
|  */ | 
| public class MsCenterUnit  implements UnitInterface { | 
|   | 
|     private static MsCenterUnit instance = new MsCenterUnit() ; | 
|   | 
|     public static MsCenterUnitAdapter adapter ; | 
|     public static MsCenterConfigVo confVo ; | 
|   | 
|     private static MsCenterManager manager ; | 
|   | 
|     private MsCenterUnit(){} ; | 
|   | 
|     public static MsCenterUnit getInstance(){ | 
|         return instance ; | 
|     } | 
|   | 
|     @Override | 
|     public void setAdapter(UnitAdapterInterface adapter) throws Exception { | 
|         if(adapter == null){ | 
|             throw new Exception("消息中心模块适配器对象不能为空!") ; | 
|         } | 
|         MsCenterUnit.adapter = (MsCenterUnitAdapter)adapter ; | 
|         MsCenterUnit.confVo = MsCenterUnit.adapter.getConfig() ; | 
|         if(MsCenterUnit.confVo == null){ | 
|             throw new Exception("消息中心模块配置对象不能为空!") ; | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 初始化 | 
|      */ | 
|     @Override | 
|     public void start(UnitCallbackInterface callback) throws Exception { | 
|         if(confVo.enable){ | 
|             manager = MsCenterManager.getInstance() ; | 
|             manager.initOption(confVo); | 
|             manager.start(1000L, confVo.notifyMsInterval, manager); | 
|             callback.call(null) ; | 
|             System.out.println("消息中心模块成功启动"); | 
|         }else{ | 
|             System.out.println("消息中心模块配置不启动"); | 
|         } | 
|   | 
|     } | 
|   | 
|     @Override | 
|     public void stop(UnitCallbackInterface callback) throws Exception { | 
|         if(manager != null){ | 
|             manager.stop(); | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 存入消息 | 
|      * @param msNode | 
|      */ | 
|     public void pushMs(MsObj msNode){ | 
|         if(manager != null){ | 
|             manager.pushMs(msNode) ; | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 注册消息接收器 | 
|      * @param webUrl 接收者web http post url | 
|      */ | 
|     public void registerMsReceiver(String webUrl){ | 
|         if(manager != null){ | 
|             manager.registerMsReceiver(webUrl) ; | 
|         } | 
|     } | 
|   | 
| } |