Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
traffic-signal-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
signal
traffic-signal-platform
Commits
0998ed96
Commit
0998ed96
authored
May 25, 2023
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 优化测试轨迹
parent
8650e8f3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
103 additions
and
32 deletions
+103
-32
ThreadPoolConfig.java
.../src/main/java/net/wanji/web/config/ThreadPoolConfig.java
+47
-0
RealTimeCarTask.java
...ice/src/main/java/net/wanji/web/task/RealTimeCarTask.java
+47
-32
WebSocketServer.java
...rc/main/java/net/wanji/web/websocket/WebSocketServer.java
+1
-0
application.yml
signal-control-service/src/main/resources/application.yml
+8
-0
No files found.
signal-control-service/src/main/java/net/wanji/web/config/ThreadPoolConfig.java
0 → 100644
View file @
0998ed96
package
net
.
wanji
.
web
.
config
;
import
com.google.common.util.concurrent.ThreadFactoryBuilder
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
java.util.concurrent.ThreadFactory
;
import
java.util.concurrent.ThreadPoolExecutor
;
/**
* @author duanruiming
* @date 2023/02/14 10:17
*/
@Configuration
public
class
ThreadPoolConfig
{
@Value
(
"${threadPoolConfig.threadPoolName}"
)
private
String
threadPoolName
;
@Value
(
"${threadPoolConfig.coreSize}"
)
private
int
coreSize
;
@Value
(
"${threadPoolConfig.maxSize}"
)
private
int
maxSize
;
@Value
(
"${threadPoolConfig.queueCapacity}"
)
private
int
queueCapacity
;
@Value
(
"${threadPoolConfig.keepAliveTime}"
)
private
int
keepAliveTime
;
@Value
(
"${threadPoolConfig.allowCoreTimeOut}"
)
private
boolean
allowCoreTimeOut
;
@Bean
(
"threadPoolExecutor"
)
public
ThreadPoolTaskExecutor
threadPoolExecutor
()
{
ThreadPoolTaskExecutor
executor
=
new
ThreadPoolTaskExecutor
();
ThreadFactory
build
=
new
ThreadFactoryBuilder
().
setNameFormat
(
threadPoolName
).
build
();
executor
.
setThreadFactory
(
build
);
executor
.
setCorePoolSize
(
coreSize
);
executor
.
setMaxPoolSize
(
maxSize
);
executor
.
setQueueCapacity
(
queueCapacity
);
executor
.
setKeepAliveSeconds
(
keepAliveTime
);
executor
.
setAllowCoreThreadTimeOut
(
allowCoreTimeOut
);
executor
.
setRejectedExecutionHandler
(
new
ThreadPoolExecutor
.
DiscardOldestPolicy
());
executor
.
initialize
();
return
executor
;
}
}
signal-control-service/src/main/java/net/wanji/web/task/RealTimeCarTask.java
View file @
0998ed96
...
@@ -10,12 +10,19 @@ import net.wanji.web.kafka.ConsumerHandler;
...
@@ -10,12 +10,19 @@ import net.wanji.web.kafka.ConsumerHandler;
import
net.wanji.web.kafka.JNMatchResultMiniData
;
import
net.wanji.web.kafka.JNMatchResultMiniData
;
import
net.wanji.web.websocket.WebSocketServer
;
import
net.wanji.web.websocket.WebSocketServer
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
/**
...
@@ -28,12 +35,14 @@ public class RealTimeCarTask {
...
@@ -28,12 +35,14 @@ public class RealTimeCarTask {
@Resource
@Resource
private
ConsumerHandler
consumerHandler
;
private
ConsumerHandler
consumerHandler
;
@Autowired
@Qualifier
(
value
=
"threadPoolExecutor"
)
private
ThreadPoolTaskExecutor
threadPoolExecutor
;
private
static
final
List
<
TempPojo
>
tempList
=
new
ArrayList
<>(
7
);
private
static
final
List
<
TempPojo
>
tempList
=
new
ArrayList
<>(
7
);
private
static
final
AtomicInteger
atomicInteger
=
new
AtomicInteger
(
0
);
private
final
AtomicInteger
atomicInteger
=
new
AtomicInteger
(
0
);
static
{
static
{
tempList
.
add
(
new
TempPojo
(
112.967134
,
28.182384
));
tempList
.
add
(
new
TempPojo
(
112.967134
,
28.182384
));
tempList
.
add
(
new
TempPojo
(
112.966402
,
28.182420
));
tempList
.
add
(
new
TempPojo
(
112.966402
,
28.182420
));
tempList
.
add
(
new
TempPojo
(
112.964600
,
28.182618
));
tempList
.
add
(
new
TempPojo
(
112.964600
,
28.182618
));
...
@@ -41,46 +50,52 @@ public class RealTimeCarTask {
...
@@ -41,46 +50,52 @@ public class RealTimeCarTask {
tempList
.
add
(
new
TempPojo
(
112.963092
,
28.184083
));
tempList
.
add
(
new
TempPojo
(
112.963092
,
28.184083
));
tempList
.
add
(
new
TempPojo
(
112.963606
,
28.188246
));
tempList
.
add
(
new
TempPojo
(
112.963606
,
28.188246
));
tempList
.
add
(
new
TempPojo
(
112.963711
,
28.189290
));
tempList
.
add
(
new
TempPojo
(
112.963711
,
28.189290
));
tempList
.
add
(
new
TempPojo
(
112.967486
,
28.187118
));
}
}
@Scheduled
(
fixedRate
=
2000
)
@Scheduled
(
fixedRate
=
2000
)
public
void
pushRealTimeCarInfo
()
{
public
void
pushRealTimeCarInfo
()
{
try
{
// threadPoolExecutor.execute(() -> {
Set
<
WebSocketServer
>
events
=
WebSocketServer
.
getWebSocketSet
(
Constant
.
WEBSOCKET_TOPIC_CAR_TRAIL_INFO
);
int
i
=
atomicInteger
.
get
();
if
(
CollectionUtil
.
isEmpty
(
events
))
{
atomicInteger
.
incrementAndGet
();
return
;
if
(
i
==
7
)
{
atomicInteger
.
set
(
0
);
}
Set
<
WebSocketServer
>
events
=
WebSocketServer
.
getWebSocketSet
(
Constant
.
WEBSOCKET_TOPIC_CAR_TRAIL_INFO
);
if
(
CollectionUtil
.
isEmpty
(
events
))
{
return
;
}
for
(
WebSocketServer
socketServer
:
events
)
{
String
userId
=
socketServer
.
getUserId
();
String
picLicense
=
null
;
if
(
StringUtils
.
isNotBlank
(
userId
))
{
picLicense
=
userId
.
substring
(
0
,
7
);
}
}
for
(
WebSocketServer
socketServer
:
events
)
{
JNMatchResultMiniData
jnMatchResultMiniData
=
consumerHandler
.
getTopicMessage
(
"CSMatchResultMiniData_0"
);
String
picLicense
=
socketServer
.
getUserId
();
if
(
Objects
.
nonNull
(
jnMatchResultMiniData
))
{
JNMatchResultMiniData
jnMatchResultMiniData
=
consumerHandler
.
getTopicMessage
(
"CSMatchResultMiniData_0"
);
List
<
JNMatchResultMiniData
.
E1FrameParticipant
>
list
=
jnMatchResultMiniData
.
getE1FrameParticipant
();
if
(
Objects
.
nonNull
(
jnMatchResultMiniData
))
{
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
List
<
JNMatchResultMiniData
.
E1FrameParticipant
>
list
=
jnMatchResultMiniData
.
getE1FrameParticipant
();
for
(
JNMatchResultMiniData
.
E1FrameParticipant
e1FrameParticipant
:
list
)
{
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
int
id
=
e1FrameParticipant
.
getId
();
for
(
JNMatchResultMiniData
.
E1FrameParticipant
e1FrameParticipant
:
list
)
{
String
license
=
e1FrameParticipant
.
getPicLicense
();
int
id
=
e1FrameParticipant
.
getId
();
// 测试车牌;京WJ0001
String
license
=
e1FrameParticipant
.
getPicLicense
();
license
=
"京WJ0001"
;
if
(
3573
==
e1FrameParticipant
.
getId
()
||
StringUtils
.
equals
(
license
,
picLicense
))
{
if
(
3573
==
e1FrameParticipant
.
getId
()
&&
StringUtils
.
equals
(
license
,
picLicense
))
{
for
(
int
i
=
0
;
i
<
tempList
.
size
();
i
++)
{
TempPojo
tempPojo
=
RealTimeCarTask
.
tempList
.
get
(
i
);
if
(
i
==
atomicInteger
.
get
())
{
e1FrameParticipant
.
setLongitude
(
tempPojo
.
getLongitude
());
atomicInteger
.
getAndIncrement
();
e1FrameParticipant
.
setLatitude
(
tempPojo
.
getLatitude
());
if
(
i
==
6
)
{
e1FrameParticipant
.
setPicLicense
(
license
);
atomicInteger
.
set
(
0
);
try
{
}
TempPojo
tempPojo
=
tempList
.
get
(
i
);
e1FrameParticipant
.
setLongitude
(
tempPojo
.
getLongitude
());
e1FrameParticipant
.
setLatitude
(
tempPojo
.
getLatitude
());
break
;
}
}
socketServer
.
sendMessage
(
JSONObject
.
toJSONString
(
e1FrameParticipant
));
socketServer
.
sendMessage
(
JSONObject
.
toJSONString
(
e1FrameParticipant
));
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
}
}
}
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"通过车牌推送数据失败,异常信息"
,
e
);
}
}
// });
}
}
@Data
@Data
...
...
signal-control-service/src/main/java/net/wanji/web/websocket/WebSocketServer.java
View file @
0998ed96
...
@@ -58,6 +58,7 @@ public class WebSocketServer {
...
@@ -58,6 +58,7 @@ public class WebSocketServer {
Set
<
WebSocketServer
>
set
=
webSocketMap
.
get
(
topic
);
Set
<
WebSocketServer
>
set
=
webSocketMap
.
get
(
topic
);
set
.
add
(
this
);
set
.
add
(
this
);
webSocketMap
.
put
(
topic
,
set
);
webSocketMap
.
put
(
topic
,
set
);
addOnlineCount
();
currentTopicSize
=
set
.
size
();
currentTopicSize
=
set
.
size
();
//加入set中
//加入set中
}
else
{
}
else
{
...
...
signal-control-service/src/main/resources/application.yml
View file @
0998ed96
...
@@ -58,3 +58,11 @@ mybatis-plus:
...
@@ -58,3 +58,11 @@ mybatis-plus:
auto-mapping-unknown-column-behavior
:
warning
auto-mapping-unknown-column-behavior
:
warning
#开启SQL打印
#开启SQL打印
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
log-impl
:
org.apache.ibatis.logging.stdout.StdOutImpl
#线程池配置
threadPoolConfig
:
threadPoolName
:
threadPoolExecutor
coreSize
:
8
maxSize
:
16
queueCapacity
:
200
keepAliveTime
:
6000
allowCoreTimeOut
:
false
\ No newline at end of file
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