|
|
|
@ -4,13 +4,13 @@ package com.zhehekeji.web.service.client;
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -19,25 +19,32 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
public class ClientChanel {
|
|
|
|
public class ClientChanel {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger tcpLogger = LoggerFactory.getLogger("tcp");
|
|
|
|
|
|
|
|
|
|
|
|
static final Logger tcpLogger = LoggerFactory.getLogger("tcp");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* key : 巷道标识符
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static Map<String, Channel> channelMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* key : 巷道标识符
|
|
|
|
* key : 巷道标识符
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static Map<String, Channel> channelMap = new ConcurrentHashMap<>();
|
|
|
|
static Map<String, LocalDateTime> channelStringTime = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* key :IP
|
|
|
|
* key :IP
|
|
|
|
* value: 巷道标识符
|
|
|
|
* value: 巷道标识符
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static Map<String,String> IP_SRMNumberMap = new ConcurrentHashMap<>();
|
|
|
|
static Map<String,String> IP_SRMNumberMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* key :巷道标识符
|
|
|
|
* key :巷道标识符
|
|
|
|
* value: IP
|
|
|
|
* value: IP
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static Map<String,String> SRMNumber_IPMap = new ConcurrentHashMap<>();
|
|
|
|
static Map<String,String> SRMNumber_IPMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
public static void putIp(String ip,String ID){
|
|
|
|
public static void putIp(String ip,String ID){
|
|
|
|
IP_SRMNumberMap.put(ip,ID);
|
|
|
|
IP_SRMNumberMap.put(ip,ID);
|
|
|
|
@ -45,6 +52,7 @@ public class ClientChanel {
|
|
|
|
|
|
|
|
|
|
|
|
public static void putSRMNUmber_Ip(String ID,String ip){
|
|
|
|
public static void putSRMNUmber_Ip(String ID,String ip){
|
|
|
|
SRMNumber_IPMap.put(ID,ip);
|
|
|
|
SRMNumber_IPMap.put(ID,ip);
|
|
|
|
|
|
|
|
IP_SRMNumberMap.put(ip,ID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getIpFromId(String ID){
|
|
|
|
public static String getIpFromId(String ID){
|
|
|
|
@ -64,9 +72,23 @@ public class ClientChanel {
|
|
|
|
InetSocketAddress socketAddress = (InetSocketAddress) channel.remoteAddress();
|
|
|
|
InetSocketAddress socketAddress = (InetSocketAddress) channel.remoteAddress();
|
|
|
|
String clientIp = socketAddress.getAddress().getHostAddress();
|
|
|
|
String clientIp = socketAddress.getAddress().getHostAddress();
|
|
|
|
putSRMNUmber_Ip(SRMNumber, clientIp);
|
|
|
|
putSRMNUmber_Ip(SRMNumber, clientIp);
|
|
|
|
|
|
|
|
channelStringTime.put(SRMNumber,LocalDateTime.now());
|
|
|
|
log.info("connect:{}巷道 ", SRMNumber);
|
|
|
|
log.info("connect:{}巷道 ", SRMNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static {
|
|
|
|
|
|
|
|
// Timer timer = new Timer();
|
|
|
|
|
|
|
|
// timer.scheduleAtFixedRate(new TimerTask() {
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
|
|
|
// public void run() {
|
|
|
|
|
|
|
|
// for (String key :channelStringTime.keySet()){
|
|
|
|
|
|
|
|
// if(LocalDateTime.now().equals(channelStringTime.get(key).plusMinutes(5))) {
|
|
|
|
|
|
|
|
// channelStringTime.remove(key);
|
|
|
|
|
|
|
|
// disConnect(key);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// },0,60000);
|
|
|
|
|
|
|
|
// }
|
|
|
|
public static void disConnect(String key){
|
|
|
|
public static void disConnect(String key){
|
|
|
|
channelMap.remove(key);
|
|
|
|
channelMap.remove(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|