|
@@ -36,7 +36,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class AliBridgeServer implements BridgeServer {
|
|
public class AliBridgeServer implements BridgeServer {
|
|
|
- private String productId;
|
|
|
|
|
private Map<String, Channel> channelMap=new ConcurrentHashMap<>();
|
|
private Map<String, Channel> channelMap=new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
private final EventBus eventBus;
|
|
private final EventBus eventBus;
|
|
@@ -53,14 +52,17 @@ public class AliBridgeServer implements BridgeServer {
|
|
|
|
|
|
|
|
private DefaultBridgeBootstrap bootstrap;
|
|
private DefaultBridgeBootstrap bootstrap;
|
|
|
|
|
|
|
|
|
|
+ private final String clusterId;
|
|
|
|
|
+
|
|
|
private final DeviceRegistry deviceRegistry;
|
|
private final DeviceRegistry deviceRegistry;
|
|
|
- public AliBridgeServer(EventBus eventBus,DeviceRegistry deviceRegistry) {
|
|
|
|
|
|
|
+ private AliBridgeServer(EventBus eventBus,DeviceRegistry deviceRegistry,String clusterId) {
|
|
|
this.deviceRegistry=deviceRegistry;
|
|
this.deviceRegistry=deviceRegistry;
|
|
|
this.eventBus = eventBus;
|
|
this.eventBus = eventBus;
|
|
|
|
|
+ this.clusterId=clusterId;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static Mono<AliBridgeServer> create(EventBus eventBus,DeviceRegistry deviceRegistry, AliIotBridgeEntity productMapping) {
|
|
|
|
|
- AliBridgeServer aliBridgeServer = new AliBridgeServer(eventBus,deviceRegistry);
|
|
|
|
|
|
|
+ public static Mono<AliBridgeServer> create(EventBus eventBus,DeviceRegistry deviceRegistry, AliIotBridgeEntity productMapping,String clusterId) {
|
|
|
|
|
+ AliBridgeServer aliBridgeServer = new AliBridgeServer(eventBus,deviceRegistry,clusterId);
|
|
|
return Mono.just(aliBridgeServer)
|
|
return Mono.just(aliBridgeServer)
|
|
|
.flatMap(server->server.initBridge(productMapping))
|
|
.flatMap(server->server.initBridge(productMapping))
|
|
|
.thenReturn(aliBridgeServer);
|
|
.thenReturn(aliBridgeServer);
|
|
@@ -70,8 +72,6 @@ public class AliBridgeServer implements BridgeServer {
|
|
|
if(start.get()){
|
|
if(start.get()){
|
|
|
return Mono.empty();
|
|
return Mono.empty();
|
|
|
}
|
|
}
|
|
|
- String productId = params.getProductId();
|
|
|
|
|
- Assert.notNull(productId,"创建网桥 productId 不能为空, mapping id {%s}",params.getId());
|
|
|
|
|
AliIotBridgeEntity.AccessConfig accessConfig = params.getAccessConfig();
|
|
AliIotBridgeEntity.AccessConfig accessConfig = params.getAccessConfig();
|
|
|
String productKey = accessConfig.getProductKey();
|
|
String productKey = accessConfig.getProductKey();
|
|
|
Assert.notNull(productKey,"创建网桥 productKey 不能为空, mapping id {%s}",params.getId());
|
|
Assert.notNull(productKey,"创建网桥 productKey 不能为空, mapping id {%s}",params.getId());
|
|
@@ -85,13 +85,12 @@ public class AliBridgeServer implements BridgeServer {
|
|
|
Assert.notNull(http2Endpoint,"创建网桥 http2Endpoint 不能为空, mapping id {%s}",params.getId());
|
|
Assert.notNull(http2Endpoint,"创建网桥 http2Endpoint 不能为空, mapping id {%s}",params.getId());
|
|
|
String regionId = accessConfig.getRegionId();
|
|
String regionId = accessConfig.getRegionId();
|
|
|
Assert.notNull(regionId,"创建网桥 regionId 不能为空, mapping id {%s}",params.getId());
|
|
Assert.notNull(regionId,"创建网桥 regionId 不能为空, mapping id {%s}",params.getId());
|
|
|
- bridgeConfigManager = DefaultBridgeConfigManager.of(productId,productKey, null, null, http2Endpoint, authEndpoint, null, getPopClientProfile(accessKey, accessSecret, regionId));
|
|
|
|
|
|
|
+ bridgeConfigManager = DefaultBridgeConfigManager.of(productKey, null, null, http2Endpoint, authEndpoint, null, getPopClientProfile(accessKey, accessSecret, regionId));
|
|
|
bootstrap=new DefaultBridgeBootstrap(bridgeConfigManager);
|
|
bootstrap=new DefaultBridgeBootstrap(bridgeConfigManager);
|
|
|
if(start.get()){
|
|
if(start.get()){
|
|
|
return Mono.empty();
|
|
return Mono.empty();
|
|
|
}
|
|
}
|
|
|
if (start.compareAndSet(false, true)) {
|
|
if (start.compareAndSet(false, true)) {
|
|
|
- this.productId=productId;
|
|
|
|
|
return Mono.fromRunnable(()->{
|
|
return Mono.fromRunnable(()->{
|
|
|
bootstrap.bootstrap(new DownlinkChannelHandler() {
|
|
bootstrap.bootstrap(new DownlinkChannelHandler() {
|
|
|
@Override
|
|
@Override
|
|
@@ -130,7 +129,7 @@ public class AliBridgeServer implements BridgeServer {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public String productId() {
|
|
public String productId() {
|
|
|
- return productId;
|
|
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -148,7 +147,7 @@ public class AliBridgeServer implements BridgeServer {
|
|
|
//注册设备信息
|
|
//注册设备信息
|
|
|
DefaultDeviceConfigManager.register(originalIdentity,productKey,deviceName,deviceSecret);
|
|
DefaultDeviceConfigManager.register(originalIdentity,productKey,deviceName,deviceSecret);
|
|
|
DefaultUplinkChannelHandler uplinkChannelHandler = new DefaultUplinkChannelHandler(bridgeConfigManager, DefaultDeviceConfigManager.getInstance());
|
|
DefaultUplinkChannelHandler uplinkChannelHandler = new DefaultUplinkChannelHandler(bridgeConfigManager, DefaultDeviceConfigManager.getInstance());
|
|
|
- channelMap.putIfAbsent(originalIdentity, new DefaultAliBridgeChannel(originalIdentity, productId, productKey, deviceName, uplinkChannelHandler, deviceRegistry, eventBus));
|
|
|
|
|
|
|
+ channelMap.putIfAbsent(originalIdentity, new DefaultAliBridgeChannel(originalIdentity, productKey, deviceName, uplinkChannelHandler, deviceRegistry, eventBus));
|
|
|
return Mono.just(channelMap.get(originalIdentity))
|
|
return Mono.just(channelMap.get(originalIdentity))
|
|
|
.doOnNext(Channel::init)
|
|
.doOnNext(Channel::init)
|
|
|
.flatMap(channel ->
|
|
.flatMap(channel ->
|
|
@@ -185,7 +184,7 @@ public class AliBridgeServer implements BridgeServer {
|
|
|
if(bootstrap!=null){
|
|
if(bootstrap!=null){
|
|
|
bootstrap.disconnectBridge();
|
|
bootstrap.disconnectBridge();
|
|
|
}
|
|
}
|
|
|
- log.info("产品网桥{}关闭",this.productId);
|
|
|
|
|
|
|
+ log.info("网桥[{}]关闭",clusterId);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -196,7 +195,7 @@ public class AliBridgeServer implements BridgeServer {
|
|
|
bootstrap.reconnectBridge();
|
|
bootstrap.reconnectBridge();
|
|
|
channelMap.values().forEach(Channel::online);
|
|
channelMap.values().forEach(Channel::online);
|
|
|
}
|
|
}
|
|
|
- log.info("产品网桥{}重启成功",this.productId);
|
|
|
|
|
|
|
+ log.info("网桥[{}]重启成功",clusterId);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|