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
4924ed56
Commit
4924ed56
authored
May 16, 2023
by
duanruiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[update] 配置端口常量
parent
1f4db17f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
11 deletions
+20
-11
Application.java
...c-dt-service/src/main/java/net/wanji/com/Application.java
+6
-1
NettyClient.java
...ervice/src/main/java/net/wanji/com/netty/NettyClient.java
+10
-10
application.yml
signal-utc-dt-service/src/main/resources/application.yml
+4
-0
No files found.
signal-utc-dt-service/src/main/java/net/wanji/com/Application.java
View file @
4924ed56
...
...
@@ -4,6 +4,7 @@ import net.wanji.com.netty.NettyClient;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.ApplicationArguments
;
import
org.springframework.boot.ApplicationRunner
;
import
org.springframework.boot.SpringApplication
;
...
...
@@ -25,6 +26,10 @@ public class Application implements ApplicationRunner {
@Qualifier
(
value
=
"threadPoolExecutor"
)
@Autowired
static
ThreadPoolTaskExecutor
threadPoolExecutor
;
@Value
(
"${portParam.localPort}"
)
int
localPort
;
@Value
(
"${portParam.remotePort}"
)
int
remoteProt
;
public
static
void
main
(
String
[]
args
)
{
...
...
@@ -33,6 +38,6 @@ public class Application implements ApplicationRunner {
@Override
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
NettyClient
.
start
(
5050
,
threadPoolExecutor
);
NettyClient
.
start
(
localPort
,
remoteProt
,
threadPoolExecutor
);
}
}
signal-utc-dt-service/src/main/java/net/wanji/com/netty/NettyClient.java
View file @
4924ed56
...
...
@@ -35,15 +35,15 @@ public class NettyClient {
/**
* 建立连接
*/
public
static
void
start
(
int
p
ort
,
ThreadPoolTaskExecutor
threadPoolExecutor
)
throws
InterruptedException
{
public
static
void
start
(
int
localPort
,
int
remoteP
ort
,
ThreadPoolTaskExecutor
threadPoolExecutor
)
throws
InterruptedException
{
EventLoopGroup
group
=
new
NioEventLoopGroup
();
Bootstrap
bootstrap
=
new
Bootstrap
();
bootstrap
.
group
(
group
)
.
channel
(
NioDatagramChannel
.
class
)
.
option
(
ChannelOption
.
RCVBUF_ALLOCATOR
,
new
FixedRecvByteBufAllocator
(
65535
))
// .localAddress(new InetSocketAddress(5051))
// 绑定
bending
端口
.
remoteAddress
(
new
InetSocketAddress
(
5051
))
// 绑定端口
.
remoteAddress
(
new
InetSocketAddress
(
remotePort
))
.
handler
(
new
ChannelInitializer
<
NioDatagramChannel
>()
{
@Override
protected
void
initChannel
(
NioDatagramChannel
datagramChannel
)
{
...
...
@@ -51,13 +51,13 @@ public class NettyClient {
.
addLast
(
new
NettyServerHandler
(
threadPoolExecutor
));
}
});
ChannelFuture
channelFuture
=
bootstrap
.
bind
(
5050
).
sync
();
ChannelFuture
channelFuture
=
bootstrap
.
bind
(
localPort
).
sync
();
Runtime
.
getRuntime
().
addShutdownHook
(
new
Thread
(()
->
{
group
.
shutdownGracefully
();
channelFuture
.
channel
().
closeFuture
().
syncUninterruptibly
();
log
.
warn
(
"server is closed"
);
}));
log
.
info
(
"udp application is running. binding port is {}"
,
p
ort
);
log
.
info
(
"udp application is running. binding port is {}"
,
remoteP
ort
);
NettyClient
.
udpChannelFuture
=
channelFuture
;
}
...
...
@@ -98,11 +98,11 @@ public class NettyClient {
long
now
=
LocalDateTime
.
now
().
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
NettyMessageCache
.
NETTY_MESSAGE_RESULT_MAP
.
forEach
((
k
,
v
)
->
{
// threadPoolExecutor.execute(() -> {
if
(
now
-
v
.
getStartTime
()
>
v
.
getWaitMillisecond
())
{
log
.
warn
(
"wait {}ms {} timeout"
,
v
.
getWaitMillisecond
(),
k
);
v
.
getCountDownLatch
().
countDown
();
}
});
if
(
now
-
v
.
getStartTime
()
>
v
.
getWaitMillisecond
())
{
log
.
warn
(
"wait {}ms {} timeout"
,
v
.
getWaitMillisecond
(),
k
);
v
.
getCountDownLatch
().
countDown
();
}
});
// });
}
}
\ No newline at end of file
signal-utc-dt-service/src/main/resources/application.yml
View file @
4924ed56
...
...
@@ -67,3 +67,7 @@ threadPoolConfig:
queueCapacity
:
200
keepAliveTime
:
6000
allowCoreTimeOut
:
false
#东土通讯端口配置
portParam
:
localPort
:
5051
remotePort
:
5050
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