Commit f4ad3e9d2d66ba93303ce3c7f70ff0b90527da87
1 parent
7bfa8306
【代码评审】IoT:插件体系
Showing
4 changed files
with
16 additions
and
19 deletions
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-common/src/main/java/cn/iocoder/yudao/module/iot/plugin/common/config/YudaoDeviceDataApiAutoConfiguration.java
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/HttpPluginSpringbootApplication.java
| ... | ... | @@ -20,8 +20,7 @@ public class HttpPluginSpringbootApplication { |
| 20 | 20 | ConfigurableApplicationContext context = application.run(args); |
| 21 | 21 | |
| 22 | 22 | // 手动获取 VertxService 并启动 |
| 23 | - // TODO @haohao:可以放在 bean 的 init 里么? | |
| 24 | - // 会和插件模式冲突 | |
| 23 | + // TODO @haohao:可以放在 bean 的 init 里么?回复:会和插件模式冲突 @芋艿,测试下 | |
| 25 | 24 | VertxService vertxService = context.getBean(VertxService.class); |
| 26 | 25 | vertxService.startServer(); |
| 27 | 26 | ... | ... |
yudao-module-iot/yudao-module-iot-plugins/yudao-module-iot-plugin-http/src/main/java/cn/iocoder/yudao/module/iot/plugin/http/config/HttpVertxPlugin.java
| 1 | 1 | package cn.iocoder.yudao.module.iot.plugin.http.config; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.lang.Assert; | |
| 3 | 4 | import cn.hutool.extra.spring.SpringUtil; |
| 4 | 5 | import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi; |
| 5 | 6 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -21,62 +22,60 @@ public class HttpVertxPlugin extends SpringPlugin { |
| 21 | 22 | |
| 22 | 23 | @Override |
| 23 | 24 | public void start() { |
| 24 | - log.info("[HttpVertxPlugin][start][begin] 开始启动 HttpVertxPlugin 插件..."); | |
| 25 | - | |
| 25 | + log.info("[HttpVertxPlugin][HttpVertxPlugin 插件启动开始...]"); | |
| 26 | 26 | try { |
| 27 | 27 | // 1. 获取插件上下文 |
| 28 | 28 | ApplicationContext pluginContext = getApplicationContext(); |
| 29 | - if (pluginContext == null) { | |
| 30 | - log.error("[HttpVertxPlugin][start][fail] pluginContext is null, 启动失败!"); | |
| 31 | - return; | |
| 32 | - } | |
| 29 | + Assert.notNull(pluginContext, "pluginContext 不能为空"); | |
| 33 | 30 | |
| 34 | 31 | // 2. 启动 Vert.x |
| 35 | 32 | VertxService vertxService = pluginContext.getBean(VertxService.class); |
| 36 | 33 | vertxService.startServer(); |
| 37 | 34 | |
| 38 | - log.info("[HttpVertxPlugin][start][end] 启动完成"); | |
| 35 | + log.info("[HttpVertxPlugin][HttpVertxPlugin 插件启动成功...]"); | |
| 39 | 36 | } catch (Exception e) { |
| 40 | - log.error("[HttpVertxPlugin][start][exception] 启动过程出现异常!", e); | |
| 37 | + log.error("[HttpVertxPlugin][HttpVertxPlugin 插件开启动异常...]", e); | |
| 41 | 38 | } |
| 42 | 39 | } |
| 43 | 40 | |
| 44 | 41 | @Override |
| 45 | 42 | public void stop() { |
| 46 | - log.info("[HttpVertxPlugin][stop][begin] 开始停止 HttpVertxPlugin 插件..."); | |
| 47 | - | |
| 43 | + log.info("[HttpVertxPlugin][HttpVertxPlugin 插件停止开始...]"); | |
| 48 | 44 | try { |
| 45 | + // 停止服务器 | |
| 49 | 46 | ApplicationContext pluginContext = getApplicationContext(); |
| 50 | 47 | if (pluginContext != null) { |
| 51 | - // 停止服务器 | |
| 52 | 48 | VertxService vertxService = pluginContext.getBean(VertxService.class); |
| 53 | 49 | vertxService.stopServer(); |
| 54 | 50 | } |
| 55 | 51 | |
| 56 | - log.info("[HttpVertxPlugin][stop][end] 停止完成"); | |
| 52 | + log.info("[HttpVertxPlugin][HttpVertxPlugin 插件停止成功...]"); | |
| 57 | 53 | } catch (Exception e) { |
| 58 | - log.error("[HttpVertxPlugin][stop][exception] 停止过程出现异常!", e); | |
| 54 | + log.error("[HttpVertxPlugin][HttpVertxPlugin 插件停止异常...]", e); | |
| 59 | 55 | } |
| 60 | 56 | } |
| 61 | 57 | |
| 62 | 58 | @Override |
| 63 | 59 | protected ApplicationContext createApplicationContext() { |
| 60 | + // TODO @haohao:这个加 deviceDataApi 的目的是啥呀? | |
| 64 | 61 | AnnotationConfigApplicationContext pluginContext = new AnnotationConfigApplicationContext() { |
| 62 | + | |
| 65 | 63 | @Override |
| 66 | 64 | protected void prepareRefresh() { |
| 67 | 65 | // 在刷新容器前注册主程序中的 Bean |
| 68 | 66 | ConfigurableListableBeanFactory beanFactory = this.getBeanFactory(); |
| 69 | 67 | DeviceDataApi deviceDataApi = SpringUtil.getBean(DeviceDataApi.class); |
| 70 | 68 | beanFactory.registerSingleton("deviceDataApi", deviceDataApi); |
| 71 | - | |
| 72 | 69 | super.prepareRefresh(); |
| 73 | 70 | } |
| 71 | + | |
| 74 | 72 | }; |
| 75 | 73 | |
| 76 | 74 | pluginContext.setClassLoader(getWrapper().getPluginClassLoader()); |
| 75 | + // TODO @芋艿:枚举 | |
| 77 | 76 | pluginContext.scan("cn.iocoder.yudao.module.iot.plugin.http.config"); |
| 78 | 77 | pluginContext.refresh(); |
| 79 | - | |
| 80 | 78 | return pluginContext; |
| 81 | 79 | } |
| 80 | + | |
| 82 | 81 | } |
| 83 | 82 | \ No newline at end of file | ... | ... |