Quellcode durchsuchen

增加OkHttp配置文件读取

tags/v1.0.0^2
林万龙 vor 3 Jahren
Ursprung
Commit
baf415e73b
5 geänderte Dateien mit 162 neuen und 138 gelöschten Zeilen
  1. +2
    -2
      dipper_position_run.sh
  2. +1
    -1
      setup_dev.sh
  3. +1
    -1
      setup_test.sh
  4. +10
    -10
      src/main/java/com/telpo/dipperposition/DipperPositionApplication.java
  5. +148
    -124
      src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java

+ 2
- 2
dipper_position_run.sh Datei anzeigen

@@ -9,7 +9,7 @@ if [[ ${environment} == 'production' ]]; then
docker rmi -f $(docker images | grep registry.cn-shanghai.aliyuncs.com/telpo_platform/rzl_adapter | awk '{print $3}')
docker login --username=rzl_wangjx@1111649216405698 --password=telpo.123 registry.cn-shanghai.aliyuncs.com
docker pull registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version
docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8092:8092 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version
docker run -e active=pro -v /home/data/dipperposition/log:/var/log/dipperposition --restart=always -p 8092:8092 -p 9101:9101 -p 9102:9102 -p 9103:9103 -d --name dipperposition_service registry.cn-shanghai.aliyuncs.com/telpo_platform/dipperposition_service:$version
#删除产生的None镜像
docker rmi -f $(docker images | grep none | awk '{print $3}')
docker ps -a
@@ -21,7 +21,7 @@ if [[ ${environment} == 'test' ]]; then

docker rmi -f $(docker images | grep 139.224.254.18:5000/dipperposition_service | awk '{print $3}')
docker pull 139.224.254.18:5000/rzl_adapter:$version
docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version
docker run -v /home/data/dipperposition/log:/var/log/dipperposition -e active=test --restart=always -d --network host -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$version

#删除产生的None镜像
docker rmi -f $(docker images | grep none | awk '{print $3}')


+ 1
- 1
setup_dev.sh Datei anzeigen

@@ -22,6 +22,6 @@ docker rmi -f $(docker images | grep none | awk '{print $3}')
# 查看镜像列表
docker images
# 启动容器
docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version
docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=dev --network host --restart=always -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version
# 查看日志
# docker logs dipperposition_service

+ 1
- 1
setup_test.sh Datei anzeigen

@@ -22,6 +22,6 @@ docker rmi -f $(docker images | grep none | awk '{print $3}')
# 查看镜像列表
docker images
# 启动容器
docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version
docker run -v /home/data/dipperposition/log:/var/log/dipperposition -d -e active=test --network host --restart=always -p 9101:9101 -p 9102:9102 -p 9103:9103 --name dipperposition_service 139.224.254.18:5000/dipperposition_service:$image_version
# 查看日志
# docker logs dipperposition_service

+ 10
- 10
src/main/java/com/telpo/dipperposition/DipperPositionApplication.java Datei anzeigen

@@ -5,6 +5,7 @@ import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.exception.NacosException;
import com.telpo.dipperposition.co.PositionConfigInfo;
import com.telpo.dipperposition.server.DipperPositionServer;
import com.telpo.dipperposition.server.EphAsyncServer;
import com.telpo.dipperposition.server.TimeAsyncServer;
@@ -14,6 +15,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@@ -35,18 +38,15 @@ import java.util.concurrent.Executor;
public class DipperPositionApplication {

public static void main(String[] args) {
log.info("北斗定位服务开始!");
SpringApplication.run(DipperPositionApplication.class, args);
log.info("北斗定位服务启动!");
try {
test();
log.info("北斗定位服务开始!");
ConfigurableApplicationContext applicationContext = SpringApplication.run(DipperPositionApplication.class, args);
log.info("北斗定位服务启动!");
//启动服务端
TimeAsyncServer nettyServer1 = new TimeAsyncServer();
nettyServer1.startTimeAsnc();
DipperPositionServer nettyServer2 = new DipperPositionServer();
nettyServer2.startPosAsnc();
EphAsyncServer nettyServer3 = new EphAsyncServer();
nettyServer3.startStarsAsnc();
ConfigurableEnvironment environment = applicationContext.getEnvironment();
PositionConfigInfo pci;
pci = (PositionConfigInfo)environment.getSystemProperties().get("position-server");
DipperPositionServer nettyServer2 = new DipperPositionServer(pci);
} catch (Exception e) {
log.error(e.getMessage());
}


+ 148
- 124
src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java Datei anzeigen

@@ -4,6 +4,7 @@ import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.exception.NacosException;
import com.telpo.dipperposition.co.PositionConfigInfo;
import com.telpo.dipperposition.handler.ServerChannelInitializer;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
@@ -12,15 +13,6 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.yaml.snakeyaml.Yaml;

import java.io.ByteArrayInputStream;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Properties;


/**
* @program: DipperPositionServer
@@ -37,132 +29,137 @@ public class DipperPositionServer {
private Integer posAsycPort;
private Integer starsAsycPort;

public DipperPositionServer() throws NacosException {
//String serverAddr = positionConfigInfo.getServerAddr();
try {
try {
InetAddress ip4 = Inet4Address.getLocalHost();
serverAddr = ip4.getHostAddress();
} catch (Exception ex) {
serverAddr = "172.16.192.26";
ex.printStackTrace();
}
String dataId = "dipperposition-service";
String group = "DEFAULT_GROUP";
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
ConfigService configService = NacosFactory.createConfigService(properties);
String content = configService.getConfig(dataId, group, 5000);

ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes());
Yaml yaml = new Yaml();
Map m1 = yaml.load(tInputStringStream);
Map m2 = (Map) m1.get("position-server");
this.serverAddr = (String)m2.get("serverAddr");
this.timeAsycPort = (Integer)m2.get("timeAsycPort");
this.posAsycPort = (Integer)m2.get("posAsycPort");
this.starsAsycPort = (Integer)m2.get("starsAsycPort");
//log.info("Map server is:" + m2.get("serverAddr"));
} catch (Exception ex) {
ex.printStackTrace();
}
//log.info("Config serverAddr is " + serverAddr);
}
/*
* 时间同步进程线程
*/
public void startTimeAsnc() {
public DipperPositionServer(PositionConfigInfo pci) throws NacosException {

//new 一个主线程组
EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
//new 一个工作线程组
EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,
timeAsycPort);
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 future = bootstrap.bind(socketAddress).sync();
log.info("服务器启动开始监听端口: {}", socketAddress.getPort());


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

/*
* 时间同步进程线程
*/
public void startPosAsnc() {

//new 一个主线程组
EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
//new 一个工作线程组
EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,
posAsycPort);
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 future = bootstrap.bind(socketAddress).sync();
log.info("服务器启动开始监听端口: {}", socketAddress.getPort());


future.channel().closeFuture().sync();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
//关闭主线程组
mainThreadGroup.shutdownGracefully();
//关闭工作线程组
workThreadGroup.shutdownGracefully();
}
this.serverAddr = pci.getServerAddr();
this.timeAsycPort = Integer.parseInt(pci.getTimeAsycPort());
this.posAsycPort = Integer.parseInt(pci.getPosAsycPort());
this.starsAsycPort = Integer.parseInt(pci.getStarsAsycPort());
//String serverAddr = positionConfigInfo.getServerAddr();
// try {
// try {
// InetAddress ip4 = Inet4Address.getLocalHost();
// serverAddr = ip4.getHostAddress();
// } catch (Exception ex) {
// serverAddr = "172.16.192.26";
// ex.printStackTrace();
// }
// String dataId = "dipperposition-service";
// String group = "DEFAULT_GROUP";
// Properties properties = new Properties();
// properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
// ConfigService configService = NacosFactory.createConfigService(properties);
// String content = configService.getConfig(dataId, group, 5000);
//
// ByteArrayInputStream tInputStringStream = new ByteArrayInputStream(content.getBytes());
// Yaml yaml = new Yaml();
// Map m1 = yaml.load(tInputStringStream);
// Map m2 = (Map) m1.get("position-server");
// this.serverAddr = (String)m2.get("serverAddr");
// this.timeAsycPort = (Integer)m2.get("timeAsycPort");
// this.posAsycPort = (Integer)m2.get("posAsycPort");
// this.starsAsycPort = (Integer)m2.get("starsAsycPort");
// log.info("Map server is:" + m2.get("serverAddr"));
// } catch (Exception ex) {
// ex.printStackTrace();
// }
}
// /*
// * 时间同步进程线程
// */
// public void startTimeAsnc() {
//
// //new 一个主线程组
// EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
// //new 一个工作线程组
// EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
// InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,
// timeAsycPort);
// 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 future = bootstrap.bind(socketAddress).sync();
// log.info("服务器启动开始监听端口: {}", socketAddress.getPort());
//
//
// future.channel().closeFuture().sync();
// } catch (InterruptedException e) {
// e.printStackTrace();
// } finally {
// //关闭主线程组
// mainThreadGroup.shutdownGracefully();
// //关闭工作线程组
// workThreadGroup.shutdownGracefully();
// }
// }

// /*
// * 时间同步进程线程
// */
// public void startPosAsnc() {
//
// //new 一个主线程组
// EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
// //new 一个工作线程组
// EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
// InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,
// posAsycPort);
// 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 future = bootstrap.bind(socketAddress).sync();
// log.info("服务器启动开始监听端口: {}", socketAddress.getPort());
//
//
// future.channel().closeFuture().sync();
// } catch (InterruptedException e) {
// e.printStackTrace();
// } finally {
// //关闭主线程组
// mainThreadGroup.shutdownGracefully();
// //关闭工作线程组
// workThreadGroup.shutdownGracefully();
// }
// }


/*
* 星历同步进程线程
*/
public void startStarsAsnc() {
//public void startStarsAsnc() {
public void start() {

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

//绑定端口,开始接收进来的连接
try {
ChannelFuture future = bootstrap.bind(socketAddress).sync();
log.info("服务器启动开始监听端口: {}", socketAddress.getPort());


future.channel().closeFuture().sync();
ChannelFuture channelFuture = bootstrap.bind(timeAsycPort).sync();
log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort);
channelFuture.addListener(future -> {
if (future.isSuccess()){
System.out.println("start success");
}else{
System.out.println("start failed");
}
});

ChannelFuture channelFuture2 = bootstrap.bind(posAsycPort).sync();
log.info("位置服务器启动开始监听端口: {}", posAsycPort);
channelFuture2.addListener(future -> {
if (future.isSuccess()){
System.out.println("start success");
}else{
System.out.println("start failed");
}
});


ChannelFuture channelFuture3 = bootstrap.bind(starsAsycPort).sync();
log.info("星历服务器启动开始监听端口: {}", starsAsycPort);
channelFuture3.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 {


Laden…
Abbrechen
Speichern