Selaa lähdekoodia

增加OkHttp配置文件读取

tags/v1.0.0^2
林万龙 3 vuotta sitten
vanhempi
commit
48f4b5e38c
3 muutettua tiedostoa jossa 59 lisäystä ja 6 poistoa
  1. +3
    -3
      src/main/java/com/telpo/dipperposition/DipperPositionApplication.java
  2. +13
    -3
      src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java
  3. +43
    -0
      src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java

+ 3
- 3
src/main/java/com/telpo/dipperposition/DipperPositionApplication.java Näytä tiedosto

@@ -44,12 +44,12 @@ public class DipperPositionApplication {
log.info("北斗定位服务启动!");
//启动服务端
ConfigurableEnvironment environment = applicationContext.getEnvironment();
log.info(environment.toString());
log.info(environment.getProperty("position-server"));
//log.info(environment.toString());
//log.info(environment.getProperty("position-server"));
//PositionConfigInfo pci;
//pci = (PositionConfigInfo)environment.getProperty("position-server");
DipperPositionServer nettyServer2 = new DipperPositionServer(environment);
log.info(environment.getSystemProperties().toString());
//log.info(environment.getSystemProperties().toString());
nettyServer2.start();
} catch (Exception e) {
log.error(e.getMessage());


+ 13
- 3
src/main/java/com/telpo/dipperposition/handler/NettyServerHandler.java Näytä tiedosto

@@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.io.InputStream;
import java.time.LocalDateTime;

/**
@@ -24,6 +25,9 @@ import java.time.LocalDateTime;
@Slf4j
public class NettyServerHandler extends ChannelInboundHandlerAdapter {

private static String AST_TIME_CMD = "54494d45";
private static String AST_POS_CMD = "504f53";
private static String AST_EPH_CMD = "455048";

@Autowired
private IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService;
@@ -110,13 +114,18 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {

String channelAns = "";
// 返回时间指令
if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) {
//if (Integer.parseInt(timeAsycServerPort) == channel.localAddress().getPort()) {
ByteBuf recvmg = (ByteBuf) msg;
String recvmgStr = recvmg.toString();
if (AST_TIME_CMD.equals(recvmg)) {
// 初始时间辅助输入;
channelAns = dipperTimeAsyncTaskService.pushAstTime();
}

// 发送SDBP-AST-POS获取辅助位置信息
if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) {
// if (Integer.parseInt(posAsycServerPort) == channel.localAddress().getPort()) {

if (AST_POS_CMD.equals(recvmg)) {
channelAns = dipperAstPosAsyncTaskService.pushAstPos(ipAddress,
centerProvinceFilePath,
centerProvince,
@@ -125,7 +134,8 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
}

// 从缓存获取SDBP-AST-EPH星历数
if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) {
//if (Integer.parseInt(starsAsycServerPort) == channel.localAddress().getPort()) {
if (AST_POS_CMD.equals(recvmg)) {
channelAns = dipperDataAsyncTaskService.getAstEPH();
}



+ 43
- 0
src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java Näytä tiedosto

@@ -28,6 +28,7 @@ public class DipperPositionServer {

// @Autowired PositionConfigInfo positionConfigInfo;
private String serverAddr;
private Integer serverPort;
private Integer timeAsycPort;
private Integer posAsycPort;
private Integer starsAsycPort;
@@ -35,6 +36,7 @@ public class DipperPositionServer {
public DipperPositionServer(ConfigurableEnvironment environment) throws NacosException {

this.serverAddr = environment.getProperty("position-server.serverAddr");
this.serverPort = Integer.parseInt(environment.getProperty("server.port"));
this.timeAsycPort = Integer.parseInt(environment.getProperty("position-server.timeAsycPort"));
this.posAsycPort = Integer.parseInt(environment.getProperty("position-server.posAsycPort"));
this.starsAsycPort = Integer.parseInt(environment.getProperty("position-server.starsAsycPort"));
@@ -211,4 +213,45 @@ public class DipperPositionServer {
workThreadGroup.shutdownGracefully();
}
}

public void start2() {

//new 一个主线程组
EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
//new 一个工作线程组
EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
//InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,null);
ServerBootstrap bootstrap = new ServerBootstrap()
.group(mainThreadGroup, workThreadGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ServerChannelInitializer())
//.localAddress(socketAddress)
//设置队列大小
.option(ChannelOption.SO_BACKLOG, 1024)
// 两小时内没有数据的通信时,TCP会自动发送一个活动探测数据报文
.childOption(ChannelOption.SO_KEEPALIVE, true);


//绑定端口,开始接收进来的连接
try {
ChannelFuture channelFuture = bootstrap.bind(serverPort).sync();
log.info("时间辅助服务器启动开始监听端口: {}", serverPort);
channelFuture.addListener(future -> {
if (future.isSuccess()){
System.out.println("start success");
}else{
System.out.println("start failed");
}
});

//channelFuture.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
//关闭主线程组
mainThreadGroup.shutdownGracefully();
//关闭工作线程组
workThreadGroup.shutdownGracefully();
}
}
}

Loading…
Peruuta
Tallenna