Browse Source

增加OkHttp配置文件读取

tags/v1.0.0^2
林万龙 4 years ago
parent
commit
807ce4deba
5 changed files with 71 additions and 74 deletions
  1. +33
    -0
      src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java
  2. +0
    -42
      src/main/java/com/telpo/dipperposition/co/RzlAccount.java
  3. +29
    -16
      src/main/java/com/telpo/dipperposition/config/PositionConfig.java
  4. +9
    -15
      src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java
  5. +0
    -1
      src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java

+ 33
- 0
src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java View File

@@ -0,0 +1,33 @@
package com.telpo.dipperposition.co;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import okhttp3.*;
import okhttp3.internal.ws.RealWebSocket;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.net.SocketFactory;

/**
* @program: RzlAccount
* @description: 融智联账号配置
* @author: king
* @create: 2021-01-12 14:02
**/
@Getter
@Setter
@Component
public class PositionConfigInfo {

private String serverAddr;

private String timeAsycServerPort;

private String posAsycServerPort;

private String starsAsycServerPort;

}

+ 0
- 42
src/main/java/com/telpo/dipperposition/co/RzlAccount.java View File

@@ -1,42 +0,0 @@
package com.telpo.dipperposition.co;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
* @program: RzlAccount
* @description: 融智联账号配置
* @author: king
* @create: 2021-01-12 14:02
**/
@Lazy
@Getter
@Setter
@ToString
@Component
public class RzlAccount {

@Value("${position.hello}")
private String hello;

RzlAccount()
{
}

private static RzlAccount instance;
public static RzlAccount getInstance(){
if (instance==null){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
instance = new RzlAccount();
}
return instance;
}
}

+ 29
- 16
src/main/java/com/telpo/dipperposition/config/PositionConfig.java View File

@@ -1,10 +1,14 @@
package com.telpo.dipperposition.config;

import com.telpo.dipperposition.co.PositionConfigInfo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
@@ -15,17 +19,28 @@ import org.springframework.context.annotation.Configuration;
*/
@Getter
@Setter
@ToString
@Configuration
public class PositionConfig {

@Autowired
private ConfigurableApplicationContext configurableApplicationContext;
//@Autowired
//private ConfigurableApplicationContext configurableApplicationContext;
//@Value(value = "${position.hello}")
private String hello;
//private String hello;

//@Value(value = "${spring.application.name}")
private String name;
//private String name;

@Value(value = "${position.server.serverAddr}")
private String serverAddr;

@Value(value = "${position.server.timeAsycPort}")
private String timeAsycServerPort;

@Value(value = "${position.server.posAsycPort}")
private String posAsycServerPort;

@Value(value = "${position.server.starsAsycPort}")
private String starsAsycServerPort;

PositionConfig()
{
@@ -33,16 +48,14 @@ public class PositionConfig {
//name = configurableApplicationContext.getEnvironment().getProperty("spring.application.name");
}

private static PositionConfig instance;
public static PositionConfig getInstance(){
if (instance==null){
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
instance = new PositionConfig();
}
return instance;
@Bean (name = "positionConfigInfo")
public PositionConfigInfo positionConfigInfo(){
PositionConfigInfo configInfo = new PositionConfigInfo();
configInfo.setServerAddr(this.serverAddr);
configInfo.setTimeAsycServerPort(this.timeAsycServerPort);
configInfo.setPosAsycServerPort(this.posAsycServerPort);
configInfo.setStarsAsycServerPort(this.starsAsycServerPort);
System.out.print(configInfo.toString());
return configInfo;
}
}

+ 9
- 15
src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java View File

@@ -1,5 +1,6 @@
package com.telpo.dipperposition.server;

import com.telpo.dipperposition.config.PositionConfig;
import com.telpo.dipperposition.handler.ServerChannelInitializer;
import com.telpo.dipperposition.service.IDipperDataAsyncTaskService;
import io.netty.bootstrap.ServerBootstrap;
@@ -24,18 +25,8 @@ import java.net.InetSocketAddress;
@Slf4j
public class DipperPositionServer {

@Value(value = "${position.server.serverAddr}")
private String serverAddr;

@Value(value = "${position.server.timeAsycPort}")
private String timeAsycServerPort;

@Value(value = "${position.server.posAsycPort}")
private String posAsycServerPort;

@Value(value = "${position.server.starsAsycPort}")
private String starsAsycServerPort;

@Autowired
PositionConfig positionConfig;
/*
* 时间同步进程线程
*/
@@ -45,7 +36,8 @@ public class DipperPositionServer {
EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
//new 一个工作线程组
EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(timeAsycServerPort));
InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(),
Integer.parseInt(positionConfig.getTimeAsycServerPort()));
ServerBootstrap bootstrap = new ServerBootstrap()
.group(mainThreadGroup, workThreadGroup)
.channel(NioServerSocketChannel.class)
@@ -83,7 +75,8 @@ public class DipperPositionServer {
EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
//new 一个工作线程组
EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(posAsycServerPort));
InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(),
Integer.parseInt(positionConfig.getPosAsycServerPort()));
ServerBootstrap bootstrap = new ServerBootstrap()
.group(mainThreadGroup, workThreadGroup)
.channel(NioServerSocketChannel.class)
@@ -122,7 +115,8 @@ public class DipperPositionServer {
EventLoopGroup mainThreadGroup = new NioEventLoopGroup(1);
//new 一个工作线程组
EventLoopGroup workThreadGroup = new NioEventLoopGroup(200);
InetSocketAddress socketAddress = new InetSocketAddress(serverAddr, Integer.parseInt(starsAsycServerPort));
InetSocketAddress socketAddress = new InetSocketAddress(positionConfig.getServerAddr(),
Integer.parseInt(positionConfig.getStarsAsycServerPort()));
ServerBootstrap bootstrap = new ServerBootstrap()
.group(mainThreadGroup, workThreadGroup)
.channel(NioServerSocketChannel.class)


+ 0
- 1
src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java View File

@@ -7,7 +7,6 @@ import com.telpo.dipperposition.config.SchedulingExecutorConfig;
import com.telpo.dipperposition.service.IDipperDataAsyncTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;



Loading…
Cancel
Save