|
@@ -8,10 +8,12 @@ import org.jetlinks.community.network.manager.entity.DeviceGatewayEntity;
|
|
import org.springframework.boot.CommandLineRunner;
|
|
import org.springframework.boot.CommandLineRunner;
|
|
import org.springframework.core.annotation.Order;
|
|
import org.springframework.core.annotation.Order;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
|
+
|
|
|
|
+import java.time.Duration;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author wangzheng
|
|
* @author wangzheng
|
|
- * @see
|
|
|
|
* @since 1.0
|
|
* @since 1.0
|
|
*/
|
|
*/
|
|
@Order(1)
|
|
@Order(1)
|
|
@@ -23,23 +25,31 @@ public class SyncDeviceGatewayState implements CommandLineRunner {
|
|
|
|
|
|
private final DeviceGatewayManager deviceGatewayManager;
|
|
private final DeviceGatewayManager deviceGatewayManager;
|
|
|
|
|
|
|
|
+ private final Duration gatewayStartupDelay = Duration.ofSeconds(5);
|
|
|
|
+
|
|
public SyncDeviceGatewayState(DeviceGatewayService deviceGatewayService, DeviceGatewayManager deviceGatewayManager) {
|
|
public SyncDeviceGatewayState(DeviceGatewayService deviceGatewayService, DeviceGatewayManager deviceGatewayManager) {
|
|
this.deviceGatewayService = deviceGatewayService;
|
|
this.deviceGatewayService = deviceGatewayService;
|
|
this.deviceGatewayManager = deviceGatewayManager;
|
|
this.deviceGatewayManager = deviceGatewayManager;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void run(String... args) throws Exception {
|
|
|
|
- deviceGatewayService.createQuery()
|
|
|
|
- .where()
|
|
|
|
- .and(DeviceGatewayEntity::getState, NetworkConfigState.enabled)
|
|
|
|
- .fetch()
|
|
|
|
- .map(DeviceGatewayEntity::getId)
|
|
|
|
- .flatMap(deviceGatewayManager::getGateway)
|
|
|
|
- .flatMap(DeviceGateway::startup)
|
|
|
|
- .onErrorContinue((err, obj) -> {
|
|
|
|
- log.error(err.getMessage(), err);
|
|
|
|
- })
|
|
|
|
|
|
+ public void run(String... args) {
|
|
|
|
+ log.debug("start device gateway in {} later", gatewayStartupDelay);
|
|
|
|
+ Mono.delay(gatewayStartupDelay)
|
|
|
|
+ .then(
|
|
|
|
+ deviceGatewayService
|
|
|
|
+ .createQuery()
|
|
|
|
+ .where()
|
|
|
|
+ .and(DeviceGatewayEntity::getState, NetworkConfigState.enabled)
|
|
|
|
+ .fetch()
|
|
|
|
+ .map(DeviceGatewayEntity::getId)
|
|
|
|
+ .flatMap(deviceGatewayManager::getGateway)
|
|
|
|
+ .flatMap(DeviceGateway::startup)
|
|
|
|
+ .onErrorContinue((err, obj) -> {
|
|
|
|
+ log.error(err.getMessage(), err);
|
|
|
|
+ })
|
|
|
|
+ .then()
|
|
|
|
+ )
|
|
.subscribe();
|
|
.subscribe();
|
|
}
|
|
}
|
|
}
|
|
}
|