Pre Merge pull request !12 from anjun/2.11

This commit is contained in:
anjun 2025-12-21 03:18:31 +00:00 committed by Gitee
commit a9797416a3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 35 additions and 13 deletions

View File

@ -123,14 +123,29 @@ public class DefaultDeviceGatewayManager implements DeviceGatewayManager {
.compute(gatewayId, (id, gateway) -> {
if (gateway != null) {
log.debug("reload device gateway {} {}:{}", prop.getName(), prop.getProvider(), prop.getId());
return provider
Mono<DeviceGateway> reloaded = provider
.reloadDeviceGateway(gateway, prop)
.cast(DeviceGateway.class);
// 如果网关被禁用重载后不启动
if (!prop.isEnabled()) {
return reloaded.flatMap(g -> {
log.debug("device gateway {} is disabled, skip startup", gatewayId);
return Mono.just(g);
});
}
return reloaded;
}
log.debug("create device gateway {} {}:{}", prop.getName(), prop.getProvider(), prop.getId());
return provider
Mono<DeviceGateway> created = provider
.createDeviceGateway(prop)
.flatMap(newer -> newer.startup().thenReturn(newer));
.cast(DeviceGateway.class);
// 只有启用的网关才自动启动
if (prop.isEnabled()) {
return created.flatMap(newer -> newer.startup().thenReturn(newer));
} else {
log.debug("device gateway {} is disabled, skip startup", gatewayId);
return created;
}
});
})
.then();

View File

@ -17,6 +17,15 @@ package org.jetlinks.community.plugin.device;
import org.hswebframework.web.exception.BusinessException;
import org.hswebframework.web.i18n.LocaleUtils;
import org.jetlinks.community.PropertyConstants;
import org.jetlinks.community.codec.Serializers;
import org.jetlinks.community.gateway.DeviceGateway;
import org.jetlinks.community.gateway.supports.DeviceGatewayProperties;
import org.jetlinks.community.gateway.supports.DeviceGatewayProvider;
import org.jetlinks.community.plugin.PluginDriverManager;
import org.jetlinks.community.plugin.context.*;
import org.jetlinks.community.plugin.monitor.PluginMonitorHelper;
import org.jetlinks.community.plugin.utils.PluginUtils;
import org.jetlinks.core.defaults.CompositeProtocolSupport;
import org.jetlinks.core.device.DeviceOperator;
import org.jetlinks.core.device.DeviceRegistry;
@ -36,15 +45,6 @@ import org.jetlinks.plugin.core.ServiceRegistry;
import org.jetlinks.plugin.internal.PluginDataIdMapper;
import org.jetlinks.plugin.internal.device.DeviceGatewayPlugin;
import org.jetlinks.plugin.internal.device.PluginDeviceGatewayService;
import org.jetlinks.community.PropertyConstants;
import org.jetlinks.community.codec.Serializers;
import org.jetlinks.community.gateway.DeviceGateway;
import org.jetlinks.community.gateway.supports.DeviceGatewayProperties;
import org.jetlinks.community.gateway.supports.DeviceGatewayProvider;
import org.jetlinks.community.plugin.PluginDriverManager;
import org.jetlinks.community.plugin.context.*;
import org.jetlinks.community.plugin.monitor.PluginMonitorHelper;
import org.jetlinks.community.plugin.utils.PluginUtils;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
@ -235,7 +235,14 @@ public class PluginDeviceGatewayProvider extends CompositeProtocolSupport
.unwrap(PluginDeviceGateway.class)
.shutdown()
.then(createDeviceGateway(properties))
.flatMap(gate -> gate.startup().thenReturn(gate));
.flatMap(gate -> {
// 只有启用的网关才自动启动
if (properties.isEnabled()) {
return gate.startup().thenReturn(gate);
} else {
return Mono.just(gate);
}
});
}
@Override