Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit aa41a5d9
由
LN
编写于
2024-08-12 20:25:26 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1.增加重连处理
1 个父辈
dcc32d1c
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
76 行增加
和
37 行删除
src/main/java/com/neotel/smfcore/custom/hanwha/client/MyWebSocketClient.java
src/main/java/com/neotel/smfcore/custom/hanwha/handler/TMSCommunicator.java
src/main/java/com/neotel/smfcore/custom/hanwha/client/MyWebSocketClient.java
查看文件 @
aa41a5d
...
@@ -62,42 +62,42 @@ public class MyWebSocketClient extends WebSocketClient {
...
@@ -62,42 +62,42 @@ public class MyWebSocketClient extends WebSocketClient {
private
static
final
long
RECONNECT_DELAY
=
5000
;
// 重连延迟时间,单位:毫秒
private
static
final
long
RECONNECT_DELAY
=
5000
;
// 重连延迟时间,单位:毫秒
private
Timer
reconnectTimer
;
// 重连定时器
private
Timer
reconnectTimer
;
// 重连定时器
private
void
startReconnect
()
{
private
void
startReconnect
()
{
try
{
//
try {
if
(
reconnectTimer
==
null
)
{
//
if (reconnectTimer == null) {
reconnectTimer
=
new
Timer
();
//
reconnectTimer = new Timer();
reconnectTimer
.
schedule
(
new
TimerTask
()
{
//
reconnectTimer.schedule(new TimerTask() {
@Override
//
@Override
public
void
run
()
{
//
public void run() {
try
{
//
try {
log
.
info
(
"startReconnect "
);
//
log.info("startReconnect ");
// 创建新的WebSocket连接
//
// 创建新的WebSocket连接
reconnect
();
//
reconnect();
}
catch
(
Exception
e
)
{
//
} catch (Exception e) {
log
.
error
(
"出错:"
+
e
.
toString
());
//
log.error("出错:" + e.toString());
}
//
}
}
//
}
},
RECONNECT_DELAY
);
//
}, RECONNECT_DELAY);
}
//
}
}
catch
(
Exception
exception
)
{
//
} catch (Exception exception) {
log
.
error
(
"startReconnect error :"
+
exception
.
toString
());
//
log.error("startReconnect error :" + exception.toString());
}
//
}
}
}
private
void
cancelReconnect
()
{
private
void
cancelReconnect
()
{
try
{
//
try{
if
(
reconnectTimer
!=
null
)
{
//
if (reconnectTimer != null) {
log
.
info
(
"cancelReconnect "
);
//
log.info("cancelReconnect ");
reconnectTimer
.
cancel
();
//
reconnectTimer.cancel();
reconnectTimer
=
null
;
//
reconnectTimer = null;
}
//
}
}
catch
(
Exception
exception
){
//
}catch (Exception exception){
log
.
error
(
"cancelReconnect error :"
+
exception
.
toString
());
//
log.error("cancelReconnect error :"+exception.toString());
}
//
}
}
}
// private void reconnect() throws URISyntaxException {
// private void reconnect() throws URISyntaxException {
// URI serverUri = super.getURI();
// URI serverUri = super.getURI();
//
MyWebSocketClient newClient = new MyWebSocketClient(serverUri
);
//
this= new MyWebSocketClient(serverUri,msgReceivedListener
);
//
newClient.
connect();
// connect();
// }
// }
}
}
src/main/java/com/neotel/smfcore/custom/hanwha/handler/TMSCommunicator.java
查看文件 @
aa41a5d
...
@@ -7,6 +7,9 @@ import java.text.SimpleDateFormat;
...
@@ -7,6 +7,9 @@ import java.text.SimpleDateFormat;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.TimeUnit
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.convert.Convert
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
...
@@ -95,6 +98,7 @@ public class TMSCommunicator implements WsMsgReceivedListener {
...
@@ -95,6 +98,7 @@ public class TMSCommunicator implements WsMsgReceivedListener {
{
{
return
gRequestID
++;
return
gRequestID
++;
}
}
private
boolean
needCheck
=
false
;
@PostConstruct
@PostConstruct
public
void
init
()
{
public
void
init
()
{
host
=
dataCache
.
getConfigCache
(
"hanwha.host"
,
host
);
host
=
dataCache
.
getConfigCache
(
"hanwha.host"
,
host
);
...
@@ -114,17 +118,46 @@ public class TMSCommunicator implements WsMsgReceivedListener {
...
@@ -114,17 +118,46 @@ public class TMSCommunicator implements WsMsgReceivedListener {
try
{
try
{
Thread
.
sleep
(
20000
);
Thread
.
sleep
(
20000
);
start
();
start
();
Thread
.
sleep
(
5000
);
needCheck
=
true
;
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
log
.
error
(
"
自动关闭库位灯
出错:"
+
e
.
getMessage
());
log
.
error
(
"
开始连接webService
出错:"
+
e
.
getMessage
());
}
}
}
}
});
}
);
closeTask
.
start
();
closeTask
.
start
();
ExecutorService
executorService
=
Executors
.
newSingleThreadExecutor
();
executorService
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
log
.
info
(
"启动 webService 状态检查"
);
while
(
true
)
{
try
{
TimeUnit
.
SECONDS
.
sleep
(
5
);
if
(
needCheck
)
{
stateCheck
();
}
}
catch
(
Exception
e
)
{
log
.
error
(
"webService"
+
e
.
getMessage
());
}
}
}
});
// start();
// start();
}
}
}
}
}
}
private
void
stateCheck
(){
if
(
websocket
.
isOpen
()||
websocket
.
isConnecting
()){
}
else
{
// log.info("开始重连");
start
()
;
}
}
private
void
updateServerInfo
(
String
serverHost
,
int
wport
,
int
aport
)
{
private
void
updateServerInfo
(
String
serverHost
,
int
wport
,
int
aport
)
{
host
=
serverHost
;
host
=
serverHost
;
webPort
=
wport
;
webPort
=
wport
;
...
@@ -238,20 +271,26 @@ public class TMSCommunicator implements WsMsgReceivedListener {
...
@@ -238,20 +271,26 @@ public class TMSCommunicator implements WsMsgReceivedListener {
@Autowired
@Autowired
private
TMSApis
tmsApis
;
private
TMSApis
tmsApis
;
private
void
SyncData
(){
private
void
SyncData
()
{
Thread
thread
=
new
Thread
(
new
Runnable
()
{
Thread
thread
=
new
Thread
(
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
try
{
// 同步数据
// 同步数据
List
<
String
>
cids
=
new
ArrayList
<>(
dataCache
.
getAllStorage
().
keySet
());
List
<
String
>
cids
=
new
ArrayList
<>(
dataCache
.
getAllStorage
().
keySet
());
SyncStorageConnectionInfo
(
cids
.
toArray
(
new
String
[
cids
.
size
()]),
new
Integer
[]{});
SyncStorageConnectionInfo
(
cids
.
toArray
(
new
String
[
cids
.
size
()]),
new
Integer
[]{});
List
<
Map
<
String
,
StoragePos
>>
allUsedPoss
=
dataCache
.
getAllUsedPosMap
();
List
<
Map
<
String
,
StoragePos
>>
allUsedPoss
=
dataCache
.
getAllUsedPosMap
();
SyncReelData
(
allUsedPoss
);
SyncReelData
(
allUsedPoss
);
SyncDeliveryReserveState
(
);
SyncDeliveryReserveState
(
);
// List<TMSPart> result= tmsApis.RequestGetPartInfo(0,"20180126153040-001");
// List<TMSPart> result= tmsApis.RequestGetPartInfo(0,"20180126153040-001");
// onMsgReceived("{\"PartNames\":[\"Z2203021401A\",\"20180711092420-002\",\"20180710181845-001\"],\"Counts\":[5000,1,1],\"TowerLamp\":false,\"Topic\":\"RequestDeliveryOrder\",\"id\":2,\"uid\":439570}");
// onMsgReceived("{\"PartNames\":[\"Z2203021401A\",\"20180711092420-002\",\"20180710181845-001\"],\"Counts\":[5000,1,1],\"TowerLamp\":false,\"Topic\":\"RequestDeliveryOrder\",\"id\":2,\"uid\":439570}");
// onMsgReceived("{\"PartNames\":[\"Z2203021401A\",\"20180711092420-002\",\"20180710181845-001\"],\"Counts\":[5000,1,1],\"TowerLamp\":false,\"Topic\":\"RequestDeliveryOrder\",\"id\":1,\"uid\":472393}");
// onMsgReceived("{\"PartNames\":[\"Z2203021401A\",\"20180711092420-002\",\"20180710181845-001\"],\"Counts\":[5000,1,1],\"TowerLamp\":false,\"Topic\":\"RequestDeliveryOrder\",\"id\":1,\"uid\":472393}");
}
catch
(
Exception
exception
)
{
log
.
error
(
exception
.
toString
());
}
}
}
});
});
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论