[+] 完善socket信令

This commit is contained in:
acgist
2023-02-14 08:14:23 +08:00
parent 78fa48c35c
commit 778b933000
59 changed files with 751 additions and 679 deletions

View File

@@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
/**
* 事件监听
* 事件用来处理异步业务还有广播业务
*
* @author acgist
*/

View File

@@ -1,87 +1,24 @@
package com.acgist.taoyao.boot.property;
import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import jakarta.annotation.PostConstruct;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
/**
* 脚本配置
*
* @author acgist
*/
@Slf4j
@Getter
@Setter
@ConfigurationProperties(prefix = "taoyao.script")
public class ScriptProperties {
/**
* 系统类型
*
* @author acgist
* 是否启用
*/
public enum SystemType {
/**
* Mac
*/
MAC("Mac OS", "Mac OS X"),
/**
* Linux
*/
LINUX("Linux"),
/**
* Windows
*/
WINDOWS("Windows XP", "Windows Vista", "Windows 7", "Windows 10", "Windows 11"),
/**
* Android
*/
ANDROID("Android");
/**
* 系统名称
*/
private final String[] osNames;
/**
* @param osNames 系统名称
*/
private SystemType(String ... osNames) {
this.osNames = osNames;
}
/**
* @param osName 系统名称
*
* @return 系统类型
*/
private static final SystemType of(String osName) {
final SystemType[] values = SystemType.values();
for (SystemType value : values) {
if(ArrayUtils.contains(value.osNames, osName)) {
return value;
}
}
return SystemType.LINUX;
}
}
/**
* Linux脚本
*/
private Map<String, String> linux;
/**
* Windows脚本
*/
private Map<String, String> windows;
private Boolean enabled;
/**
* 重启媒体服务
*/
@@ -107,29 +44,4 @@ public class ScriptProperties {
*/
private String platformShutdown;
@PostConstruct
public void init() {
final String osName = System.getProperty("os.name");
final SystemType type = SystemType.of(osName);
switch (type) {
case LINUX -> this.set(this.linux);
case WINDOWS -> this.set(this.windows);
default -> log.error("没有配置系统脚本:{}", type);
}
}
/**
* 配置脚本
*
* @param map 脚本
*/
private void set(Map<String, String> map) {
this.mediaReboot = map.get("media-reboot");
this.mediaShutdown = map.get("media-shutdown");
this.systemReboot = map.get("system-reboot");
this.systemShutdown = map.get("system-shutdown");
this.platformReboot = map.get("platform-reboot");
this.platformShutdown = map.get("platform-shutdown");
}
}

View File

@@ -27,6 +27,10 @@ public class SocketProperties {
* 监听端口
*/
private Integer port;
/**
* 超时时间
*/
private Integer timeout;
/**
* 线程队列长度
*/
@@ -47,6 +51,9 @@ public class SocketProperties {
* 线程销毁时间
*/
private Integer keepAliveTime;
/**
* 缓冲大小
*/
private Integer bufferSize;
}

View File

@@ -41,10 +41,5 @@ public class TaoyaoProperties {
*/
@Schema(title = "超时时间", description = "超时时间")
private Long timeout;
/**
* 最大超时时间
*/
@Schema(title = "最大超时时间", description = "最大超时时间")
private Long maxTimeout;
}

View File

@@ -1,36 +0,0 @@
package com.acgist.taoyao.boot.utils;
import java.lang.reflect.InvocationTargetException;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
/**
* Bean工具
*
* @author acgist
*/
@Slf4j
public final class BeanUtils {
private BeanUtils() {
}
/**
* @param <T> 类型
*
* @param clazz 类型
*
* @return 实例
*/
public static final <T> T newInstance(Class<T> clazz) {
Objects.requireNonNull(clazz, "无效类型");
try {
return clazz.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
log.error("创建类型实例异常:{}", clazz, e);
}
return null;
}
}

View File

@@ -1,70 +0,0 @@
package com.acgist.taoyao.boot.utils;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
/**
* URL工具
*
* @author acgist
*/
public final class URLUtils {
private URLUtils() {
}
/**
* URL编码
*
* @param content 原始内容
*
* @return 编码内容
*/
public static final String encode(String content) {
if (StringUtils.isEmpty(content)) {
return content;
}
return URLEncoder
.encode(content, StandardCharsets.UTF_8)
// 空格编码变成加号导致加号解码变成空格
.replace("+", "%20");
}
/**
* URL解码
*
* @param content 编码内容
*
* @return 原始内容
*/
public static final String decode(String content) {
if (StringUtils.isEmpty(content)) {
return content;
}
return URLDecoder.decode(content, StandardCharsets.UTF_8);
}
/**
* Map转为URL参数
*
* @param map Map
*
* @return URL参数
*/
public static final String toQuery(Map<String, String> map) {
if (MapUtils.isEmpty(map)) {
return null;
}
return map.entrySet().stream()
.filter(entry -> StringUtils.isNotEmpty(entry.getKey()) || StringUtils.isNotEmpty(entry.getValue()))
.map(entry -> String.join("=", entry.getKey(), URLUtils.encode(entry.getValue())))
.collect(Collectors.joining("&"));
}
}