[opt]解决Bus乘客屏偶现卡顿的问题
This commit is contained in:
@@ -36,24 +36,24 @@ PASSWORD=xintai2018
|
||||
RELEASE=true
|
||||
# AI CLOUD 云平台
|
||||
# 工具类
|
||||
MOGO_UTILS_VERSION=1.4.5.10
|
||||
MOGO_UTILS_VERSION=1.4.5.12
|
||||
# 网络请求
|
||||
MOGO_NETWORK_VERSION=1.4.5.10
|
||||
MOGO_NETWORK_VERSION=1.4.5.12
|
||||
# 鉴权
|
||||
MOGO_PASSPORT_VERSION=1.4.5.10
|
||||
MOGO_PASSPORT_VERSION=1.4.5.12
|
||||
# 常链接
|
||||
MOGO_SOCKET_VERSION=1.4.5.10
|
||||
MOGO_SOCKET_VERSION=1.4.5.12
|
||||
# 数据采集
|
||||
MOGO_REALTIME_VERSION=1.4.5.10
|
||||
MOGO_REALTIME_VERSION=1.4.5.12
|
||||
# 探路,道路事件发布,获取
|
||||
MOGO_TANLU_VERSION=1.4.5.10
|
||||
MOGO_TANLU_VERSION=1.4.5.12
|
||||
# 直播推流
|
||||
MOGO_LIVE_VERSION=1.4.5.10
|
||||
MOGO_LIVE_VERSION=1.4.5.12
|
||||
# 直播拉流
|
||||
MOGO_TRAFFICLIVE_VERSION=1.4.5.10
|
||||
MOGO_TRAFFICLIVE_VERSION=1.4.5.12
|
||||
# 定位服务
|
||||
MOGO_LOCATION_VERSION=1.4.5.10
|
||||
MOGO_LOCATION_VERSION=1.4.5.12
|
||||
# 远程通讯模块
|
||||
MOGO_TELEMATIC_VERSION=1.4.5.10
|
||||
MOGO_TELEMATIC_VERSION=1.4.5.12
|
||||
# v2x
|
||||
MOGO_V2X_VERSION=1.4.5.10
|
||||
MOGO_V2X_VERSION=1.4.5.12
|
||||
|
||||
@@ -5,8 +5,8 @@ import static com.mogo.telematic.client.status.ConnectState.STATUS_CONNECT_CLOSE
|
||||
import android.content.Context;
|
||||
import android.net.nsd.NsdServiceInfo;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import com.elegant.log.simplelog.Logger;
|
||||
import com.mogo.telematic.client.NettyTcpClient;
|
||||
import com.mogo.telematic.client.NsdClient;
|
||||
import com.mogo.telematic.client.listener.MessageStateListener;
|
||||
@@ -42,8 +42,6 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
private Context mContext;
|
||||
private NettyServerListener mListener;
|
||||
|
||||
// 采用轮询的方式查询可连接设备
|
||||
private AbstractDiscoveryTask mDiscoveryTask;
|
||||
private long network_ip = 0;
|
||||
private long network_start = 0;
|
||||
private long network_end = 0;
|
||||
@@ -140,7 +138,7 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
nettyTcpServer.setListener(mDefaultServerListener);
|
||||
nettyTcpServer.start();
|
||||
} else {
|
||||
Log.i(TAG, "服务端已开启,不要重复启动!");
|
||||
Logger.i(TAG, "服务端已开启,不要重复启动!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +177,7 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
mNsdServer.setRegisterState(new NSDServer.IRegisterState() {
|
||||
@Override
|
||||
public void onServiceRegistered(NsdServiceInfo serviceInfo) {
|
||||
Log.i(TAG, "已注册服务onServiceRegistered: " + serviceInfo.toString());
|
||||
Logger.i(TAG, "已注册服务onServiceRegistered: " + serviceInfo.toString());
|
||||
//已经注册可停止该服务
|
||||
// nsdServer.stopNSDServer();
|
||||
}
|
||||
@@ -234,7 +232,7 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
public void onServerFound(NsdServiceInfo info, int port) {
|
||||
if (info != null) {
|
||||
String hostAddress = info.getHost().getHostAddress();
|
||||
Log.d(TAG, "NSD查询到指定服务器信息ip为:" + hostAddress + ",port为:" + port);
|
||||
Logger.d(TAG, "NSD查询到指定服务器信息ip为:" + hostAddress + ",port为:" + port);
|
||||
//获取到指定的地址,进行Netty的连接
|
||||
if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
|
||||
new Thread(() -> {
|
||||
@@ -248,7 +246,7 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
|
||||
@Override
|
||||
public void onServerFail() {
|
||||
Log.d(TAG, "NSD查询失败,未找到");
|
||||
Logger.d(TAG, "NSD查询失败,未找到");
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -274,7 +272,7 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
|
||||
private void scanDriverServer(String uuid, NettyClientListener listener) {
|
||||
// 启动发现司机屏幕任务
|
||||
mDiscoveryTask = new DiscoveryDriverTask();
|
||||
AbstractDiscoveryTask discoveryTask = new DiscoveryDriverTask();
|
||||
network_ip = NetInfo.getUnsignedLongFromIp(currentIp);
|
||||
mClientListener = listener;
|
||||
|
||||
@@ -289,25 +287,21 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
network_end = (network_start | ((1 << shift) - 1));
|
||||
}
|
||||
|
||||
mDiscoveryTask.setNetwork(network_ip, network_start, network_end);
|
||||
mDiscoveryTask.addDiscoveryDriverListener(new DiscoveryDriverListener() {
|
||||
discoveryTask.setNetwork(network_ip, network_start, network_end);
|
||||
discoveryTask.addDiscoveryDriverListener(new DiscoveryDriverListener() {
|
||||
@Override
|
||||
public void onSuccess(ArrayList<HostBean> hostList) {
|
||||
// 这里返回数据代表了有司机端正在运行,这里遍历集合数据进行连接
|
||||
if (hostList != null && hostList.size() > 0) {
|
||||
String hostAddress = "";
|
||||
for (HostBean hostBean : hostList) {
|
||||
if (mNettyTcpClient != null && (mNettyTcpClient.isConnecting() || mNettyTcpClient.getConnectStatus())) {
|
||||
Log.d(TAG, "当前乘客屏幕已经连接到了ip:" + hostAddress + ",port为:" + 1088);
|
||||
return;
|
||||
}
|
||||
hostAddress = hostBean.ipAddress;
|
||||
Log.d(TAG, "NSD查询到指定服务器信息ip为:" + hostAddress + ",port为:" + 1088);
|
||||
//获取到指定的地址,进行Netty的连接
|
||||
connectNettyServer(hostAddress, 1088, uuid);
|
||||
if (Thread.currentThread() == Looper.getMainLooper().getThread()) {
|
||||
ThreadPoolManager.getSingleThreadExecutor().execute(() -> {
|
||||
realConnectServer(hostList, uuid);
|
||||
});
|
||||
} else {
|
||||
realConnectServer(hostList, uuid);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "扫描完成,未找到可连接司机屏幕服务");
|
||||
Logger.d(TAG, "扫描完成,未找到可连接司机屏幕服务");
|
||||
// 这里做1、8网段的切换扫描
|
||||
if (currentIp.equals(currentIp1)) {
|
||||
currentIp = currentIp8;
|
||||
@@ -323,13 +317,27 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
|
||||
}
|
||||
});
|
||||
mDiscoveryTask.execute();
|
||||
discoveryTask.execute();
|
||||
}
|
||||
|
||||
private void realConnectServer(ArrayList<HostBean> hostList, String uuid) {
|
||||
String hostAddress = "";
|
||||
for (HostBean hostBean : hostList) {
|
||||
if (mNettyTcpClient != null && (mNettyTcpClient.isConnecting() || mNettyTcpClient.getConnectStatus())) {
|
||||
Logger.d(TAG, "当前乘客屏幕已经连接到了ip:" + hostAddress + ",port为:" + 1088);
|
||||
return;
|
||||
}
|
||||
hostAddress = hostBean.ipAddress;
|
||||
Logger.d(TAG, "NSD查询到指定服务器信息ip为:" + hostAddress + ",port为:" + 1088);
|
||||
//获取到指定的地址,进行Netty的连接
|
||||
connectNettyServer(hostAddress, 1088, uuid);
|
||||
}
|
||||
}
|
||||
|
||||
private void connectNettyServer(String serverAddress, int port, String sign) {
|
||||
Log.d(TAG, "connectNettyServer");
|
||||
Logger.d(TAG, "connectNettyServer");
|
||||
if (serverAddress == null || serverAddress.length() == 0) {
|
||||
Log.e(TAG, "Netty Server的ip不能为空!");
|
||||
Logger.e(TAG, "Netty Server的ip不能为空!");
|
||||
return;
|
||||
}
|
||||
if (!isCanceled) {
|
||||
@@ -379,7 +387,7 @@ public class NSDNettyManager implements TelematicHandler.ITelematicListener {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "Client is connected.");
|
||||
Logger.d(TAG, "Client is connected.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.mogo.telematic
|
||||
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
object ThreadPoolManager {
|
||||
|
||||
@JvmStatic
|
||||
val singleThreadExecutor: ExecutorService by lazy {
|
||||
Executors.newSingleThreadExecutor()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user