Bläddra i källkod

修改到docker外运行环境

tags/v1.0.0^2
林万龙 3 år sedan
förälder
incheckning
49ebcb1f85
5 ändrade filer med 26 tillägg och 102 borttagningar
  1. +1
    -2
      src/main/java/com/telpo/dipperposition/DipperPositionApplication.java
  2. +7
    -0
      src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java
  3. +7
    -0
      src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java
  4. +7
    -0
      src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java
  5. +4
    -100
      src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java

+ 1
- 2
src/main/java/com/telpo/dipperposition/DipperPositionApplication.java Visa fil

@@ -33,8 +33,7 @@ public class DipperPositionApplication {
log.info("北斗定位服务启动!");
//启动服务端
ConfigurableEnvironment environment = applicationContext.getEnvironment();
// TimeAsyncServer timeAsyncServer = new TimeAsyncServer(environment);
// timeAsyncServer.start();

DipperPositionServer nettyServer = new DipperPositionServer(environment);
nettyServer.start();
} catch (Exception e) {


+ 7
- 0
src/main/java/com/telpo/dipperposition/controller/DipperAstPosAsyncTaskController.java Visa fil

@@ -6,6 +6,8 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;


/**
* @program: DipperAstPosAsyncTaskController
@@ -20,6 +22,11 @@ public class DipperAstPosAsyncTaskController {
@Autowired
IDipperAstPosAsyncTaskService dipperAstPosAsyncTaskService;

private DipperAstPosAsyncTaskController dipperAstPosAsyncTaskController;
@PostConstruct
public void init() {
dipperAstPosAsyncTaskController = this;
}
/*
* 拉取星历数据
*/


+ 7
- 0
src/main/java/com/telpo/dipperposition/controller/DipperAstTimeAsyncTaskController.java Visa fil

@@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;


/**
* @program: DipperPositionController
@@ -22,6 +24,11 @@ public class DipperAstTimeAsyncTaskController {
@Autowired
IDipperAstTimeAsyncTaskService dipperTimeAsyncTaskService;

private DipperAstTimeAsyncTaskController dipperTimeAsyncTaskController;
@PostConstruct
public void init() {
dipperTimeAsyncTaskController = this;
}
/*
* 拉取星历数据
*/


+ 7
- 0
src/main/java/com/telpo/dipperposition/controller/DipperDataAsyncTaskController.java Visa fil

@@ -7,6 +7,8 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;


/**
* @program: DipperPositionController
@@ -24,6 +26,11 @@ public class DipperDataAsyncTaskController {
@Autowired
IDipperDataAsyncTaskService dipperDataAsyncTaskService;

private DipperDataAsyncTaskController dipperDataAsyncTaskController;
@PostConstruct
public void init() {
dipperDataAsyncTaskController = this;
}
/*
* 拉取星历数据
*/


+ 4
- 100
src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java Visa fil

@@ -26,48 +26,14 @@ import java.net.InetSocketAddress;
@Slf4j
public class DipperPositionServer {

// @Autowired PositionConfigInfo positionConfigInfo;
private String serverAddr;
private Integer serverPort;
private Integer timeAsycPort;
private Integer posAsycPort;
private Integer starsAsycPort;

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"));
//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();
// }
}

/*
@@ -79,12 +45,12 @@ public class DipperPositionServer {
EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
//new 一个工作线程组
EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
//InetSocketAddress socketAddress = new InetSocketAddress(serverAddr,9011);
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会自动发送一个活动探测数据报文
@@ -93,30 +59,8 @@ public class DipperPositionServer {

//绑定端口,开始接收进来的连接
try {
// 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.channel().closeFuture().sync();
//
// 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");
// }
// });
// channelFuture2.channel().closeFuture().sync();
//

ChannelFuture channelFuture3 = bootstrap.bind(starsAsycPort).sync();
ChannelFuture channelFuture3 = bootstrap.bind(socketAddress).sync();
log.info("星历服务器启动开始监听端口: {}", starsAsycPort);
channelFuture3.addListener(future -> {
if (future.isSuccess()){
@@ -136,44 +80,4 @@ public class DipperPositionServer {
}
}

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(timeAsycPort).sync();
log.info("时间辅助服务器启动开始监听端口: {}", timeAsycPort);
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();
}
}
}

Laddar…
Avbryt
Spara