新增延迟测试,允许测试指定服务器之间或指定服务器到自定义公网ip的延迟,去除服务器状态信息,升级springboot版本
This commit is contained in:
parent
8b94d074cc
commit
fa0c2d43bd
25
pom.xml
25
pom.xml
@ -14,7 +14,7 @@
|
|||||||
<name>scalable-network-storage</name>
|
<name>scalable-network-storage</name>
|
||||||
<description>scalable-network-storage</description>
|
<description>scalable-network-storage</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>21</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -69,16 +69,10 @@
|
|||||||
<version>5.8.26</version>
|
<version>5.8.26</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.oshi</groupId>
|
|
||||||
<artifactId>oshi-core</artifactId>
|
|
||||||
<version>6.4.7</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-compress</artifactId>
|
<artifactId>commons-compress</artifactId>
|
||||||
<version>1.21</version>
|
<version>1.25.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -101,6 +95,21 @@
|
|||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.graalvm.buildtools</groupId>
|
||||||
|
<artifactId>native-maven-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<imageName>sns</imageName>
|
||||||
|
<buildArgs>
|
||||||
|
<arg>--gc=G1</arg>
|
||||||
|
<arg>-H:+ReportExceptionStackTraces</arg>
|
||||||
|
<arg>--initialize-at-build-time=org.apache.commons.logging.LogFactory,org.apache.commons.logging.LogFactoryService</arg>
|
||||||
|
</buildArgs>
|
||||||
|
<metadataRepository>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</metadataRepository>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.lion.sns;
|
package com.lion.sns;
|
||||||
|
|
||||||
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
@ -11,9 +12,14 @@ public class ScalableNetworkStorageApplication {
|
|||||||
private static ConfigurableApplicationContext context;
|
private static ConfigurableApplicationContext context;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
boot();
|
||||||
context = SpringApplication.run(ScalableNetworkStorageApplication.class, args);
|
context = SpringApplication.run(ScalableNetworkStorageApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void boot(){
|
||||||
|
new Bootstrap();
|
||||||
|
}
|
||||||
|
|
||||||
public static void restart() {
|
public static void restart() {
|
||||||
ApplicationArguments args = context.getBean(ApplicationArguments.class);
|
ApplicationArguments args = context.getBean(ApplicationArguments.class);
|
||||||
|
|
||||||
|
|||||||
@ -1,18 +1,30 @@
|
|||||||
package com.lion.sns.configuration;
|
package com.lion.sns.configuration;
|
||||||
|
|
||||||
|
import com.lion.sns.message.*;
|
||||||
|
import com.lion.sns.pojo.*;
|
||||||
|
import com.lion.sns.pojo.Record;
|
||||||
import com.lion.sns.service.UserService;
|
import com.lion.sns.service.UserService;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.servlet.http.HttpSessionEvent;
|
import jakarta.servlet.http.HttpSessionEvent;
|
||||||
import jakarta.servlet.http.HttpSessionListener;
|
import jakarta.servlet.http.HttpSessionListener;
|
||||||
|
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@RegisterReflectionForBinding(classes = {AbstractMessage.class, AdjustShareMessage.class, CancelShareMessage.class, CompressFileMessage.class, ConfigMessage.class,
|
||||||
|
ConnectMessage.class, DelayTestMessage.class, DynamicConfigMessage.class, ExtractFileMessage.class, FileOperateMessage.class, FileQueryMessage.class, FileResponseMessage.class,
|
||||||
|
MoveFileRequestMessage.class, MoveFileResponseMessage.class, PairMessage.class, PairResultMessage.class, ResponseMessage.class, ShareFileMessage.class, ShareFileQueryMessage.class,
|
||||||
|
TaskCancelMessage.class, TaskStatusMessage.class, UnPairMessage.class, FileNode.class, Progress.class, Record.class, ShareFile.class, ShareFileDownloadRecord.class, Site.class, Task.class,
|
||||||
|
User.class})
|
||||||
public class BeanConfiguration {
|
public class BeanConfiguration {
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
|
public BeanConfiguration(UserService userService){
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public HttpSessionListener getHttpSessionListener(){
|
public HttpSessionListener getHttpSessionListener(){
|
||||||
return new HttpSessionListener() {
|
return new HttpSessionListener() {
|
||||||
|
|||||||
@ -0,0 +1,266 @@
|
|||||||
|
package com.lion.sns.configuration;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.ibatis.annotations.DeleteProvider;
|
||||||
|
import org.apache.ibatis.annotations.InsertProvider;
|
||||||
|
import org.apache.ibatis.annotations.SelectProvider;
|
||||||
|
import org.apache.ibatis.annotations.UpdateProvider;
|
||||||
|
import org.apache.ibatis.cache.decorators.FifoCache;
|
||||||
|
import org.apache.ibatis.cache.decorators.LruCache;
|
||||||
|
import org.apache.ibatis.cache.decorators.SoftCache;
|
||||||
|
import org.apache.ibatis.cache.decorators.WeakCache;
|
||||||
|
import org.apache.ibatis.cache.impl.PerpetualCache;
|
||||||
|
import org.apache.ibatis.javassist.util.proxy.ProxyFactory;
|
||||||
|
import org.apache.ibatis.javassist.util.proxy.RuntimeSupport;
|
||||||
|
import org.apache.ibatis.logging.Log;
|
||||||
|
import org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl;
|
||||||
|
import org.apache.ibatis.logging.jdk14.Jdk14LoggingImpl;
|
||||||
|
import org.apache.ibatis.logging.log4j2.Log4j2Impl;
|
||||||
|
import org.apache.ibatis.logging.nologging.NoLoggingImpl;
|
||||||
|
import org.apache.ibatis.logging.slf4j.Slf4jImpl;
|
||||||
|
import org.apache.ibatis.logging.stdout.StdOutImpl;
|
||||||
|
import org.apache.ibatis.reflection.TypeParameterResolver;
|
||||||
|
import org.apache.ibatis.scripting.defaults.RawLanguageDriver;
|
||||||
|
import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
|
||||||
|
import org.apache.ibatis.session.SqlSessionFactory;
|
||||||
|
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||||
|
import org.mybatis.spring.mapper.MapperFactoryBean;
|
||||||
|
import org.mybatis.spring.mapper.MapperScannerConfigurer;
|
||||||
|
import org.springframework.aot.hint.MemberCategory;
|
||||||
|
import org.springframework.aot.hint.RuntimeHints;
|
||||||
|
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||||
|
import org.springframework.beans.PropertyValue;
|
||||||
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
|
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
|
||||||
|
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
|
||||||
|
import org.springframework.beans.factory.aot.BeanRegistrationExcludeFilter;
|
||||||
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||||
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor;
|
||||||
|
import org.springframework.beans.factory.support.RegisteredBean;
|
||||||
|
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.ImportRuntimeHints;
|
||||||
|
import org.springframework.core.ResolvableType;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@ImportRuntimeHints(MyBatisNativeConfiguration.MyBaitsRuntimeHintsRegistrar.class)
|
||||||
|
public class MyBatisNativeConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
MyBatisBeanFactoryInitializationAotProcessor myBatisBeanFactoryInitializationAotProcessor() {
|
||||||
|
return new MyBatisBeanFactoryInitializationAotProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
static MyBatisMapperFactoryBeanPostProcessor myBatisMapperFactoryBeanPostProcessor() {
|
||||||
|
return new MyBatisMapperFactoryBeanPostProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MyBaitsRuntimeHintsRegistrar implements RuntimeHintsRegistrar {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||||
|
Stream.of(RawLanguageDriver.class,
|
||||||
|
XMLLanguageDriver.class,
|
||||||
|
RuntimeSupport.class,
|
||||||
|
ProxyFactory.class,
|
||||||
|
Slf4jImpl.class,
|
||||||
|
Log.class,
|
||||||
|
JakartaCommonsLoggingImpl.class,
|
||||||
|
Log4j2Impl.class,
|
||||||
|
Jdk14LoggingImpl.class,
|
||||||
|
StdOutImpl.class,
|
||||||
|
NoLoggingImpl.class,
|
||||||
|
SqlSessionFactory.class,
|
||||||
|
PerpetualCache.class,
|
||||||
|
FifoCache.class,
|
||||||
|
LruCache.class,
|
||||||
|
SoftCache.class,
|
||||||
|
WeakCache.class,
|
||||||
|
SqlSessionFactoryBean.class,
|
||||||
|
ArrayList.class,
|
||||||
|
HashMap.class,
|
||||||
|
TreeSet.class,
|
||||||
|
HashSet.class
|
||||||
|
).forEach(x -> hints.reflection().registerType(x, MemberCategory.values()));
|
||||||
|
Stream.of(
|
||||||
|
"org/apache/ibatis/builder/xml/*.dtd",
|
||||||
|
"org/apache/ibatis/builder/xml/*.xsd"
|
||||||
|
).forEach(hints.resources()::registerPattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MyBatisBeanFactoryInitializationAotProcessor
|
||||||
|
implements BeanFactoryInitializationAotProcessor, BeanRegistrationExcludeFilter {
|
||||||
|
|
||||||
|
private final Set<Class<?>> excludeClasses = new HashSet<>();
|
||||||
|
|
||||||
|
MyBatisBeanFactoryInitializationAotProcessor() {
|
||||||
|
excludeClasses.add(MapperScannerConfigurer.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public boolean isExcludedFromAotProcessing(RegisteredBean registeredBean) {
|
||||||
|
return excludeClasses.contains(registeredBean.getBeanClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
|
||||||
|
String[] beanNames = beanFactory.getBeanNamesForType(MapperFactoryBean.class);
|
||||||
|
if (beanNames.length == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (context, code) -> {
|
||||||
|
RuntimeHints hints = context.getRuntimeHints();
|
||||||
|
for (String beanName : beanNames) {
|
||||||
|
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName.substring(1));
|
||||||
|
PropertyValue mapperInterface = beanDefinition.getPropertyValues().getPropertyValue("mapperInterface");
|
||||||
|
if (mapperInterface != null && mapperInterface.getValue() != null) {
|
||||||
|
Class<?> mapperInterfaceType = (Class<?>) mapperInterface.getValue();
|
||||||
|
if (mapperInterfaceType != null) {
|
||||||
|
registerReflectionTypeIfNecessary(mapperInterfaceType, hints);
|
||||||
|
hints.proxies().registerJdkProxy(mapperInterfaceType);
|
||||||
|
hints.resources()
|
||||||
|
.registerPattern(mapperInterfaceType.getName().replace('.', '/').concat(".xml"));
|
||||||
|
registerMapperRelationships(mapperInterfaceType, hints);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerMapperRelationships(Class<?> mapperInterfaceType, RuntimeHints hints) {
|
||||||
|
Method[] methods = ReflectionUtils.getAllDeclaredMethods(mapperInterfaceType);
|
||||||
|
for (Method method : methods) {
|
||||||
|
if (method.getDeclaringClass() != Object.class) {
|
||||||
|
ReflectionUtils.makeAccessible(method);
|
||||||
|
registerSqlProviderTypes(method, hints, SelectProvider.class, SelectProvider::value, SelectProvider::type);
|
||||||
|
registerSqlProviderTypes(method, hints, InsertProvider.class, InsertProvider::value, InsertProvider::type);
|
||||||
|
registerSqlProviderTypes(method, hints, UpdateProvider.class, UpdateProvider::value, UpdateProvider::type);
|
||||||
|
registerSqlProviderTypes(method, hints, DeleteProvider.class, DeleteProvider::value, DeleteProvider::type);
|
||||||
|
Class<?> returnType = MyBatisMapperTypeUtils.resolveReturnClass(mapperInterfaceType, method);
|
||||||
|
registerReflectionTypeIfNecessary(returnType, hints);
|
||||||
|
MyBatisMapperTypeUtils.resolveParameterClasses(mapperInterfaceType, method)
|
||||||
|
.forEach(x -> registerReflectionTypeIfNecessary(x, hints));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
private <T extends Annotation> void registerSqlProviderTypes(
|
||||||
|
Method method, RuntimeHints hints, Class<T> annotationType, Function<T, Class<?>>... providerTypeResolvers) {
|
||||||
|
for (T annotation : method.getAnnotationsByType(annotationType)) {
|
||||||
|
for (Function<T, Class<?>> providerTypeResolver : providerTypeResolvers) {
|
||||||
|
registerReflectionTypeIfNecessary(providerTypeResolver.apply(annotation), hints);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerReflectionTypeIfNecessary(Class<?> type, RuntimeHints hints) {
|
||||||
|
if (!type.isPrimitive() && !type.getName().startsWith("java")) {
|
||||||
|
hints.reflection().registerType(type, MemberCategory.values());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MyBatisMapperTypeUtils {
|
||||||
|
private MyBatisMapperTypeUtils() {
|
||||||
|
// NOP
|
||||||
|
}
|
||||||
|
|
||||||
|
static Class<?> resolveReturnClass(Class<?> mapperInterface, Method method) {
|
||||||
|
Type resolvedReturnType = TypeParameterResolver.resolveReturnType(method, mapperInterface);
|
||||||
|
return typeToClass(resolvedReturnType, method.getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
static Set<Class<?>> resolveParameterClasses(Class<?> mapperInterface, Method method) {
|
||||||
|
return Stream.of(TypeParameterResolver.resolveParamTypes(method, mapperInterface))
|
||||||
|
.map(x -> typeToClass(x, x instanceof Class ? (Class<?>) x : Object.class)).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> typeToClass(Type src, Class<?> fallback) {
|
||||||
|
Class<?> result = null;
|
||||||
|
if (src instanceof Class<?>) {
|
||||||
|
if (((Class<?>) src).isArray()) {
|
||||||
|
result = ((Class<?>) src).getComponentType();
|
||||||
|
} else {
|
||||||
|
result = (Class<?>) src;
|
||||||
|
}
|
||||||
|
} else if (src instanceof ParameterizedType) {
|
||||||
|
ParameterizedType parameterizedType = (ParameterizedType) src;
|
||||||
|
int index = (parameterizedType.getRawType() instanceof Class
|
||||||
|
&& Map.class.isAssignableFrom((Class<?>) parameterizedType.getRawType())
|
||||||
|
&& parameterizedType.getActualTypeArguments().length > 1) ? 1 : 0;
|
||||||
|
Type actualType = parameterizedType.getActualTypeArguments()[index];
|
||||||
|
result = typeToClass(actualType, fallback);
|
||||||
|
}
|
||||||
|
if (result == null) {
|
||||||
|
result = fallback;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static class MyBatisMapperFactoryBeanPostProcessor implements MergedBeanDefinitionPostProcessor, BeanFactoryAware {
|
||||||
|
|
||||||
|
private static final org.apache.commons.logging.Log LOG = LogFactory.getLog(
|
||||||
|
MyBatisMapperFactoryBeanPostProcessor.class);
|
||||||
|
|
||||||
|
private static final String MAPPER_FACTORY_BEAN = "org.mybatis.spring.mapper.MapperFactoryBean";
|
||||||
|
|
||||||
|
private ConfigurableBeanFactory beanFactory;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBeanFactory(BeanFactory beanFactory) {
|
||||||
|
this.beanFactory = (ConfigurableBeanFactory) beanFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
|
||||||
|
if (ClassUtils.isPresent(MAPPER_FACTORY_BEAN, this.beanFactory.getBeanClassLoader())) {
|
||||||
|
resolveMapperFactoryBeanTypeIfNecessary(beanDefinition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resolveMapperFactoryBeanTypeIfNecessary(RootBeanDefinition beanDefinition) {
|
||||||
|
if (!beanDefinition.hasBeanClass() || !MapperFactoryBean.class.isAssignableFrom(beanDefinition.getBeanClass())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (beanDefinition.getResolvableType().hasUnresolvableGenerics()) {
|
||||||
|
Class<?> mapperInterface = getMapperInterface(beanDefinition);
|
||||||
|
if (mapperInterface != null) {
|
||||||
|
// Exposes a generic type information to context for prevent early initializing
|
||||||
|
beanDefinition
|
||||||
|
.setTargetType(ResolvableType.forClassWithGenerics(beanDefinition.getBeanClass(), mapperInterface));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Class<?> getMapperInterface(RootBeanDefinition beanDefinition) {
|
||||||
|
try {
|
||||||
|
return (Class<?>) beanDefinition.getPropertyValues().get("mapperInterface");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
LOG.debug("Fail getting mapper interface type.", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
package com.lion.sns.configuration;
|
package com.lion.sns.configuration;
|
||||||
|
|
||||||
import com.lion.sns.interceptor.Interceptor;
|
import com.lion.sns.interceptor.Interceptor;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
@ -10,9 +9,13 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class WebComponentConfiguration implements WebMvcConfigurer {
|
public class WebComponentConfiguration implements WebMvcConfigurer {
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
Interceptor interceptor;
|
Interceptor interceptor;
|
||||||
|
|
||||||
|
public WebComponentConfiguration(Interceptor interceptor){
|
||||||
|
this.interceptor = interceptor;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
public void addCorsMappings(CorsRegistry registry) {
|
||||||
registry.addMapping("/**")
|
registry.addMapping("/**")
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package com.lion.sns.configuration;
|
package com.lion.sns.configuration;
|
||||||
|
|
||||||
import com.lion.sns.service.WebSocketService;
|
import com.lion.sns.service.WebSocketService;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
import org.springframework.web.socket.config.annotation.EnableWebSocket;
|
||||||
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
|
||||||
@ -11,9 +10,12 @@ import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry
|
|||||||
@EnableWebSocket
|
@EnableWebSocket
|
||||||
public class WebsocketConfiguration implements WebSocketConfigurer {
|
public class WebsocketConfiguration implements WebSocketConfigurer {
|
||||||
|
|
||||||
@Resource
|
|
||||||
WebSocketService webSocketService;
|
WebSocketService webSocketService;
|
||||||
|
|
||||||
|
public WebsocketConfiguration(WebSocketService webSocketService){
|
||||||
|
this.webSocketService = webSocketService;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||||
registry.addHandler(webSocketService, "/ws/").setAllowedOrigins("*");
|
registry.addHandler(webSocketService, "/ws/").setAllowedOrigins("*");
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package com.lion.sns.controller;
|
|||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.lion.sns.service.FileService;
|
import com.lion.sns.service.FileService;
|
||||||
import com.lion.sns.util.Response;
|
import com.lion.sns.util.Response;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
@ -14,9 +13,14 @@ import java.util.Arrays;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/file/")
|
@RequestMapping("/file/")
|
||||||
public class FileController {
|
public class FileController {
|
||||||
@Resource
|
// @Resource
|
||||||
FileService fileService;
|
FileService fileService;
|
||||||
|
|
||||||
|
public FileController(FileService fileService) {
|
||||||
|
this.fileService = fileService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("get")
|
@GetMapping("get")
|
||||||
public String getFiles(String path, @SessionAttribute("id") Integer userid){
|
public String getFiles(String path, @SessionAttribute("id") Integer userid){
|
||||||
return fileService.getFiles(path, userid);
|
return fileService.getFiles(path, userid);
|
||||||
|
|||||||
@ -1,15 +1,18 @@
|
|||||||
package com.lion.sns.controller;
|
package com.lion.sns.controller;
|
||||||
|
|
||||||
import com.lion.sns.service.ShareService;
|
import com.lion.sns.service.ShareService;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/share/")
|
@RequestMapping("/share/")
|
||||||
public class ShareFileController {
|
public class ShareFileController {
|
||||||
@Resource
|
// @Resource
|
||||||
ShareService shareService;
|
ShareService shareService;
|
||||||
|
|
||||||
|
public ShareFileController(ShareService shareService) {
|
||||||
|
this.shareService = shareService;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("")
|
@PostMapping("")
|
||||||
public String shareFile(String path, Integer time, Integer count, String[] fileNames, @SessionAttribute("id") Integer userid){
|
public String shareFile(String path, Integer time, Integer count, String[] fileNames, @SessionAttribute("id") Integer userid){
|
||||||
return shareService.shareFile(path, time, count, fileNames, userid);
|
return shareService.shareFile(path, time, count, fileNames, userid);
|
||||||
|
|||||||
@ -2,7 +2,6 @@ package com.lion.sns.controller;
|
|||||||
|
|
||||||
import com.lion.sns.pojo.Site;
|
import com.lion.sns.pojo.Site;
|
||||||
import com.lion.sns.service.SiteService;
|
import com.lion.sns.service.SiteService;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -11,9 +10,13 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/manage/site/")
|
@RequestMapping("/manage/site/")
|
||||||
public class SiteManageController {
|
public class SiteManageController {
|
||||||
@Resource
|
// @Resource
|
||||||
SiteService siteService;
|
SiteService siteService;
|
||||||
|
|
||||||
|
public SiteManageController(SiteService siteService) {
|
||||||
|
this.siteService = siteService;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("alter")
|
@PostMapping("alter")
|
||||||
public String alterSite(Site site){
|
public String alterSite(Site site){
|
||||||
return siteService.alterSite(site);
|
return siteService.alterSite(site);
|
||||||
|
|||||||
@ -2,16 +2,19 @@ package com.lion.sns.controller;
|
|||||||
|
|
||||||
import com.lion.sns.pojo.User;
|
import com.lion.sns.pojo.User;
|
||||||
import com.lion.sns.service.UserService;
|
import com.lion.sns.service.UserService;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/manage/user/")
|
@RequestMapping("/manage/user/")
|
||||||
public class UserManageController {
|
public class UserManageController {
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
|
public UserManageController(UserService userService) {
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("create")
|
@PostMapping("create")
|
||||||
public String createUser(User user){
|
public String createUser(User user){
|
||||||
return userService.createUser(user);
|
return userService.createUser(user);
|
||||||
|
|||||||
@ -4,7 +4,6 @@ import com.lion.sns.pojo.User;
|
|||||||
import com.lion.sns.service.FileService;
|
import com.lion.sns.service.FileService;
|
||||||
import com.lion.sns.service.SiteService;
|
import com.lion.sns.service.SiteService;
|
||||||
import com.lion.sns.service.UserService;
|
import com.lion.sns.service.UserService;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
@ -14,21 +13,28 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.SessionAttribute;
|
import org.springframework.web.bind.annotation.SessionAttribute;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class indexController {
|
public class indexController {
|
||||||
@Resource
|
// @Resource
|
||||||
UserService userService;
|
UserService userService;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
SiteService siteService;
|
SiteService siteService;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
FileService fileService;
|
FileService fileService;
|
||||||
|
|
||||||
|
public indexController(UserService userService, SiteService siteService, FileService fileService){
|
||||||
|
this.userService = userService;
|
||||||
|
this.siteService = siteService;
|
||||||
|
this.fileService = fileService;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public String index(){
|
public void index(HttpServletResponse resp) throws IOException {
|
||||||
return "index";
|
resp.sendRedirect("/index");
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
|
|||||||
@ -9,13 +9,13 @@ import java.util.Date;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface SiteMapper {
|
public interface SiteMapper {
|
||||||
|
|
||||||
@Insert("insert into site (ip, domain, reverse_proxy_prefix, hostname, system, cpu_arch, cpu_name, cpu_core, cpu_thread, storage_path, available_space, total_space)" +
|
@Insert("insert into site (ip, domain, reverse_proxy_prefix, hostname, storage_path, available_space, total_space)" +
|
||||||
"VALUES (#{ip}, #{domain}, #{reverseProxyPrefix}, #{hostname}, #{system}, #{cpuArch}, #{cpuName}, #{cpuCore}, #{cpuThread}, #{storagePath}, #{availableSpace}, #{totalSpace})")
|
"VALUES (#{ip}, #{domain}, #{reverseProxyPrefix}, #{hostname}, #{storagePath}, #{availableSpace}, #{totalSpace})")
|
||||||
@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
|
@Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
|
||||||
void insertSite(Site site);
|
void insertSite(Site site);
|
||||||
|
|
||||||
@Update("update site set ip=#{ip}, domain=#{domain}, reverse_proxy_prefix=#{reverseProxyPrefix}, hostname=#{hostname}, system=#{system}, cpu_arch=#{cpuArch}," +
|
@Update("update site set ip=#{ip}, domain=#{domain}, reverse_proxy_prefix=#{reverseProxyPrefix}, hostname=#{hostname}," +
|
||||||
"cpu_name=#{cpuName}, cpu_core=#{cpuCore}, cpu_thread=#{cpuThread}, storage_path=#{storagePath}, available_space=#{availableSpace}, total_space=#{totalSpace} where id=#{id}")
|
"storage_path=#{storagePath}, available_space=#{availableSpace}, total_space=#{totalSpace} where id=#{id}")
|
||||||
void updateSite(Site site);
|
void updateSite(Site site);
|
||||||
|
|
||||||
@Update("update site set last_online=#{last_online} where id=#{id} and id != 1")
|
@Update("update site set last_online=#{last_online} where id=#{id} and id != 1")
|
||||||
|
|||||||
@ -9,7 +9,6 @@ public class AbstractMessage {
|
|||||||
|
|
||||||
public static final int FILE_QUERY_MESSAGE = 1;
|
public static final int FILE_QUERY_MESSAGE = 1;
|
||||||
public static final int FILE_RESPONSE_MESSAGE = 2;
|
public static final int FILE_RESPONSE_MESSAGE = 2;
|
||||||
public static final int STATUS_MESSAGE = 10;
|
|
||||||
public static final int MOVE_FILE_REQUEST_MESSAGE = 15;
|
public static final int MOVE_FILE_REQUEST_MESSAGE = 15;
|
||||||
public static final int MOVE_FILE_RESPONSE_MESSAGE = 16;
|
public static final int MOVE_FILE_RESPONSE_MESSAGE = 16;
|
||||||
public static final int PAIR_MESSAGE = 20;
|
public static final int PAIR_MESSAGE = 20;
|
||||||
|
|||||||
@ -30,7 +30,6 @@ public class MessageCodec extends ByteToMessageCodec<AbstractMessage> {
|
|||||||
abstractMessage = switch (type){
|
abstractMessage = switch (type){
|
||||||
case AbstractMessage.FILE_QUERY_MESSAGE -> objectMapper.readValue(bytes, FileQueryMessage.class);
|
case AbstractMessage.FILE_QUERY_MESSAGE -> objectMapper.readValue(bytes, FileQueryMessage.class);
|
||||||
case AbstractMessage.FILE_RESPONSE_MESSAGE -> objectMapper.readValue(bytes, FileResponseMessage.class);
|
case AbstractMessage.FILE_RESPONSE_MESSAGE -> objectMapper.readValue(bytes, FileResponseMessage.class);
|
||||||
case AbstractMessage.STATUS_MESSAGE -> objectMapper.readValue(bytes, StatusMessage.class);
|
|
||||||
case AbstractMessage.MOVE_FILE_REQUEST_MESSAGE -> objectMapper.readValue(bytes, MoveFileRequestMessage.class);
|
case AbstractMessage.MOVE_FILE_REQUEST_MESSAGE -> objectMapper.readValue(bytes, MoveFileRequestMessage.class);
|
||||||
case AbstractMessage.PAIR_MESSAGE -> objectMapper.readValue(bytes, PairMessage.class);
|
case AbstractMessage.PAIR_MESSAGE -> objectMapper.readValue(bytes, PairMessage.class);
|
||||||
case AbstractMessage.PAIR_RESULT_MESSAGE -> objectMapper.readValue(bytes, PairResultMessage.class);
|
case AbstractMessage.PAIR_RESULT_MESSAGE -> objectMapper.readValue(bytes, PairResultMessage.class);
|
||||||
|
|||||||
@ -11,11 +11,6 @@ public class PairMessage extends AbstractMessage{
|
|||||||
String domain;
|
String domain;
|
||||||
String reverseProxyPrefix;
|
String reverseProxyPrefix;
|
||||||
String hostname;
|
String hostname;
|
||||||
String system;
|
|
||||||
String cpuArch;
|
|
||||||
String cpuName;
|
|
||||||
int cpuCore;
|
|
||||||
int cpuThread;
|
|
||||||
String storagePath;
|
String storagePath;
|
||||||
long availableSpace;
|
long availableSpace;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
package com.lion.sns.message;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class StatusMessage extends AbstractMessage{
|
|
||||||
{
|
|
||||||
messageType = STATUS_MESSAGE;
|
|
||||||
}
|
|
||||||
int id;
|
|
||||||
long usedMemory;
|
|
||||||
long totalMemory;
|
|
||||||
double usedMemoryPercentage;
|
|
||||||
long usedSpace;
|
|
||||||
long totalSpace;
|
|
||||||
double usedSpacePercentage;
|
|
||||||
double[] systemLoad;
|
|
||||||
double usedCpuPercentage;
|
|
||||||
long ioRead;
|
|
||||||
long ioWrite;
|
|
||||||
long networkReceive;
|
|
||||||
long networkSend;
|
|
||||||
long systemUpTime;
|
|
||||||
long systemBootTime;
|
|
||||||
}
|
|
||||||
@ -5,8 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
import com.lion.sns.message.PairMessage;
|
import com.lion.sns.message.PairMessage;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
public class Site {
|
public class Site {
|
||||||
@ -17,11 +15,6 @@ public class Site {
|
|||||||
site.setDomain(pairMessage.getDomain());
|
site.setDomain(pairMessage.getDomain());
|
||||||
site.setReverseProxyPrefix(pairMessage.getReverseProxyPrefix());
|
site.setReverseProxyPrefix(pairMessage.getReverseProxyPrefix());
|
||||||
site.setHostname(pairMessage.getHostname());
|
site.setHostname(pairMessage.getHostname());
|
||||||
site.setSystem(pairMessage.getSystem());
|
|
||||||
site.setCpuArch(pairMessage.getCpuArch());
|
|
||||||
site.setCpuName(pairMessage.getCpuName());
|
|
||||||
site.setCpuCore(pairMessage.getCpuCore());
|
|
||||||
site.setCpuThread(pairMessage.getCpuThread());
|
|
||||||
site.setStoragePath(pairMessage.getStoragePath());
|
site.setStoragePath(pairMessage.getStoragePath());
|
||||||
return site;
|
return site;
|
||||||
}
|
}
|
||||||
@ -41,13 +34,6 @@ public class Site {
|
|||||||
String domain;
|
String domain;
|
||||||
String reverseProxyPrefix;
|
String reverseProxyPrefix;
|
||||||
String hostname;
|
String hostname;
|
||||||
String system;
|
|
||||||
String cpuArch;
|
|
||||||
String cpuName;
|
|
||||||
int cpuCore;
|
|
||||||
int cpuThread;
|
|
||||||
Date lastOnline;
|
|
||||||
boolean isOnline;
|
|
||||||
String storagePath;
|
String storagePath;
|
||||||
long totalSpace;
|
long totalSpace;
|
||||||
long availableSpace;
|
long availableSpace;
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import io.netty.channel.socket.nio.NioSocketChannel;
|
|||||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||||
import io.netty.util.concurrent.DefaultPromise;
|
import io.netty.util.concurrent.DefaultPromise;
|
||||||
import io.netty.util.concurrent.Promise;
|
import io.netty.util.concurrent.Promise;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -46,13 +45,12 @@ public class CommunicateService {
|
|||||||
|
|
||||||
SiteMapper siteMapper;
|
SiteMapper siteMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
TaskService taskService;
|
TaskService taskService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
CustomConfigurationMapper customConfigurationMapper;
|
CustomConfigurationMapper customConfigurationMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
UserMapper userMapper;
|
UserMapper userMapper;
|
||||||
|
|
||||||
HashMap<Integer, Channel> sessions;
|
HashMap<Integer, Channel> sessions;
|
||||||
@ -61,8 +59,6 @@ public class CommunicateService {
|
|||||||
|
|
||||||
HashMap<Integer, DefaultPromise<AbstractMessage>> promises;
|
HashMap<Integer, DefaultPromise<AbstractMessage>> promises;
|
||||||
|
|
||||||
HashMap<Integer, StatusMessage> loadInformation;
|
|
||||||
|
|
||||||
HashMap<Integer, User> userid2user;
|
HashMap<Integer, User> userid2user;
|
||||||
|
|
||||||
HashMap<Integer, HttpSession> userid2httpSession;
|
HashMap<Integer, HttpSession> userid2httpSession;
|
||||||
@ -78,14 +74,15 @@ public class CommunicateService {
|
|||||||
Interceptor interceptor;
|
Interceptor interceptor;
|
||||||
|
|
||||||
public CommunicateService(WebSocketService webSocketService, CustomConfigurationMapper customConfigurationMapper, SiteMapper siteMapper,
|
public CommunicateService(WebSocketService webSocketService, CustomConfigurationMapper customConfigurationMapper, SiteMapper siteMapper,
|
||||||
Interceptor interceptor){
|
Interceptor interceptor, TaskService taskService, UserMapper userMapper){
|
||||||
|
this.userMapper = userMapper;
|
||||||
|
this.taskService = taskService;
|
||||||
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
||||||
this.customConfigurationMapper = customConfigurationMapper;
|
this.customConfigurationMapper = customConfigurationMapper;
|
||||||
this.interceptor = interceptor;
|
this.interceptor = interceptor;
|
||||||
threadPool = Executors.newFixedThreadPool(2);
|
threadPool = Executors.newFixedThreadPool(2);
|
||||||
messageId = new AtomicInteger();
|
messageId = new AtomicInteger();
|
||||||
eventLoop = new DefaultEventLoop();
|
eventLoop = new DefaultEventLoop();
|
||||||
loadInformation = new HashMap<>();
|
|
||||||
sessions = new HashMap<>();
|
sessions = new HashMap<>();
|
||||||
userid2user = new HashMap<>();
|
userid2user = new HashMap<>();
|
||||||
userid2httpSession = new HashMap<>();
|
userid2httpSession = new HashMap<>();
|
||||||
@ -103,7 +100,7 @@ public class CommunicateService {
|
|||||||
}}).bind(7777);
|
}}).bind(7777);
|
||||||
this.webSocketService = webSocketService;
|
this.webSocketService = webSocketService;
|
||||||
this.siteMapper = siteMapper;
|
this.siteMapper = siteMapper;
|
||||||
webSocketService.initScheduleThread(loadInformation);
|
webSocketService.initScheduleThread();
|
||||||
|
|
||||||
webSocketService.logoutFunction = (Function<Integer, Object>) userid -> {
|
webSocketService.logoutFunction = (Function<Integer, Object>) userid -> {
|
||||||
User logoutUser = this.userid2user.remove(userid);
|
User logoutUser = this.userid2user.remove(userid);
|
||||||
@ -327,12 +324,6 @@ public class CommunicateService {
|
|||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||||
AbstractMessage abstractMessage = (AbstractMessage) msg;
|
AbstractMessage abstractMessage = (AbstractMessage) msg;
|
||||||
switch (abstractMessage.messageType){
|
switch (abstractMessage.messageType){
|
||||||
case AbstractMessage.STATUS_MESSAGE -> {
|
|
||||||
StatusMessage statusMessage = (StatusMessage) abstractMessage;
|
|
||||||
statusMessage.setMessageType(0);
|
|
||||||
statusMessage.setMessageId(0);
|
|
||||||
loadInformation.put(statusMessage.getId(), statusMessage);
|
|
||||||
}
|
|
||||||
case AbstractMessage.TASK_STATUS_MESSAGE -> {
|
case AbstractMessage.TASK_STATUS_MESSAGE -> {
|
||||||
TaskStatusMessage taskStatusMessage = (TaskStatusMessage) abstractMessage;
|
TaskStatusMessage taskStatusMessage = (TaskStatusMessage) abstractMessage;
|
||||||
for (Task task : taskStatusMessage.getTasks()) {
|
for (Task task : taskStatusMessage.getTasks()) {
|
||||||
|
|||||||
@ -13,11 +13,9 @@ import com.lion.sns.util.CustomUtil;
|
|||||||
import com.lion.sns.util.IoUtil;
|
import com.lion.sns.util.IoUtil;
|
||||||
import com.lion.sns.util.Response;
|
import com.lion.sns.util.Response;
|
||||||
import io.netty.util.concurrent.DefaultPromise;
|
import io.netty.util.concurrent.DefaultPromise;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.compress.archivers.ArchiveEntry;
|
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -44,19 +42,19 @@ import java.util.zip.CRC32;
|
|||||||
public class FileService {
|
public class FileService {
|
||||||
|
|
||||||
String storagePath;
|
String storagePath;
|
||||||
@Resource
|
// @Resource
|
||||||
CommunicateService communicateService;
|
CommunicateService communicateService;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
WebSocketService webSocketService;
|
WebSocketService webSocketService;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
TaskService taskService;
|
TaskService taskService;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
ShareFileMapper shareFileMapper;
|
ShareFileMapper shareFileMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
UserMapper userMapper;
|
UserMapper userMapper;
|
||||||
|
|
||||||
ObjectMapper objectMapper;
|
ObjectMapper objectMapper;
|
||||||
@ -67,7 +65,13 @@ public class FileService {
|
|||||||
|
|
||||||
HashMap<String, FileNode> shareFileNodes;
|
HashMap<String, FileNode> shareFileNodes;
|
||||||
|
|
||||||
public FileService(CustomConfigurationMapper customConfigurationMapper){
|
public FileService(CustomConfigurationMapper customConfigurationMapper, CommunicateService communicateService, WebSocketService webSocketService,
|
||||||
|
TaskService taskService, ShareFileMapper shareFileMapper, UserMapper userMapper){
|
||||||
|
this.communicateService = communicateService;
|
||||||
|
this.webSocketService = webSocketService;
|
||||||
|
this.taskService = taskService;
|
||||||
|
this.shareFileMapper = shareFileMapper;
|
||||||
|
this.userMapper = userMapper;
|
||||||
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
||||||
threadPool = Executors.newFixedThreadPool(4);
|
threadPool = Executors.newFixedThreadPool(4);
|
||||||
ipAndShareCode = new HashMap<>();
|
ipAndShareCode = new HashMap<>();
|
||||||
@ -877,7 +881,7 @@ public class FileService {
|
|||||||
for (String path : task.getPaths()) {
|
for (String path : task.getPaths()) {
|
||||||
File file = new File(storagePath + task.getRelativePath(), path);
|
File file = new File(storagePath + task.getRelativePath(), path);
|
||||||
if(file.isFile()){
|
if(file.isFile()){
|
||||||
ArchiveEntry entry = new TarArchiveEntry(file, finalPath.relativize(file.toPath()).toString());
|
TarArchiveEntry entry = new TarArchiveEntry(file, finalPath.relativize(file.toPath()).toString());
|
||||||
aos.putArchiveEntry(entry);
|
aos.putArchiveEntry(entry);
|
||||||
InputStream inputStream = Files.newInputStream(file.toPath());
|
InputStream inputStream = Files.newInputStream(file.toPath());
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
@ -893,7 +897,7 @@ public class FileService {
|
|||||||
Files.walkFileTree(file.toPath(), new SimpleFileVisitor<>() {
|
Files.walkFileTree(file.toPath(), new SimpleFileVisitor<>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
|
||||||
ArchiveEntry entry = new TarArchiveEntry(dir.toFile(), finalPath.relativize(dir).toString());
|
TarArchiveEntry entry = new TarArchiveEntry(dir.toFile(), finalPath.relativize(dir).toString());
|
||||||
aos.putArchiveEntry(entry);
|
aos.putArchiveEntry(entry);
|
||||||
aos.closeArchiveEntry();
|
aos.closeArchiveEntry();
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
@ -901,7 +905,7 @@ public class FileService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
ArchiveEntry entry = new TarArchiveEntry(file.toFile(), finalPath.relativize(file).toString());
|
TarArchiveEntry entry = new TarArchiveEntry(file.toFile(), finalPath.relativize(file).toString());
|
||||||
aos.putArchiveEntry(entry);
|
aos.putArchiveEntry(entry);
|
||||||
InputStream inputStream = Files.newInputStream(file.toFile().toPath());
|
InputStream inputStream = Files.newInputStream(file.toFile().toPath());
|
||||||
byte[] buf = new byte[8192];
|
byte[] buf = new byte[8192];
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import com.lion.sns.pojo.ShareFile;
|
|||||||
import com.lion.sns.pojo.User;
|
import com.lion.sns.pojo.User;
|
||||||
import com.lion.sns.util.CustomUtil;
|
import com.lion.sns.util.CustomUtil;
|
||||||
import com.lion.sns.util.Response;
|
import com.lion.sns.util.Response;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -20,21 +19,25 @@ import java.util.*;
|
|||||||
@Service
|
@Service
|
||||||
public class ShareService {
|
public class ShareService {
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
ShareFileMapper shareFileMapper;
|
ShareFileMapper shareFileMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
CommunicateService communicateService;
|
CommunicateService communicateService;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
UserMapper userMapper;
|
UserMapper userMapper;
|
||||||
|
|
||||||
String storagePath;
|
String storagePath;
|
||||||
|
|
||||||
ObjectMapper objectMapper;
|
ObjectMapper objectMapper;
|
||||||
public ShareService(CustomConfigurationMapper customConfigurationMapper){
|
public ShareService(CustomConfigurationMapper customConfigurationMapper, ShareFileMapper shareFileMapper,
|
||||||
|
CommunicateService communicateService, UserMapper userMapper){
|
||||||
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
||||||
objectMapper = CustomUtil.objectMapper;
|
objectMapper = CustomUtil.objectMapper;
|
||||||
|
this.communicateService = communicateService;
|
||||||
|
this.shareFileMapper = shareFileMapper;
|
||||||
|
this.userMapper = userMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String shareFile(String path, Integer time, Integer count, String[] fileNames, int userid){
|
public String shareFile(String path, Integer time, Integer count, String[] fileNames, int userid){
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import com.lion.sns.pojo.Site;
|
|||||||
import com.lion.sns.pojo.User;
|
import com.lion.sns.pojo.User;
|
||||||
import com.lion.sns.util.CustomUtil;
|
import com.lion.sns.util.CustomUtil;
|
||||||
import com.lion.sns.util.Response;
|
import com.lion.sns.util.Response;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -23,25 +22,31 @@ import java.io.IOException;
|
|||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SiteService {
|
public class SiteService {
|
||||||
@Resource
|
// @Resource
|
||||||
SiteMapper siteMapper;
|
SiteMapper siteMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
ShareFileMapper shareFileMapper;
|
ShareFileMapper shareFileMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
CommunicateService communicateService;
|
CommunicateService communicateService;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
CustomConfigurationMapper customConfigurationMapper;
|
CustomConfigurationMapper customConfigurationMapper;
|
||||||
|
|
||||||
ObjectMapper objectMapper = CustomUtil.objectMapper;
|
ObjectMapper objectMapper = CustomUtil.objectMapper;
|
||||||
|
|
||||||
|
public SiteService(SiteMapper siteMapper, ShareFileMapper shareFileMapper, CommunicateService communicateService, CustomConfigurationMapper customConfigurationMapper) {
|
||||||
|
this.siteMapper = siteMapper;
|
||||||
|
this.shareFileMapper = shareFileMapper;
|
||||||
|
this.communicateService = communicateService;
|
||||||
|
this.customConfigurationMapper = customConfigurationMapper;
|
||||||
|
}
|
||||||
|
|
||||||
public String alterSite(Site site){
|
public String alterSite(Site site){
|
||||||
Response response = new Response();
|
Response response = new Response();
|
||||||
|
|
||||||
@ -154,10 +159,6 @@ public class SiteService {
|
|||||||
public String getSites() {
|
public String getSites() {
|
||||||
Response response = new Response();
|
Response response = new Response();
|
||||||
ArrayList<Site> sites = siteMapper.selectAllSite();
|
ArrayList<Site> sites = siteMapper.selectAllSite();
|
||||||
HashMap<Integer, String> ips = communicateService.ips;
|
|
||||||
for (Site site : sites)
|
|
||||||
if(ips.containsKey(site.getId()))
|
|
||||||
site.setOnline(true);
|
|
||||||
|
|
||||||
response.success(objectMapper.valueToTree(sites));
|
response.success(objectMapper.valueToTree(sites));
|
||||||
return response.toJSONString();
|
return response.toJSONString();
|
||||||
@ -168,21 +169,14 @@ public class SiteService {
|
|||||||
User user = communicateService.userid2user.get(userid);
|
User user = communicateService.userid2user.get(userid);
|
||||||
ArrayList<Site> sites = siteMapper.selectAllSite();
|
ArrayList<Site> sites = siteMapper.selectAllSite();
|
||||||
ArrayList<Site> result = new ArrayList<>();
|
ArrayList<Site> result = new ArrayList<>();
|
||||||
HashMap<Integer, String> ips = communicateService.ips;
|
if(user.getId() != 1) {
|
||||||
if(user.getId() != 1)
|
for (Site site : sites)
|
||||||
for (Site site : sites) {
|
if (user.getSiteId() == site.getId()) {
|
||||||
if(user.getSiteId() == site.getId()) {
|
|
||||||
result.add(site);
|
result.add(site);
|
||||||
if (ips.containsKey(site.getId()))
|
break;
|
||||||
site.setOnline(true);
|
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
result.addAll(sites);
|
||||||
for (Site site : sites) {
|
|
||||||
if (ips.containsKey(site.getId()))
|
|
||||||
site.setOnline(true);
|
|
||||||
result.add(site);
|
|
||||||
}
|
|
||||||
|
|
||||||
response.success(objectMapper.valueToTree(result));
|
response.success(objectMapper.valueToTree(result));
|
||||||
return response.toJSONString();
|
return response.toJSONString();
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import com.lion.sns.pojo.Site;
|
|||||||
import com.lion.sns.pojo.User;
|
import com.lion.sns.pojo.User;
|
||||||
import com.lion.sns.util.CustomUtil;
|
import com.lion.sns.util.CustomUtil;
|
||||||
import com.lion.sns.util.Response;
|
import com.lion.sns.util.Response;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -24,26 +23,32 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class UserService {
|
public class UserService {
|
||||||
@Resource
|
// @Resource
|
||||||
UserMapper userMapper;
|
UserMapper userMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
SiteMapper siteMapper;
|
SiteMapper siteMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
CommunicateService communicateService;
|
CommunicateService communicateService;
|
||||||
|
|
||||||
CustomConfigurationMapper customConfigurationMapper;
|
CustomConfigurationMapper customConfigurationMapper;
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
ShareFileMapper shareFileMapper;
|
ShareFileMapper shareFileMapper;
|
||||||
|
|
||||||
ObjectMapper objectMapper = CustomUtil.objectMapper;
|
ObjectMapper objectMapper = CustomUtil.objectMapper;
|
||||||
|
|
||||||
String storagePath;
|
String storagePath;
|
||||||
|
|
||||||
public UserService(CustomConfigurationMapper customConfigurationMapper){
|
public UserService(CustomConfigurationMapper customConfigurationMapper, UserMapper userMapper,
|
||||||
|
SiteMapper siteMapper, CommunicateService communicateService, ShareFileMapper shareFileMapper
|
||||||
|
){
|
||||||
this.customConfigurationMapper = customConfigurationMapper;
|
this.customConfigurationMapper = customConfigurationMapper;
|
||||||
|
this.userMapper = userMapper;
|
||||||
|
this.siteMapper = siteMapper;
|
||||||
|
this.shareFileMapper = shareFileMapper;
|
||||||
|
this.communicateService = communicateService;
|
||||||
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,17 +6,14 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||||||
import com.lion.sns.dao.CustomConfigurationMapper;
|
import com.lion.sns.dao.CustomConfigurationMapper;
|
||||||
import com.lion.sns.dao.UserMapper;
|
import com.lion.sns.dao.UserMapper;
|
||||||
import com.lion.sns.message.AbstractMessage;
|
import com.lion.sns.message.AbstractMessage;
|
||||||
import com.lion.sns.message.StatusMessage;
|
|
||||||
import com.lion.sns.message.PairMessage;
|
import com.lion.sns.message.PairMessage;
|
||||||
import com.lion.sns.message.ResponseMessage;
|
import com.lion.sns.message.ResponseMessage;
|
||||||
import com.lion.sns.pojo.Task;
|
import com.lion.sns.pojo.Task;
|
||||||
|
|
||||||
import com.lion.sns.pojo.User;
|
import com.lion.sns.pojo.User;
|
||||||
import com.lion.sns.util.CustomUtil;
|
import com.lion.sns.util.CustomUtil;
|
||||||
import com.lion.sns.util.IoUtil;
|
|
||||||
import io.netty.util.concurrent.DefaultPromise;
|
import io.netty.util.concurrent.DefaultPromise;
|
||||||
import io.netty.util.concurrent.Promise;
|
import io.netty.util.concurrent.Promise;
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.socket.*;
|
import org.springframework.web.socket.*;
|
||||||
@ -42,7 +39,7 @@ public class WebSocketService implements WebSocketHandler {
|
|||||||
* 进度发给发起的那个session
|
* 进度发给发起的那个session
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Resource
|
// @Resource
|
||||||
UserMapper userMapper;
|
UserMapper userMapper;
|
||||||
|
|
||||||
HashMap<Integer, Task> tasks;
|
HashMap<Integer, Task> tasks;
|
||||||
@ -61,13 +58,12 @@ public class WebSocketService implements WebSocketHandler {
|
|||||||
|
|
||||||
public final Map<Integer, Promise<AbstractMessage>> pairMessages;
|
public final Map<Integer, Promise<AbstractMessage>> pairMessages;
|
||||||
|
|
||||||
private Map<Integer, StatusMessage> loadMap;
|
|
||||||
|
|
||||||
private final ScheduledExecutorService scheduledThread;
|
private final ScheduledExecutorService scheduledThread;
|
||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
public WebSocketService(CustomConfigurationMapper customConfigurationMapper) {
|
public WebSocketService(CustomConfigurationMapper customConfigurationMapper, UserMapper userMapper) {
|
||||||
this.customConfigurationMapper = customConfigurationMapper;
|
this.customConfigurationMapper = customConfigurationMapper;
|
||||||
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
storagePath = customConfigurationMapper.selectValue(CustomConfigurationMapper.PATH);
|
||||||
objectMapper = CustomUtil.objectMapper;
|
objectMapper = CustomUtil.objectMapper;
|
||||||
@ -76,6 +72,7 @@ public class WebSocketService implements WebSocketHandler {
|
|||||||
scheduledThread = Executors.newScheduledThreadPool(1);
|
scheduledThread = Executors.newScheduledThreadPool(1);
|
||||||
userid2session = new HashMap<>();
|
userid2session = new HashMap<>();
|
||||||
onlineUsers = new HashMap<>();
|
onlineUsers = new HashMap<>();
|
||||||
|
this.userMapper = userMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -176,41 +173,6 @@ public class WebSocketService implements WebSocketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendLoadInformation(){
|
|
||||||
//两种状态:1.管理员看全部状态 2.用户看自己所绑定的服务器状态
|
|
||||||
if(session == null && onlineUsers.isEmpty())
|
|
||||||
return;
|
|
||||||
loadMap.put(1, IoUtil.generateLoadMessage(1, storagePath));
|
|
||||||
|
|
||||||
ObjectNode totalStatus = objectMapper.createObjectNode();
|
|
||||||
HashMap<Integer, ObjectNode> userid2status = new HashMap<>();
|
|
||||||
totalStatus.set("1", objectMapper.valueToTree(loadMap.get(1)));
|
|
||||||
totalStatus.put("type", MESSAGE_TYPE.STATUS);
|
|
||||||
|
|
||||||
loadMap.forEach((k, v) -> totalStatus.set(String.valueOf(k), objectMapper.valueToTree(v)));
|
|
||||||
for (User user : onlineUsers.values()) {
|
|
||||||
if(loadMap.containsKey(user.getSiteId())) {
|
|
||||||
ObjectNode status = objectMapper.createObjectNode();
|
|
||||||
status.put("type", MESSAGE_TYPE.STATUS);
|
|
||||||
status.set("1", objectMapper.valueToTree(loadMap.get(user.getSiteId())));
|
|
||||||
userid2status.put(user.getId(), status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if(session != null && session.isOpen())
|
|
||||||
session.sendMessage(new TextMessage(totalStatus.toString()));
|
|
||||||
|
|
||||||
userid2session.forEach((k, v) -> {
|
|
||||||
if(k != 1 && v != null && v.isOpen()){
|
|
||||||
try {
|
|
||||||
v.sendMessage(new TextMessage(userid2status.get(k).toString()));
|
|
||||||
} catch (IOException e) {log.error(e.getMessage());}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}catch (IOException e){log.error(e.getMessage());}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendTaskInformation(){
|
public void sendTaskInformation(){
|
||||||
if(tasks.isEmpty() || (session == null && onlineUsers.isEmpty()))
|
if(tasks.isEmpty() || (session == null && onlineUsers.isEmpty()))
|
||||||
return;
|
return;
|
||||||
@ -240,11 +202,9 @@ public class WebSocketService implements WebSocketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initScheduleThread(HashMap<Integer, StatusMessage> loadMap){
|
public void initScheduleThread(){
|
||||||
this.loadMap = loadMap;
|
|
||||||
scheduledThread.scheduleAtFixedRate(() -> {
|
scheduledThread.scheduleAtFixedRate(() -> {
|
||||||
try {
|
try {
|
||||||
sendLoadInformation();
|
|
||||||
sendTaskInformation();
|
sendTaskInformation();
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -285,7 +245,6 @@ public class WebSocketService implements WebSocketHandler {
|
|||||||
static class MESSAGE_TYPE{
|
static class MESSAGE_TYPE{
|
||||||
final static String PAIR = "pair";
|
final static String PAIR = "pair";
|
||||||
final static String INIT = "init";
|
final static String INIT = "init";
|
||||||
final static String STATUS = "status";
|
|
||||||
final static String STATUS_ALTER = "statusAlter";
|
final static String STATUS_ALTER = "statusAlter";
|
||||||
final static String TASK = "task";
|
final static String TASK = "task";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import java.nio.file.SimpleFileVisitor;
|
|||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
@ -171,7 +170,6 @@ public class CustomUtil {
|
|||||||
}
|
}
|
||||||
Site site = Site.generateSite(IoUtil.generatePairMessage());
|
Site site = Site.generateSite(IoUtil.generatePairMessage());
|
||||||
site.setId(1);
|
site.setId(1);
|
||||||
site.setLastOnline(new Date());
|
|
||||||
site.setStoragePath(path);
|
site.setStoragePath(path);
|
||||||
site.setDomain(null);
|
site.setDomain(null);
|
||||||
site.setReverseProxyPrefix(null);
|
site.setReverseProxyPrefix(null);
|
||||||
|
|||||||
@ -3,126 +3,53 @@ package com.lion.sns.util;
|
|||||||
import cn.hutool.core.net.NetUtil;
|
import cn.hutool.core.net.NetUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.core.util.URLUtil;
|
import cn.hutool.core.util.URLUtil;
|
||||||
import cn.hutool.system.oshi.CpuInfo;
|
|
||||||
import cn.hutool.system.oshi.OshiUtil;
|
|
||||||
import com.lion.sns.message.StatusMessage;
|
|
||||||
import com.lion.sns.message.PairMessage;
|
import com.lion.sns.message.PairMessage;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.catalina.connector.ClientAbortException;
|
import org.apache.catalina.connector.ClientAbortException;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import oshi.hardware.*;
|
|
||||||
import oshi.software.os.OperatingSystem;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Data
|
@Data
|
||||||
public class IoUtil {
|
public class IoUtil {
|
||||||
static long ioRead;
|
|
||||||
static long ioWrite;
|
|
||||||
static long networkSend;
|
|
||||||
static long networkReceive;
|
|
||||||
static NetworkIF networkIF;
|
|
||||||
static List<HWDiskStore> diskStores;
|
|
||||||
static CpuInfo cpuInfo;
|
|
||||||
static GlobalMemory globalMemory;
|
|
||||||
|
|
||||||
static long send;
|
@Getter
|
||||||
static long sendNow;
|
static String ip;
|
||||||
static long receive;
|
|
||||||
static long receiveNow;
|
|
||||||
|
|
||||||
static long read;
|
|
||||||
static long readNow;
|
|
||||||
static long write;
|
|
||||||
static long writeNow;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(){
|
public static void init(){
|
||||||
ScheduledExecutorService thread = Executors.newScheduledThreadPool(1);
|
try {
|
||||||
List<NetworkIF> networkIFs = OshiUtil.getNetworkIFs();
|
ip = getPublicIP();
|
||||||
cpuInfo = OshiUtil.getCpuInfo();
|
}catch (IOException | URISyntaxException e){
|
||||||
globalMemory = OshiUtil.getMemory();
|
log.info("当前机器网卡为内网ip且无法获取公网ip,程序退出");
|
||||||
|
Runtime.getRuntime().exit(1);
|
||||||
for (NetworkIF nif : networkIFs)
|
|
||||||
if (nif.getName().startsWith("eth") || nif.getName().startsWith("ens")) {
|
|
||||||
networkIF = nif;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(networkIF == null)
|
|
||||||
log.error("网卡 不存在");
|
|
||||||
else{
|
|
||||||
send = networkIF.getBytesSent();
|
|
||||||
receive = networkIF.getBytesRecv();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
diskStores = OshiUtil.getDiskStores();
|
|
||||||
for (HWDiskStore diskStore : diskStores) {
|
|
||||||
read += diskStore.getReadBytes();
|
|
||||||
write += diskStore.getWriteBytes();
|
|
||||||
}
|
|
||||||
thread.scheduleAtFixedRate(IoUtil::monitor, 0, 1, TimeUnit.SECONDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void monitor(){
|
|
||||||
networkIF.updateAttributes();
|
|
||||||
sendNow = networkIF.getBytesSent();
|
|
||||||
receiveNow = networkIF.getBytesRecv();
|
|
||||||
networkSend = sendNow - send;
|
|
||||||
networkReceive = receiveNow - receive;
|
|
||||||
send = sendNow;
|
|
||||||
receive = receiveNow;
|
|
||||||
|
|
||||||
writeNow = 0;
|
|
||||||
readNow = 0;
|
|
||||||
for (HWDiskStore diskStore : diskStores) {
|
|
||||||
diskStore.updateAttributes();
|
|
||||||
writeNow += diskStore.getWriteBytes();
|
|
||||||
readNow += diskStore.getReadBytes();
|
|
||||||
}
|
|
||||||
ioWrite = writeNow - write;
|
|
||||||
ioRead = readNow - read;
|
|
||||||
write = writeNow;
|
|
||||||
read = readNow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PairMessage generatePairMessage(){
|
public static PairMessage generatePairMessage(){
|
||||||
PairMessage pairMessage = new PairMessage();
|
PairMessage pairMessage = new PairMessage();
|
||||||
String ip = networkIF.getIPv4addr()[0].split("/")[0];
|
String ip;
|
||||||
String privateIPPattern = "(^10\\.)|(^172\\.1[6-9]\\.)|(^172\\.2[0-9]\\.)|(^172\\.3[0-1]\\.)|(^192\\.168\\.)";
|
try {
|
||||||
if(Pattern.compile(privateIPPattern).matcher(ip).find())
|
ip = getPublicIP();
|
||||||
try {
|
}catch (IOException | URISyntaxException e){
|
||||||
ip = getPublicIP();
|
log.info("当前机器网卡为内网ip且无法获取公网ip,程序退出");
|
||||||
}catch (IOException | URISyntaxException e){
|
Runtime.getRuntime().exit(1);
|
||||||
log.info("当前机器网卡为内网ip且无法获取公网ip,程序退出");
|
return null;
|
||||||
Runtime.getRuntime().exit(1);
|
}
|
||||||
}
|
|
||||||
pairMessage.setIp(ip);
|
pairMessage.setIp(ip);
|
||||||
pairMessage.setHostname(NetUtil.getLocalHostName());
|
pairMessage.setHostname(NetUtil.getLocalHostName());
|
||||||
|
|
||||||
OperatingSystem os = OshiUtil.getOs();
|
|
||||||
pairMessage.setSystem(os.getFamily() + " " + os.getVersionInfo().toString());
|
|
||||||
pairMessage.setCpuArch(System.getProperty("os.arch"));
|
|
||||||
|
|
||||||
CentralProcessor processor = OshiUtil.getHardware().getProcessor();
|
|
||||||
pairMessage.setCpuName(processor.getProcessorIdentifier().getName().strip());
|
|
||||||
pairMessage.setCpuCore(processor.getPhysicalProcessorCount());
|
|
||||||
pairMessage.setCpuThread(processor.getLogicalProcessorCount());
|
|
||||||
return pairMessage;
|
return pairMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,48 +72,6 @@ public class IoUtil {
|
|||||||
return json.substring(startIndex + 1, endIndex);
|
return json.substring(startIndex + 1, endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StatusMessage generateLoadMessage(int id, String path){
|
|
||||||
StatusMessage statusMessage = new StatusMessage();
|
|
||||||
statusMessage.setId(id);
|
|
||||||
|
|
||||||
statusMessage.setTotalMemory(globalMemory.getTotal());
|
|
||||||
statusMessage.setUsedMemory(globalMemory.getTotal() - globalMemory.getAvailable());
|
|
||||||
statusMessage.setUsedMemoryPercentage(numberFormat((double) statusMessage.getUsedMemory() / statusMessage.getTotalMemory()));
|
|
||||||
|
|
||||||
File file = new File(path);
|
|
||||||
statusMessage.setTotalSpace(file.getTotalSpace());
|
|
||||||
statusMessage.setUsedSpace(file.getTotalSpace() - file.getFreeSpace());
|
|
||||||
statusMessage.setUsedSpacePercentage(numberFormat((double) statusMessage.getUsedSpace() / statusMessage.getTotalSpace()));
|
|
||||||
|
|
||||||
statusMessage.setSystemLoad(OshiUtil.getHardware().getProcessor().getSystemLoadAverage(3));
|
|
||||||
statusMessage.setUsedCpuPercentage(numberFormat(100 - OshiUtil.getCpuInfo().getFree()));
|
|
||||||
|
|
||||||
statusMessage.setIoRead(ioRead);
|
|
||||||
statusMessage.setIoWrite(ioWrite);
|
|
||||||
statusMessage.setNetworkReceive(networkReceive);
|
|
||||||
statusMessage.setNetworkSend(networkSend);
|
|
||||||
|
|
||||||
statusMessage.setSystemUpTime(OshiUtil.getOs().getSystemUptime());
|
|
||||||
statusMessage.setSystemBootTime(OshiUtil.getOs().getSystemBootTime());
|
|
||||||
|
|
||||||
statusMessage.setMessageId(0);
|
|
||||||
statusMessage.setMessageType(0);
|
|
||||||
return statusMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static double numberFormat(double number){
|
|
||||||
if(number <= 0)
|
|
||||||
return number;
|
|
||||||
if(number < 1)
|
|
||||||
return Double.parseDouble(String.format("%.1f", number * 100));
|
|
||||||
else
|
|
||||||
return Double.parseDouble(String.format("%.1f", number));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getIp(){
|
|
||||||
return networkIF.getIPv4addr()[0].split("/")[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void export(HttpServletRequest request, HttpServletResponse response, String path) {
|
public static void export(HttpServletRequest request, HttpServletResponse response, String path) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
||||||
|
Before Width: | Height: | Size: 1.5 KiB |
@ -1,18 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>SNS</title>
|
|
||||||
<script type="module" crossorigin src="/index.js"></script>
|
|
||||||
<link rel="stylesheet" href="/index.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="dom"></div>
|
|
||||||
<div id="app">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Loading…
Reference in New Issue
Block a user