新增下载平台的test方法,调用下载调度器的文件
parent
fd55f7cfae
commit
6e34870174
@ -1,57 +0,0 @@
|
||||
package com.docus.server.common.netty.server;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.util.AttributeKey;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 客户端IP和通信信道的映射
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ChannelRepository {
|
||||
|
||||
/**
|
||||
* <collectorId-Channel>
|
||||
*/
|
||||
private final static Map<String, Channel> COLLECTOR_ID_CHANNEL_CACHE_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 终端上线
|
||||
*/
|
||||
public void put(String collectorId, Channel channel) {
|
||||
|
||||
//缓存
|
||||
COLLECTOR_ID_CHANNEL_CACHE_MAP.put(collectorId, channel);
|
||||
|
||||
AttributeKey<String> attributeKey = AttributeKey.valueOf("ip");
|
||||
channel.attr(attributeKey).set(collectorId);
|
||||
|
||||
}
|
||||
|
||||
public String getClientKey(Channel channel) {
|
||||
|
||||
AttributeKey<String> key = AttributeKey.valueOf("ip");
|
||||
|
||||
if (channel.hasAttr(key)) {
|
||||
return channel.attr(key).get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Channel get(String key) {
|
||||
return COLLECTOR_ID_CHANNEL_CACHE_MAP.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端离线
|
||||
*/
|
||||
public void remove(String key) {
|
||||
COLLECTOR_ID_CHANNEL_CACHE_MAP.remove(key);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package com.docus.server.common.netty.server;
|
||||
|
||||
import com.docus.core.util.json.JSON;
|
||||
import com.docus.server.common.netty.CommMsg;
|
||||
import com.docus.server.common.netty.state.DeviceStateContext;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.util.Attribute;
|
||||
import io.netty.util.AttributeKey;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 采集器id和终端
|
||||
* 通信信道的映射
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CollectorChannelCacheMap {
|
||||
|
||||
/**
|
||||
* <collectorId-Channel>
|
||||
*/
|
||||
private final static Map<String, Channel> COLLECTOR_ID_CHANNEL_CACHE_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 采集器上线
|
||||
*/
|
||||
public void put(String collectorId, Channel channel) {
|
||||
|
||||
//缓存
|
||||
COLLECTOR_ID_CHANNEL_CACHE_MAP.put(collectorId, channel);
|
||||
|
||||
AttributeKey<String> attributeKey = AttributeKey.valueOf("collectorId");
|
||||
channel.attr(attributeKey).set(collectorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据channel获取采集器id
|
||||
*/
|
||||
public String getClientKey(Channel channel) {
|
||||
|
||||
AttributeKey<String> key = AttributeKey.valueOf("collectorId");
|
||||
|
||||
if (channel.hasAttr(key)) {
|
||||
return channel.attr(key).get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void writeAndFlush(String collectorId, CommMsg commMsg) {
|
||||
Channel channel = this.get(collectorId);
|
||||
if (null != channel && channel.isOpen()) {
|
||||
channel.writeAndFlush(Unpooled.copiedBuffer(JSON.toJSON(commMsg), CharsetUtil.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
public Channel get(String key) {
|
||||
return COLLECTOR_ID_CHANNEL_CACHE_MAP.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端离线
|
||||
*/
|
||||
public void remove(String key) {
|
||||
COLLECTOR_ID_CHANNEL_CACHE_MAP.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置属性
|
||||
*
|
||||
* @param ctx 通道上下文
|
||||
* @param value 值
|
||||
*/
|
||||
public void setAttribute(ChannelHandlerContext ctx, DeviceStateContext value) {
|
||||
Attribute<DeviceStateContext> attribute = getAttribute(ctx);
|
||||
attribute.set(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取属性值
|
||||
*
|
||||
* @param ctx 通道上下文
|
||||
* @return 属性值 有可能为 null
|
||||
*/
|
||||
public DeviceStateContext getAttributeValue(ChannelHandlerContext ctx) {
|
||||
Attribute<DeviceStateContext> attribute = getAttribute(ctx);
|
||||
DeviceStateContext value = attribute.get();
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 永远不会返回 null
|
||||
*
|
||||
* @param ctx channel 上下
|
||||
* @return ctx 关联的 channle 的 attribute
|
||||
*/
|
||||
private Attribute<DeviceStateContext> getAttribute(ChannelHandlerContext ctx) {
|
||||
return ctx.channel().attr(AttributeKey.valueOf("state"));
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
//package com.docus.server.api.scheduling.management;
|
||||
//
|
||||
//import io.swagger.annotations.Api;
|
||||
//import io.swagger.annotations.ApiImplicitParam;
|
||||
//import io.swagger.annotations.ApiImplicitParams;
|
||||
//import io.swagger.annotations.ApiOperation;
|
||||
//import org.springframework.cloud.openfeign.FeignClient;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//import org.springframework.web.multipart.MultipartFile;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * 文件上传下载 API
|
||||
// *
|
||||
// * @author AutoGenerator
|
||||
// * @since 2023-07-15
|
||||
// */
|
||||
//@Api(value = "通用文件上传下载接口", tags = "通用文件上传下载接口")
|
||||
//@FeignClient(value = "collector-scheduling-management", contextId = "collector-scheduling-management.FileApi")
|
||||
//@RequestMapping("/sch/file")
|
||||
//public interface FileApi {
|
||||
//
|
||||
// @ApiOperation("文件下载")
|
||||
// @GetMapping("/download")
|
||||
// void downloadFile(@RequestParam(value = "filePath") String filePath, HttpServletResponse response) throws Exception;
|
||||
//
|
||||
// @ApiOperation("文件上传")
|
||||
// @PostMapping("/upload")
|
||||
// @ApiImplicitParams({
|
||||
// @ApiImplicitParam(name = "files", value = "文件", required = true, dataTypeClass = MultipartFile.class)
|
||||
// })
|
||||
// void uploadFile(@RequestPart MultipartFile[] files, String pathKey) throws Exception;
|
||||
//
|
||||
//}
|
Loading…
Reference in New Issue