【功能完善】IoT: 添加插件目录配置,重构 SpringPluginManager 实例化逻辑,删除不再使用的 ExampleService 类以优化代码结构。
This commit is contained in:
parent
5524324554
commit
a85890d958
|
@ -5,11 +5,13 @@ import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
|
|||
import cn.iocoder.yudao.module.iot.framework.plugin.listener.CustomPluginStateListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.pf4j.spring.SpringPluginManager;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.DependsOn;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
|
@ -19,6 +21,8 @@ public class UnifiedConfiguration {
|
|||
|
||||
@Resource
|
||||
private DeviceDataApi deviceDataApi;
|
||||
@Value("${pf4j.pluginsDir:pluginsDir}")
|
||||
private String pluginsDir;
|
||||
|
||||
@Bean(SERVICE_REGISTRY_INITIALIZED_MARKER)
|
||||
public Object serviceRegistryInitializedMarker() {
|
||||
|
@ -31,7 +35,7 @@ public class UnifiedConfiguration {
|
|||
@DependsOn(SERVICE_REGISTRY_INITIALIZED_MARKER)
|
||||
public SpringPluginManager pluginManager() {
|
||||
log.info("[init][实例化 SpringPluginManager]");
|
||||
SpringPluginManager springPluginManager = new SpringPluginManager() {
|
||||
SpringPluginManager springPluginManager = new SpringPluginManager(Paths.get(pluginsDir)) {
|
||||
@Override
|
||||
public void startPlugins() {
|
||||
// 禁用插件启动,避免插件启动时,启动所有插件
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package cn.iocoder.yudao.module.iot.service.plugin;
|
||||
|
||||
import cn.iocoder.yudao.module.iot.mqttrpc.server.RpcServer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ExampleService {
|
||||
|
||||
private final RpcServer rpcServer;
|
||||
|
||||
@PostConstruct
|
||||
public void registerMethods() {
|
||||
rpcServer.registerMethod("add", params -> {
|
||||
if (params.length != 2) {
|
||||
throw new IllegalArgumentException("add方法需要两个参数");
|
||||
}
|
||||
int a = ((Number) params[0]).intValue();
|
||||
int b = ((Number) params[1]).intValue();
|
||||
return add(a, b);
|
||||
});
|
||||
|
||||
rpcServer.registerMethod("concat", params -> {
|
||||
if (params.length != 2) {
|
||||
throw new IllegalArgumentException("concat方法需要两个参数");
|
||||
}
|
||||
String str1 = params[0].toString();
|
||||
String str2 = params[1].toString();
|
||||
return concat(str1, str2);
|
||||
});
|
||||
}
|
||||
|
||||
private int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
private String concat(String a, String b) {
|
||||
return a + b;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue