| package com.dy.rtuMw.server.mqtt; | 
|   | 
| import com.dy.common.mw.UnitAdapterInterface; | 
| import com.dy.common.mw.UnitCallbackInterface; | 
| import com.dy.common.mw.UnitInterface; | 
|   | 
| /** | 
|  * @Author: liurunyu | 
|  * @Date: 2025/6/4 14:46 | 
|  * @Description | 
|  */ | 
| public class MqttUnit  implements UnitInterface { | 
|   | 
|     private static MqttUnit instance = new MqttUnit() ; | 
|   | 
|     public static MqttUnitAdapter adapter ; | 
|     public static MqttUnitConfigVo confVo ; | 
|   | 
|     private static MqttManager manager ; | 
|     private MqttUnit(){} ; | 
|   | 
|     public static MqttUnit getInstance(){ | 
|         return instance ; | 
|     } | 
|   | 
|     @Override | 
|     public void setAdapter(UnitAdapterInterface adapter) throws Exception { | 
|         if(adapter == null){ | 
|             throw new Exception("Mqtt消息模块适配器对象不能为空!") ; | 
|         } | 
|         MqttUnit.adapter = (MqttUnitAdapter)adapter ; | 
|         MqttUnit.confVo = MqttUnit.adapter.getConfig() ; | 
|         if(MqttUnit.confVo == null){ | 
|             throw new Exception("Mqtt消息模块配置对象不能为空!") ; | 
|         } | 
|     } | 
|   | 
|     /** | 
|      * 初始化 | 
|      */ | 
|     @Override | 
|     public void start(UnitCallbackInterface callback) throws Exception { | 
|         if(confVo.enable){ | 
|             manager = MqttManager.getInstance() ; | 
|             manager.initOption(confVo); | 
|             manager.start(); | 
|             callback.call(null) ; | 
|             System.out.println("Mqtt消息模块成功启动"); | 
|         }else{ | 
|             System.out.println("Mqtt消息模块配置不启动"); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public void stop(UnitCallbackInterface callback) throws Exception { | 
|         if(manager != null){ | 
|             manager.stop(); | 
|         } | 
|         callback.call(null) ; | 
|     } | 
|   | 
|     public void recover(UnitCallbackInterface callback) throws Exception { | 
|         this.start(callback) ; | 
|         callback.call(null) ; | 
|     } | 
|   | 
| } |