使用阿里代码规范。规范代码写法
This commit is contained in:
@@ -85,7 +85,9 @@ public class ZLMHttpHookSubscribe {
|
||||
if (result == null) {
|
||||
result = key.getString(s).equals(hookResponse.getString(s));
|
||||
}else {
|
||||
if (key.getString(s) == null) continue;
|
||||
if (key.getString(s) == null) {
|
||||
continue;
|
||||
}
|
||||
result = result && key.getString(s).equals(hookResponse.getString(s));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,9 @@ public class ZLMMediaListManager {
|
||||
|
||||
// 使用异步的当时更新媒体流列表
|
||||
zlmresTfulUtils.getMediaList(mediaServerItem, (mediaList ->{
|
||||
if (mediaList == null) return;
|
||||
if (mediaList == null) {
|
||||
return;
|
||||
}
|
||||
String dataStr = mediaList.getString("data");
|
||||
|
||||
Integer code = mediaList.getInteger("code");
|
||||
@@ -176,7 +178,9 @@ public class ZLMMediaListManager {
|
||||
//使用异步更新推流
|
||||
zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId, "rtmp", json->{
|
||||
|
||||
if (json == null) return;
|
||||
if (json == null) {
|
||||
return;
|
||||
}
|
||||
String dataStr = json.getString("data");
|
||||
|
||||
Integer code = json.getInteger("code");
|
||||
|
||||
@@ -23,7 +23,9 @@ public class ZLMRTPServerFactory {
|
||||
private int[] portRangeArray = new int[2];
|
||||
|
||||
public int getFreePort(MediaServerItem mediaServerItem, int startPort, int endPort, List<Integer> usedFreelist) {
|
||||
if (endPort <= startPort) return -1;
|
||||
if (endPort <= startPort) {
|
||||
return -1;
|
||||
}
|
||||
if (usedFreelist == null) {
|
||||
usedFreelist = new ArrayList<>();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.media.zlm;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
@@ -51,6 +52,9 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
@Autowired
|
||||
private MediaConfig mediaConfig;
|
||||
|
||||
@Autowired
|
||||
private DynamicTask dynamicTask;
|
||||
|
||||
@Qualifier("taskExecutor")
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor taskExecutor;
|
||||
@@ -97,27 +101,25 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
all.add(mediaConfig.getMediaSerItem());
|
||||
}
|
||||
for (MediaServerItem mediaServerItem : all) {
|
||||
if (startGetMedia == null) startGetMedia = new HashMap<>();
|
||||
if (startGetMedia == null) {
|
||||
startGetMedia = new HashMap<>();
|
||||
}
|
||||
startGetMedia.put(mediaServerItem.getId(), true);
|
||||
taskExecutor.execute(()->{
|
||||
connectZlmServer(mediaServerItem);
|
||||
});
|
||||
}
|
||||
Timer timer = new Timer();
|
||||
// 10分钟后未连接到则不再去主动连接, TODO 并对重启前使用此在zlm的通道发送bye
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
String taskKey = "zlm-connect-timeout";
|
||||
dynamicTask.startDelay(taskKey, ()->{
|
||||
if (startGetMedia != null) {
|
||||
Set<String> allZlmId = startGetMedia.keySet();
|
||||
for (String id : allZlmId) {
|
||||
logger.error("[ {} ]]主动连接失败,不再主动连接", id);
|
||||
logger.error("[ {} ]]主动连接失败,不再尝试连接", id);
|
||||
}
|
||||
startGetMedia = null;
|
||||
}
|
||||
// TODO 清理数据库中与redis不匹配的zlm
|
||||
}
|
||||
}, 60 * 1000 * 10);
|
||||
// TODO 清理数据库中与redis不匹配的zlm
|
||||
}, 6 * 1000 );
|
||||
}
|
||||
|
||||
@Async
|
||||
@@ -139,12 +141,12 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
if ( startGetMedia.get(mediaServerItem.getId()) == null || !startGetMedia.get(mediaServerItem.getId())) {
|
||||
return null;
|
||||
}
|
||||
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMServerConfig ZLMServerConfig = null;
|
||||
if (responseJSON != null) {
|
||||
JSONArray data = responseJSON.getJSONArray("data");
|
||||
JSONObject responseJson = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMServerConfig zlmServerConfig = null;
|
||||
if (responseJson != null) {
|
||||
JSONArray data = responseJson.getJSONArray("data");
|
||||
if (data != null && data.size() > 0) {
|
||||
ZLMServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
}
|
||||
} else {
|
||||
logger.error("[ {} ]-[ {}:{} ]第{}次主动连接失败, 2s后重试",
|
||||
@@ -159,9 +161,9 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ZLMServerConfig = getMediaServerConfig(mediaServerItem, index += 1);
|
||||
zlmServerConfig = getMediaServerConfig(mediaServerItem, index += 1);
|
||||
}
|
||||
return ZLMServerConfig;
|
||||
return zlmServerConfig;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,18 +29,22 @@ public class StreamProxyItem extends GbStream {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApp(String app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStream(String stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
@@ -124,18 +124,22 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApp(String app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStream(String stream) {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user