Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
p x
wsmock
Commits
6314a96d
Commit
6314a96d
authored
Jan 12, 2026
by
p x
Browse files
和APK:联调一次
parent
eb5a2d1c
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
logs/wsmock.log
View file @
6314a96d
This diff is collapsed.
Click to expand it.
src/main/kotlin/com/inzy/wsmock/ScheduledAdasPushTask.kt
View file @
6314a96d
...
...
@@ -52,7 +52,7 @@ class ScheduledAdasPushTask(
// @Scheduled(fixedDelayString = "#{@pushConfig.pushInterval}")
// @Scheduled(fixedDelayString = "#{@pushConfig.pushInterval}")
fun
pushMsgToType1
()
{
val
onlineChannels
=
channelManager
.
getAllChannels
()
/*
val onlineChannels = channelManager.getAllChannels()
//得到设置了type属性的channel
val typeChannels = filterTypeChannels(PARAM_TYPE_VALUE_1)
// println("onlineChannels.size = ${onlineChannels.size} typeChannels.size = ${typeChannels.size}")
...
...
@@ -63,25 +63,25 @@ class ScheduledAdasPushTask(
channelManager.sendMsgFromType(typeChannels, carDst.get(carDstIndex))
carDstIndex = (carDstIndex + 1) % carDst.size // 循环索引
}
}
*/
}
// @Scheduled(fixedDelayString = "200")
fun
pushMsgToType2
()
{
/*
fun pushMsgToType2() {
//得到设置了type属性的channel
val typeChannels = filterTypeChannels(PARAM_TYPE_VALUE_2)
// println("onlineChannels.size = ${onlineChannels.size} typeChannels.size = ${typeChannels.size}")
val msgObj = JSONObject()
msgObj["content"] = "定时推送消息 type=2 ${LocalDateTime.now()}"
channelManager.sendMsgFromType(typeChannels, msgObj.toJSONString())
}
}
*/
/**
* @param type 前端的查询参数
* **/
private
fun
filterTypeChannels
(
type
:
String
):
Map
<
String
,
Channel
>
{
/*
private fun filterTypeChannels(type: String): Map<String, Channel> {
val onlineChannels = channelManager.getAllChannels()
//得到设置了type属性的channel
val typeChannels =
...
...
@@ -93,7 +93,7 @@ class ScheduledAdasPushTask(
false
}
return typeChannels
}
}
*/
/**
...
...
src/main/kotlin/com/inzy/wsmock/push/AdasPushTask.kt
View file @
6314a96d
...
...
@@ -5,6 +5,9 @@ import com.alibaba.fastjson2.JSONObject
import
com.inzy.wsmock.ChannelManager
import
com.inzy.wsmock.PushConfig
import
com.inzy.wsmock.RequestParamHandler
import
com.inzy.wsmock.RequestParamHandler.Companion.PARAM_TYPE_KEY
import
com.inzy.wsmock.RequestParamHandler.Companion.PARAM_TYPE_VALUE_3
import
com.inzy.wsmock.RequestParamHandler.Companion.REQUEST_PARAMS_KEY
import
com.inzy.wsmock.bean.DriveInOrOut
import
com.inzy.wsmock.utils.FileIoUtil
import
io.netty.channel.Channel
...
...
@@ -19,14 +22,16 @@ import java.util.concurrent.atomic.AtomicBoolean
import
java.util.concurrent.atomic.AtomicInteger
@Component
//@Scope("prototype")
class
AdasPushTask
(
// 注入Spring资源加载器(Spring自动装配)
private
val
resourceLoader
:
ResourceLoader
,
private
val
pushConfig
:
PushConfig
,
)
:
PushTask
{
private
val
instanceId
=
System
.
currentTimeMillis
()
// 实例唯一标识,用于验证多实例
private
val
logger
=
LoggerFactory
.
getLogger
(
javaClass
)
// 注入ChannelManager单例
private
val
channelManager
=
ChannelManager
.
instance
...
...
@@ -34,7 +39,8 @@ class AdasPushTask(
private
var
carDst
=
mutableListOf
<
String
>()
//车辆行驶的位置
private
var
carIndex
=
AtomicInteger
(
0
)
// private var carIndex = AtomicInteger(0)
private
var
carPos
=
0
//感知物
private
var
preDst
=
mutableListOf
<
String
>()
...
...
@@ -47,6 +53,7 @@ class AdasPushTask(
@PostConstruct
fun
readMockFile
()
{
logger
.
info
(
"创建 AdasPushTask 实例,ID: $instanceId"
)
var
classpathResource
=
resourceLoader
.
getResource
(
"classpath:adasm/CarVehicle_fz.txt"
)
// 读取文件内容(Kotlin简化写法)
CoroutineScope
(
Dispatchers
.
IO
).
launch
{
...
...
@@ -59,6 +66,7 @@ class AdasPushTask(
@PreDestroy
fun
destroy
()
{
// logger.info("销毁 AdasPushTask 实例,ID: $instanceId")
carDst
.
clear
()
preDst
.
clear
()
}
...
...
@@ -96,26 +104,31 @@ class AdasPushTask(
CoroutineScope
(
Dispatchers
.
Default
).
launch
{
while
(
isActive
)
{
if
(
pushConfig
.
pushStart
.
get
()
==
0
)
{
println
(
"------------没开始推"
)
//
println("------------没开始推")
// carIndex = 0
isFence
.
set
(
false
)
carPos
=
0
isV2x
.
set
(
false
)
// carIndex.set(0)
isFence
.
set
(
false
)
delay
(
200
)
// sendMsg(channel, carDst.first())
delay
(
1000
)
continue
}
if
(
carDst
.
isNotEmpty
())
{
carDst
.
forEachIndexed
{
index
,
string
->
// println("carIndex = ${carIndex}")
if
(
pushConfig
.
pushStart
.
get
()
==
0
){
return
@forEachIndexed
if
(
pushConfig
.
pushStart
.
get
()
==
0
)
{
return
@forEachIndexed
}
carIndex
.
set
(
index
)
//推送电子围栏
carPos
=
index
// takeFen(index)
// carIndex.set(index)
sendMsg
(
channel
,
string
)
delay
(
200
)
}
println
(
"---- pushConfig.pushStart.set(0)"
)
carIndex
.
set
(
0
)
//
println("---- pushConfig.pushStart.set(0)")
//
carIndex.set(0)
pushConfig
.
pushStart
.
set
(
0
)
}
}
...
...
@@ -141,10 +154,12 @@ class AdasPushTask(
private
fun
pushFence
(
channel
:
Channel
)
{
CoroutineScope
(
Dispatchers
.
Default
).
launch
{
while
(
isActive
)
{
// println("---电子围栏carIndex = ${carIndex.get()}")
if
(
carIndex
.
get
()
==
0
)
// println("---carPos = ${carPos}")
if
(
carPos
==
0
)
{
delay
(
100
)
continue
if
(
carIndex
.
get
()
==
130
)
{
//驶入 130
}
if
(
carPos
==
30
)
{
//驶入 130
if
(
isFence
.
compareAndSet
(
false
,
true
))
{
val
driveInOrOut
=
DriveInOrOut
().
apply
{
finished
=
true
...
...
@@ -152,7 +167,7 @@ class AdasPushTask(
sendMsg
(
channel
,
JSON
.
toJSONString
(
driveInOrOut
))
isFence
.
set
(
false
)
}
}
else
if
(
car
Index
.
get
()
==
500
)
{
//驶出
2
00
}
else
if
(
car
Pos
==
500
)
{
//驶出
5
00
if
(
isFence
.
compareAndSet
(
false
,
true
))
{
val
driveInOrOut
=
DriveInOrOut
().
apply
{
finished
=
false
...
...
@@ -160,7 +175,36 @@ class AdasPushTask(
sendMsg
(
channel
,
JSON
.
toJSONString
(
driveInOrOut
))
}
}
delay
(
150
)
delay
(
50
)
}
}
}
private
fun
takeFen
(
index
:
Int
)
{
if
(
index
==
0
)
{
isFence
.
set
(
false
)
return
}
if
(
index
==
130
)
{
if
(
isFence
.
compareAndSet
(
false
,
true
))
{
val
driveInOrOut
=
DriveInOrOut
().
apply
{
finished
=
true
}
val
fenChannels
=
filterTypeChannels
(
PARAM_TYPE_VALUE_3
)
fenChannels
.
forEach
{
string
,
channel
->
sendMsg
(
channel
,
JSON
.
toJSONString
(
driveInOrOut
))
}
isFence
.
set
(
false
)
}
}
else
if
(
index
==
500
)
{
if
(
isFence
.
compareAndSet
(
false
,
true
))
{
val
driveInOrOut
=
DriveInOrOut
().
apply
{
finished
=
true
}
val
fenChannels
=
filterTypeChannels
(
PARAM_TYPE_VALUE_3
)
fenChannels
.
forEach
{
string
,
channel
->
sendMsg
(
channel
,
JSON
.
toJSONString
(
driveInOrOut
))
}
}
}
}
...
...
@@ -193,22 +237,22 @@ class AdasPushTask(
CoroutineScope
(
Dispatchers
.
Default
).
launch
{
while
(
isActive
)
{
if
(
pushConfig
.
pushStart
.
get
()
==
0
)
{
delay
(
100
0
)
delay
(
100
)
continue
}
if
(
car
Index
.
get
()
<
100
)
if
(
car
Pos
<
100
)
continue
if
(
car
Index
.
get
()
==
200
)
{
//施工
if
(
car
Pos
==
200
)
{
//施工
pushV2xAtomic
(
channel
,
SHIGONG_V2X
)
}
else
if
(
car
Index
.
get
()
==
230
)
{
//交叉路口
}
else
if
(
car
Pos
==
230
)
{
//交叉路口
pushV2xAtomic
(
channel
,
JIAOCHALUKOU_V2X
)
}
else
if
(
car
Index
.
get
()
==
260
)
{
//人行横道
}
else
if
(
car
Pos
==
260
)
{
//人行横道
pushV2xAtomic
(
channel
,
RENXINGHENGDAO_V2X
)
}
else
if
(
car
Index
.
get
()
==
320
)
{
//前向碰撞
}
else
if
(
car
Pos
==
320
)
{
//前向碰撞
pushV2xAtomic
(
channel
,
QIANPENG_V2X
)
}
else
if
(
car
Index
.
get
()
==
350
)
{
//弱势交通
}
else
if
(
car
Pos
==
350
)
{
//弱势交通
pushV2xAtomic
(
channel
,
RUOSHI_V2X
)
}
else
if
(
car
Index
.
get
()
==
400
)
{
//车内限速标牌
}
else
if
(
car
Pos
==
400
)
{
//车内限速标牌
pushV2xAtomic
(
channel
,
XIANSU_V2X
,
false
)
}
delay
(
150
)
...
...
@@ -228,6 +272,25 @@ class AdasPushTask(
}
/**
* 返回某个type的channel
* @param type 前端的查询参数
**/
private
fun
filterTypeChannels
(
type
:
String
):
Map
<
String
,
Channel
>
{
val
onlineChannels
=
channelManager
.
getAllChannels
()
//得到设置了type属性的channel
val
typeChannels
=
onlineChannels
.
filter
{
(
id
,
channel
)
->
if
(
channel
.
hasAttr
(
REQUEST_PARAMS_KEY
))
{
val
params
=
channel
.
attr
(
REQUEST_PARAMS_KEY
).
get
()
return
@filter
params
.
get
(
PARAM_TYPE_KEY
)
==
type
}
false
}
return
typeChannels
}
private
fun
sendMsg
(
channel
:
Channel
,
msg
:
String
)
{
if
(!
channel
.
isActive
())
{
// println("无在线客户端,跳过推送")
...
...
src/main/kotlin/com/inzy/wsmock/push/PushFactory.kt
View file @
6314a96d
...
...
@@ -2,6 +2,9 @@ package com.inzy.wsmock.push
import
com.inzy.wsmock.RequestParamHandler
import
io.netty.channel.Channel
import
jakarta.annotation.PreDestroy
import
org.springframework.beans.factory.annotation.Autowired
import
org.springframework.context.ApplicationContext
import
org.springframework.stereotype.Component
@Component
...
...
@@ -9,6 +12,12 @@ class PushFactory(
private
val
adasPushTask
:
AdasPushTask
)
{
// @Autowired
// private lateinit var applicationContext: ApplicationContext
// private var adasPushTask: AdasPushTask? = null
/**根据路径推送***/
fun
pushMsgFormPath
(
channel
:
Channel
)
{
var
path
=
""
...
...
@@ -30,6 +39,8 @@ class PushFactory(
private
fun
createPushProduct
(
path
:
String
):
PushTask
{
when
(
path
)
{
"/ws/adas"
->
{
// 关键:每次调用 getBean 都会创建新的 AdasPushTask 实例
// return applicationContext.getBean(AdasPushTask::class.java)
return
adasPushTask
}
...
...
@@ -39,5 +50,11 @@ class PushFactory(
}
}
// @PreDestroy
// fun destroy() {
//// println("-=---PushFactory.destroy")
// adasPushTask?.destroy()
// }
}
\ 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