diff --git a/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java b/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java new file mode 100644 index 0000000..f4f3de0 --- /dev/null +++ b/src/main/java/com/telpo/dipperposition/co/PositionConfigInfo.java @@ -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; + +} diff --git a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java b/src/main/java/com/telpo/dipperposition/co/RzlAccount.java deleted file mode 100644 index 5b589b4..0000000 --- a/src/main/java/com/telpo/dipperposition/co/RzlAccount.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java index d9faef3..aae0be6 100644 --- a/src/main/java/com/telpo/dipperposition/config/PositionConfig.java +++ b/src/main/java/com/telpo/dipperposition/config/PositionConfig.java @@ -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; } } diff --git a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java index 9b4066d..48b475f 100644 --- a/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java +++ b/src/main/java/com/telpo/dipperposition/server/DipperPositionServer.java @@ -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) diff --git a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java index 0928dc5..8eb9e01 100644 --- a/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java +++ b/src/main/java/com/telpo/dipperposition/service/impl/DipperDataAsyncTaskServiceImpl.java @@ -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;