Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
TDLCloud
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
WitCloud
TDLCloud
Commits
d796e99a
Commit
d796e99a
authored
Apr 29, 2018
by
wangjunqiangs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加简单的超时清理,防止config线程过多,卡死emq(未测试)
parent
6e15f3cc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
MqttListener.java
src/main/java/com/example/tdl/mqtt/MqttListener.java
+22
-2
No files found.
src/main/java/com/example/tdl/mqtt/MqttListener.java
View file @
d796e99a
...
...
@@ -50,7 +50,7 @@ public class MqttListener implements MqttCallback {
@Autowired
private
ConfigService
configService
;
Map
<
String
,
Future
<
String
>>
futureMap
=
new
HashMap
<
String
,
Future
<
String
>>();
Map
<
String
,
Future
<
String
>>
futureMap
=
new
HashMap
<
String
,
Future
<
String
>>();
private
ScheduledExecutorService
mReconnectScheduler
;
private
long
mInitDelay
=
INIT_DELAY_DEFAULT
;
...
...
@@ -121,6 +121,23 @@ public class MqttListener implements MqttCallback {
// clientReconnect();
}
private
void
clearOvertimeConfig
(
Long
ts
){
try
{
for
(
String
key
:
futureMap
.
keySet
()){
String
[]
tmparray
=
key
.
split
(
"_"
);
Long
tskey
=
Long
.
valueOf
(
tmparray
[
2
]);
if
(
ts
-
tskey
>
60
*
1000
){
Future
<
String
>
result
=
futureMap
.
get
(
key
);
result
.
cancel
(
true
);
if
(
result
.
isCancelled
())
futureMap
.
remove
(
key
);
}
}
}
catch
(
Exception
e
){
System
.
out
.
println
(
e
.
getMessage
());
}
}
@Override
public
void
messageArrived
(
String
topic
,
MqttMessage
mqttMessage
)
throws
Exception
{
String
Message
=
mqttMessage
.
toString
();
...
...
@@ -128,6 +145,7 @@ public class MqttListener implements MqttCallback {
String
[]
tmparray
=
topic
.
split
(
"/"
);
String
Type
=
tmparray
[
1
];
String
SN
=
tmparray
[
2
];
clearOvertimeConfig
(
timestamp
);
if
(
SN
.
matches
(
"^[0-9]*$"
)){
try
{
Integer
flag
=
parseData
(
Message
,
SN
,
Type
);
...
...
@@ -155,11 +173,13 @@ public class MqttListener implements MqttCallback {
mqttconfig
.
getUsername
(),
mqttconfig
.
getPassword
(),
mqttconfig
.
getQos
(),
mqttconfig
.
getCacrt
(),
mqttconfig
.
getClientkey
(),
mqttconfig
.
getClientcrt
(),
mqttconfig
.
getClientpwd
());
result
=
configthreadPool
.
submit
(
gcconfig
);
futureMap
.
put
(
Type
+
"_"
+
SN
+
"_"
+
timestamp
,
result
);
// while (result.isDone())
// {
// String respcmd = result.get();
// }
//
futureMap.put(timestamp.toString(),result);
//
}
catch
(
JsonSyntaxException
e
)
{
e
.
printStackTrace
();
System
.
out
.
println
(
"mqttAsyncClient: message "
+
Message
+
" received syntax error."
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment