✨ cms添加回调操作
This commit is contained in:
parent
220e723d4c
commit
c81be25465
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
</parent>
|
||||
<groupId>net.javase.hk</groupId>
|
||||
<artifactId>hk-sup-spring-boot-starter</artifactId>
|
||||
<version>0.0.3</version>
|
||||
<version>0.0.4</version>
|
||||
<name>hk-sup-spring-boot-starter</name>
|
||||
<description>hk-sup-spring-boot-starter</description>
|
||||
<properties>
|
||||
|
|
|
@ -36,13 +36,13 @@ public class CmsServer {
|
|||
private HCISUPCMS.DEVICE_REGISTER_CB deviceRegisterCb;
|
||||
HCISUPCMS.NET_EHOME_CMS_LISTEN_PARAM struCMSListenPara = new HCISUPCMS.NET_EHOME_CMS_LISTEN_PARAM();
|
||||
|
||||
private Runnable preStartCallback = null;
|
||||
private Runnable stopCallback = null;
|
||||
private CmsServerCallback callback = null;
|
||||
|
||||
public CmsServer(HkSupSdkProperties supSdkProperties, ApplicationContext applicationContext) {
|
||||
this.supSdkProperties = supSdkProperties;
|
||||
this.applicationContext = applicationContext;
|
||||
createSDKInstance();
|
||||
callback = applicationContext.getBeansOfType(CmsServerCallback.class).values().stream().findAny().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,28 +160,16 @@ public class CmsServer {
|
|||
*/
|
||||
void startCmsServer() {
|
||||
try {
|
||||
Optional.ofNullable(preStartCallback).ifPresent(Runnable::run);
|
||||
Optional<CmsServerCallback> opt = Optional.ofNullable(callback);
|
||||
opt.ifPresent(CmsServerCallback::preStart);
|
||||
cmsInit();
|
||||
startCmsListen();
|
||||
opt.ifPresent(CmsServerCallback::finishStart);
|
||||
} catch (Exception ex) {
|
||||
log.error("启动CMS注册服务失败: " + ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化服务 前置回调
|
||||
*/
|
||||
public void preStartCallback(Runnable callback) {
|
||||
this.preStartCallback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置停止服务后回调
|
||||
*/
|
||||
public void stopCallback(Runnable callback) {
|
||||
this.stopCallback = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止CMS服务,回收资源
|
||||
*/
|
||||
|
@ -192,7 +180,7 @@ public class CmsServer {
|
|||
hcisupcms.NET_ECMS_StopListen(CmsHandle);
|
||||
hcisupcms.NET_ECMS_Fini();
|
||||
log.info("停止CMS注册服务成功!");
|
||||
Optional.ofNullable(stopCallback).ifPresent(Runnable::run);
|
||||
Optional.ofNullable(callback).ifPresent(CmsServerCallback::finishStop);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
log.error("停止CMS注册服务失败: " + ex.getMessage(), ex);
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package net.javase.hksup.starter.service;
|
||||
|
||||
/**
|
||||
* CmsServerCallback
|
||||
*
|
||||
* @author Frank
|
||||
*/
|
||||
public interface CmsServerCallback {
|
||||
|
||||
void preStart();
|
||||
|
||||
void finishStart();
|
||||
|
||||
void finishStop();
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user