优化级联注册,以及sip日志

This commit is contained in:
648540858
2022-12-12 10:28:36 +08:00
parent 1516991372
commit c1145a8163
8 changed files with 77 additions and 146 deletions

View File

@@ -154,7 +154,8 @@ public class DeviceServiceImpl implements IDeviceService {
}
// 刷新过期任务
String registerExpireTaskKey = registerExpireTaskKeyPrefix + device.getDeviceId();
dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), device.getExpires() * 1000);
// 增加一个10秒给设备重发消息的机会
dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), (device.getExpires() + 10) * 1000);
}
@Override

View File

@@ -135,14 +135,7 @@ public class PlatformServiceImpl implements IPlatformService {
dynamicTask.startCron(registerTaskKey,
// 注册失败注册成功时由程序直接调用了online方法
()-> {
try {
logger.info("[国标级联] 平台:{}注册即将到期,重新注册", parentPlatform.getServerGBId());
commanderForPlatform.register(parentPlatform, eventResult -> {
offline(parentPlatform, false);
},null);
} catch (InvalidArgumentException | ParseException | SipException e) {
logger.error("[命令发送失败] 国标级联定时注册: {}", e.getMessage());
}
registerTask(parentPlatform);
},
(parentPlatform.getExpires() - 10) *1000);
}
@@ -194,6 +187,28 @@ public class PlatformServiceImpl implements IPlatformService {
}
}
private void registerTask(ParentPlatform parentPlatform){
try {
// 设置超时重发, 后续从底层支持消息重发
String key = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId() + "_timeout";
if (dynamicTask.isAlive(key)) {
return;
}
dynamicTask.startDelay(key, ()->{
registerTask(parentPlatform);
}, 1000);
logger.info("[国标级联] 平台:{}注册即将到期,重新注册", parentPlatform.getServerGBId());
commanderForPlatform.register(parentPlatform, eventResult -> {
dynamicTask.stop(key);
offline(parentPlatform, false);
},eventResult -> {
dynamicTask.stop(key);
});
} catch (InvalidArgumentException | ParseException | SipException e) {
logger.error("[命令发送失败] 国标级联定时注册: {}", e.getMessage());
}
}
@Override
public void offline(ParentPlatform parentPlatform, boolean stopRegister) {
logger.info("[平台离线]{}", parentPlatform.getServerGBId());