修复采集BUG
This commit is contained in:
parent
ee03c86167
commit
abcbd83bc2
5
pom.xml
5
pom.xml
|
@ -112,6 +112,11 @@
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.iot.modbus.rtcp.commons</groupId>
|
||||||
|
<artifactId>modbus-rtcp-commons-keymgr</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-devtools</artifactId>
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.iot.modbus_rtcp;
|
package com.iot.modbus_rtcp;
|
||||||
|
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.iot.modbus.rtcp.commons.keymgr.LicenseValidator;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
@ -12,12 +13,13 @@ import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@SpringBootApplication(scanBasePackages = {"com.iot.modbus_rtcp"})
|
@SpringBootApplication(scanBasePackages = {"com.iot.modbus_rtcp", "com.iot.modbus.rtcp"})
|
||||||
public class ModbusRtcpApplication implements ApplicationContextAware {
|
public class ModbusRtcpApplication implements ApplicationContextAware {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger("com.iot.modbus_rtcp.rabbit");
|
private static final Logger logger = LoggerFactory.getLogger("com.iot.modbus_rtcp.rabbit");
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws Exception {
|
||||||
|
LicenseValidator.main(args);
|
||||||
SpringApplication.run(ModbusRtcpApplication.class, args);
|
SpringApplication.run(ModbusRtcpApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,11 @@ public class ModbusTCPController implements ApplicationRunner {
|
||||||
return Response.succeed(this.nettyServer.getGroup().onlineGateway());
|
return Response.succeed(this.nettyServer.getGroup().onlineGateway());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/online/total")
|
||||||
|
public Response<Long> onlineTotal() {
|
||||||
|
return Response.succeed(this.nettyServer.getGroup().onlineTotal());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) throws Exception {
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
this.nettyServer = new NettyServer(502, 10);
|
this.nettyServer = new NettyServer(502, 10);
|
||||||
|
|
|
@ -10,7 +10,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -81,7 +80,7 @@ public class AutoCollectJobs {
|
||||||
}
|
}
|
||||||
}, new ThreadPoolExecutor.CallerRunsPolicy());
|
}, new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
|
||||||
@Scheduled(cron = "0/30 * * * * ? ")
|
// @Scheduled(cron = "0/30 * * * * ? ")
|
||||||
public void autoCollect() {
|
public void autoCollect() {
|
||||||
int pageIndex = 0;
|
int pageIndex = 0;
|
||||||
int pageSize = 1000;
|
int pageSize = 1000;
|
||||||
|
|
|
@ -72,6 +72,13 @@ public class ChannelGroup {
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long onlineTotal() {
|
||||||
|
return this.mChannelMap.keySet()
|
||||||
|
.stream()
|
||||||
|
.filter(identifier -> !StringUtils.contains(identifier, ":"))
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
public void see() {
|
public void see() {
|
||||||
log.info("当前连接有:{}", new ArrayList<>(this.mChannelMap.keySet()));
|
log.info("当前连接有:{}", new ArrayList<>(this.mChannelMap.keySet()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.iot.modbus_rtcp.netty;
|
package com.iot.modbus_rtcp.netty;
|
||||||
|
|
||||||
|
import com.iot.modbus.rtcp.commons.keymgr.LicenseValidator;
|
||||||
|
import com.iot.modbus_rtcp.utils.SpringUtil;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
|
@ -73,6 +75,7 @@ public class NettyServer extends ChannelInitializer<SocketChannel> {
|
||||||
String ip = ch.remoteAddress().getHostString();
|
String ip = ch.remoteAddress().getHostString();
|
||||||
//过滤掉docker 网关请求
|
//过滤掉docker 网关请求
|
||||||
if ("172.17.0.1".equals(ip)) return;
|
if ("172.17.0.1".equals(ip)) return;
|
||||||
|
SpringUtil.getBean(LicenseValidator.class).verifyNumber(ch::close);
|
||||||
int port = ch.remoteAddress().getPort();
|
int port = ch.remoteAddress().getPort();
|
||||||
this.group.put(ChannelGroup.getKey(ip, port), new SyncPriorityChannel(ch));
|
this.group.put(ChannelGroup.getKey(ip, port), new SyncPriorityChannel(ch));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue