|
@@ -6,6 +6,8 @@ import org.hswebframework.web.logger.ReactiveLogger;
|
|
|
import org.jetlinks.community.bridge.core.AliBridgeCodec;
|
|
import org.jetlinks.community.bridge.core.AliBridgeCodec;
|
|
|
import org.jetlinks.community.bridge.entity.AliIotBridgeEntity;
|
|
import org.jetlinks.community.bridge.entity.AliIotBridgeEntity;
|
|
|
import org.jetlinks.community.bridge.message.AliBridgeMessage;
|
|
import org.jetlinks.community.bridge.message.AliBridgeMessage;
|
|
|
|
|
+import org.jetlinks.core.cluster.ClusterManager;
|
|
|
|
|
+import org.jetlinks.core.cluster.ClusterService;
|
|
|
import org.jetlinks.core.device.DeviceRegistry;
|
|
import org.jetlinks.core.device.DeviceRegistry;
|
|
|
import org.jetlinks.core.event.EventBus;
|
|
import org.jetlinks.core.event.EventBus;
|
|
|
import org.jetlinks.core.message.CommonDeviceMessage;
|
|
import org.jetlinks.core.message.CommonDeviceMessage;
|
|
@@ -19,8 +21,6 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
import reactor.core.publisher.*;
|
|
import reactor.core.publisher.*;
|
|
|
import reactor.core.scheduler.Schedulers;
|
|
import reactor.core.scheduler.Schedulers;
|
|
|
-
|
|
|
|
|
-import java.time.Duration;
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -35,7 +35,7 @@ import java.util.Objects;
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
-public class AliBridgeGateway{
|
|
|
|
|
|
|
+public class AliBridgeGateway extends ClusterService<AliIotBridgeEntity> {
|
|
|
private Map<String,AliBridgeServer> bridgeMap=new HashMap<>();
|
|
private Map<String,AliBridgeServer> bridgeMap=new HashMap<>();
|
|
|
private final EmitterProcessor<Message> messageProcessor = EmitterProcessor.create(false);
|
|
private final EmitterProcessor<Message> messageProcessor = EmitterProcessor.create(false);
|
|
|
|
|
|
|
@@ -48,10 +48,18 @@ public class AliBridgeGateway{
|
|
|
|
|
|
|
|
public AliBridgeGateway(DeviceRegistry registry,
|
|
public AliBridgeGateway(DeviceRegistry registry,
|
|
|
EventBus eventBus,
|
|
EventBus eventBus,
|
|
|
|
|
+ ClusterManager clusterManager,
|
|
|
DecodedClientMessageHandler messageHandler) {
|
|
DecodedClientMessageHandler messageHandler) {
|
|
|
|
|
+ super(clusterManager);
|
|
|
this.registry = registry;
|
|
this.registry = registry;
|
|
|
this.eventBus=eventBus;
|
|
this.eventBus=eventBus;
|
|
|
this.messageHandler = messageHandler;
|
|
this.messageHandler = messageHandler;
|
|
|
|
|
+
|
|
|
|
|
+ this.handleClusterMsg()
|
|
|
|
|
+ .flatMap(replaceMsg->
|
|
|
|
|
+ replaceBridgeServer(replaceMsg,false)
|
|
|
|
|
+ ).subscribe();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -104,7 +112,9 @@ public class AliBridgeGateway{
|
|
|
|
|
|
|
|
|
|
|
|
|
public Mono<AliBridgeServer> replaceBridgeServer(AliIotBridgeEntity bridge,boolean broadcast){
|
|
public Mono<AliBridgeServer> replaceBridgeServer(AliIotBridgeEntity bridge,boolean broadcast){
|
|
|
- return initBridge(bridge,broadcast)
|
|
|
|
|
|
|
+ return Mono.zip(Mono.just(broadcast)
|
|
|
|
|
+ .filter(Boolean.TRUE::equals)
|
|
|
|
|
+ .flatMap(ignore->sendClusterMsg(bridge)),initBridge(bridge,broadcast))
|
|
|
.then(lookUpServer(bridge.getId()));
|
|
.then(lookUpServer(bridge.getId()));
|
|
|
}
|
|
}
|
|
|
|
|
|