Commit fe6c067ab9c7b724c06181b70554cb7c9a7e28bf

Authored by 杜云山
1 parent 75092d17
Exists in develop

完成 AeroflexVirtualBox

Showing 33 changed files with 512 additions and 877 deletions   Show diff stats
@@ -5,21 +5,34 @@ @@ -5,21 +5,34 @@
5 <parent> 5 <parent>
6 <groupId>org.springframework.boot</groupId> 6 <groupId>org.springframework.boot</groupId>
7 <artifactId>spring-boot-starter-parent</artifactId> 7 <artifactId>spring-boot-starter-parent</artifactId>
8 - <version>2.2.11.RELEASE</version> 8 + <version>2.4.3</version>
9 <relativePath/> <!-- lookup parent from repository --> 9 <relativePath/> <!-- lookup parent from repository -->
10 </parent> 10 </parent>
11 - <groupId>com.example</groupId>  
12 - <artifactId>demo</artifactId> 11 + <groupId>com.peony</groupId>
  12 + <artifactId>virtual-box</artifactId>
13 <version>0.0.1-SNAPSHOT</version> 13 <version>0.0.1-SNAPSHOT</version>
14 <name>mina</name> 14 <name>mina</name>
15 - <description>Demo project for Spring Boot</description> 15 +
16 <properties> 16 <properties>
17 <java.version>1.8</java.version> 17 <java.version>1.8</java.version>
18 </properties> 18 </properties>
  19 +
19 <dependencies> 20 <dependencies>
  21 +
20 <dependency> 22 <dependency>
21 <groupId>org.springframework.boot</groupId> 23 <groupId>org.springframework.boot</groupId>
22 - <artifactId>spring-boot-starter-web</artifactId> 24 + <artifactId>spring-boot-starter</artifactId>
  25 + </dependency>
  26 +
  27 + <dependency>
  28 + <groupId>org.springframework.boot</groupId>
  29 + <artifactId>spring-boot-configuration-processor</artifactId>
  30 + </dependency>
  31 +
  32 + <dependency>
  33 + <groupId>org.apache.mina</groupId>
  34 + <artifactId>mina-core</artifactId>
  35 + <version>2.1.4</version>
23 </dependency> 36 </dependency>
24 37
25 <dependency> 38 <dependency>
@@ -28,11 +41,14 @@ @@ -28,11 +41,14 @@
28 <scope>runtime</scope> 41 <scope>runtime</scope>
29 <optional>true</optional> 42 <optional>true</optional>
30 </dependency> 43 </dependency>
  44 +
31 <dependency> 45 <dependency>
32 <groupId>org.projectlombok</groupId> 46 <groupId>org.projectlombok</groupId>
33 <artifactId>lombok</artifactId> 47 <artifactId>lombok</artifactId>
  48 + <scope>provided</scope>
34 <optional>true</optional> 49 <optional>true</optional>
35 </dependency> 50 </dependency>
  51 +
36 <dependency> 52 <dependency>
37 <groupId>org.springframework.boot</groupId> 53 <groupId>org.springframework.boot</groupId>
38 <artifactId>spring-boot-starter-test</artifactId> 54 <artifactId>spring-boot-starter-test</artifactId>
@@ -44,42 +60,6 @@ @@ -44,42 +60,6 @@
44 </exclusion> 60 </exclusion>
45 </exclusions> 61 </exclusions>
46 </dependency> 62 </dependency>
47 - <!--导入模板引擎才能实现页面跳转-->  
48 - <dependency>  
49 - <groupId>org.springframework.boot</groupId>  
50 - <artifactId>spring-boot-starter-thymeleaf</artifactId>  
51 - </dependency>  
52 - <!--springbootSecurity-->  
53 - <dependency>  
54 - <groupId>org.springframework.boot</groupId>  
55 - <artifactId>spring-boot-starter-security</artifactId>  
56 - </dependency>  
57 -  
58 - <!--rabbitmq-->  
59 - <dependency>  
60 - <groupId>org.springframework.boot</groupId>  
61 - <artifactId>spring-boot-starter-amqp</artifactId>  
62 - </dependency>  
63 -  
64 - <!--spring-statemachine-->  
65 - <dependency>  
66 - <groupId>org.springframework.statemachine</groupId>  
67 - <artifactId>spring-statemachine-core</artifactId>  
68 - <version>1.2.0.RELEASE</version>  
69 - </dependency>  
70 -  
71 - <!--mina-->  
72 - <dependency>  
73 - <groupId>org.apache.mina</groupId>  
74 - <artifactId>mina-core</artifactId>  
75 - <version>2.1.3</version>  
76 - </dependency>  
77 - <dependency>  
78 - <groupId>org.apache.mina</groupId>  
79 - <artifactId>mina-integration-spring</artifactId>  
80 - <version>1.1.7</version>  
81 - </dependency>  
82 -  
83 63
84 </dependencies> 64 </dependencies>
85 65
src/main/java/com/example/mina/Application.java
@@ -3,6 +3,10 @@ package com.example.mina; @@ -3,6 +3,10 @@ package com.example.mina;
3 import org.springframework.boot.SpringApplication; 3 import org.springframework.boot.SpringApplication;
4 import org.springframework.boot.autoconfigure.SpringBootApplication; 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5
  6 +/**
  7 + * @author 杜云山
  8 + * @date 2021/03/05
  9 + */
6 @SpringBootApplication 10 @SpringBootApplication
7 public class Application { 11 public class Application {
8 12
src/main/java/com/example/mina/base/AbstractHardwareDataBuffer.java 0 → 100644
@@ -0,0 +1,92 @@ @@ -0,0 +1,92 @@
  1 +package com.example.mina.base;
  2 +
  3 +import com.example.mina.entity.Entry;
  4 +
  5 +/**
  6 + * @author 杜云山
  7 + * @date 2021/03/05
  8 + */
  9 +public abstract class AbstractHardwareDataBuffer {
  10 +
  11 + protected int maxRow;
  12 +
  13 + protected int maxCol;
  14 +
  15 + protected int maxOffset;
  16 +
  17 + protected int maxAttenuate;
  18 +
  19 + protected Entry[][] matrixData;
  20 +
  21 + protected Entry[] offsetData;
  22 +
  23 + public AbstractHardwareDataBuffer() {
  24 + }
  25 +
  26 + public AbstractHardwareDataBuffer(int row, int col, int offset, int maxAttenuate) {
  27 + this.maxRow = row;
  28 + this.maxCol = col;
  29 + this.maxOffset = offset;
  30 + this.maxAttenuate = maxAttenuate;
  31 + }
  32 +
  33 + /**
  34 + * Set cross point attenuation value. Actually that is not correct.
  35 + * In case of LTE device, this is a ON/OFF status (0,1)
  36 + *
  37 + * @param row the row index. *** starts from 1 ***
  38 + * @param col the col index. *** starts from 1 ***
  39 + * @param val the attenuation value
  40 + */
  41 + public synchronized void setAttenuation(int row, int col, int val) {
  42 +
  43 + if (val != -1 && (row < 1 || row > maxRow || col < 1 || col > maxCol)) {
  44 + return;
  45 + }
  46 + if (val == -1) {
  47 + val = maxAttenuate;
  48 + }
  49 + matrixData[row - 1][col - 1] = new Entry(row - 1, col - 1, "rr", val, false);
  50 + ;
  51 + }
  52 +
  53 + public int getAttenuation(int row, int col) {
  54 + return matrixData[row - 1][col - 1].getValue();
  55 + }
  56 +
  57 + public synchronized void setOffset(int row, int val) {
  58 + if (row < 1 || row > maxOffset) {
  59 + return;
  60 + }
  61 + offsetData[row - 1] = new Entry(row - 1, 0, "rr", val, false);
  62 + }
  63 +
  64 + public int getOffset(int row) {
  65 + return offsetData[row - 1].getValue();
  66 + }
  67 +
  68 + public Entry[] getOffsetData() {
  69 + return offsetData;
  70 + }
  71 +
  72 + public Entry[][] getMatrixData() {
  73 + return matrixData;
  74 + }
  75 +
  76 + public int getMaxRow() {
  77 + return maxRow;
  78 + }
  79 +
  80 + public int getMaxCol() {
  81 + return maxCol;
  82 + }
  83 +
  84 + public int getMaxOffset() {
  85 + return maxOffset;
  86 + }
  87 +
  88 + public int getMaxAttenuate() {
  89 + return maxAttenuate;
  90 + }
  91 +
  92 +}
src/main/java/com/example/mina/base/AbstractVirtualBoxHandler.java 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +package com.example.mina.base;
  2 +
  3 +import org.apache.mina.core.service.IoHandlerAdapter;
  4 +
  5 +/**
  6 + * @author 杜云山
  7 + * @date 21/03/05
  8 + */
  9 +public abstract class AbstractVirtualBoxHandler extends IoHandlerAdapter {
  10 +
  11 + /**
  12 + * 初始化矩阵以及该设备的一些参数
  13 + */
  14 + protected abstract void initMatrix();
  15 +
  16 + /**
  17 + * 处理消息
  18 + *
  19 + * @param cmd 指令数据
  20 + * @param len 数据长度
  21 + * @return 返回消息
  22 + */
  23 + protected abstract byte[] handleMessage(byte[] cmd, int len);
  24 +
  25 +}
src/main/java/com/example/mina/box1/AeroflexVirtualBoxHandler.java 0 → 100644
@@ -0,0 +1,139 @@ @@ -0,0 +1,139 @@
  1 +package com.example.mina.box1;
  2 +
  3 +import com.example.mina.base.AbstractVirtualBoxHandler;
  4 +import com.example.mina.entity.AeroflexDataBuffer;
  5 +import com.example.mina.util.StrUtil;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +import org.apache.mina.core.buffer.IoBuffer;
  8 +import org.apache.mina.core.session.IoSession;
  9 +
  10 +/**
  11 + * @author 杜云山
  12 + * @date 21/03/05
  13 + */
  14 +@Slf4j
  15 +public class AeroflexVirtualBoxHandler extends AbstractVirtualBoxHandler {
  16 +
  17 + private static final byte[] ERROR = "ERROR".getBytes();
  18 +
  19 + private static final byte[] NONE = "OK".getBytes();
  20 +
  21 + private static final String SET_ALL = "ATTN ALL MAX";
  22 +
  23 + private static final String SET_ONE = "ATTN";
  24 +
  25 + private static final String GET_ONE = "ATTN?";
  26 +
  27 + private static final String SPACE_SPLIT = " ";
  28 +
  29 + private static final String SEMICOLON_SPLIT = ";";
  30 +
  31 + private AeroflexDataBuffer dataBuffer;
  32 +
  33 + public AeroflexVirtualBoxHandler() {
  34 + this.initMatrix();
  35 + }
  36 +
  37 + @Override
  38 + protected void initMatrix() {
  39 +
  40 + int row = 10;
  41 + int col = 1;
  42 + int maxAttenuate = 888;
  43 +
  44 + dataBuffer = new AeroflexDataBuffer(row, maxAttenuate);
  45 + }
  46 +
  47 + @Override
  48 + public void messageReceived(IoSession session, Object message) {
  49 +
  50 + IoBuffer ioBuffer = (IoBuffer) message;
  51 + byte[] bytes = ioBuffer.array();
  52 +
  53 + byte[] result = handleMessage(bytes, bytes.length);
  54 +
  55 + session.write(IoBuffer.wrap(result));
  56 + }
  57 +
  58 + @Override
  59 + protected byte[] handleMessage(byte[] cmd, int len) {
  60 + String command = new String(cmd).trim();
  61 +
  62 + log.info("aeroflexVirtualBoxHandler receive: {}", command);
  63 +
  64 + if (command.startsWith(SET_ALL)) {
  65 + //set all to max
  66 + for (int i = 1; i < dataBuffer.getMaxRow(); i++) {
  67 + dataBuffer.setOffset(i, dataBuffer.getMaxAttenuate());
  68 + }
  69 +
  70 + return NONE;
  71 + } else if (command.startsWith(GET_ONE)) {
  72 + //get
  73 + String[] sss = command.split(SPACE_SPLIT);
  74 + if (sss.length >= 2) {
  75 +
  76 + int row = StrUtil.toInt(sss[1]);
  77 + if (row >= 0 && row <= dataBuffer.getMaxRow()) {
  78 + String str = String.valueOf(dataBuffer.getOffset(row));
  79 + log.info("aeroflexVirtualBoxHandler return: {}", str);
  80 + return str.getBytes();
  81 + }
  82 + }
  83 + return ERROR;
  84 +
  85 + } else if (command.startsWith(SET_ONE)) {
  86 + //Set, Follow by ATTN?
  87 + String[] aa = command.split(SEMICOLON_SPLIT);
  88 +
  89 + String[] sss = aa[0].split(SPACE_SPLIT);
  90 +
  91 + if (sss.length >= 3) {
  92 +
  93 + int row = StrUtil.toInt(sss[1]);
  94 + int val = StrUtil.toInt(sss[2]);
  95 +
  96 + if (row >= 0 && row <= dataBuffer.getMaxRow()) {
  97 + if (val >= 0 && val <= dataBuffer.getMaxAttenuate()) {
  98 + dataBuffer.setOffset(row, val);
  99 +
  100 + String str = String.valueOf(dataBuffer.getOffset(row));
  101 + log.info("aeroflexVirtualBoxHandler return =====> {}", str);
  102 + return str.getBytes();
  103 + }
  104 + }
  105 + }
  106 +
  107 + return ERROR;
  108 +
  109 + } else {
  110 + return ERROR;
  111 + }
  112 +
  113 + }
  114 +
  115 + @Override
  116 + public void sessionCreated(IoSession session) {
  117 +
  118 + log.info("--- abstractVirtual server session created");
  119 + }
  120 +
  121 + @Override
  122 + public void sessionOpened(IoSession session) {
  123 +
  124 + log.info("--- abstractVirtual server session Opened");
  125 + }
  126 +
  127 + @Override
  128 + public void sessionClosed(IoSession session) {
  129 +
  130 + log.info("--- abstractVirtual server session Closed");
  131 + }
  132 +
  133 + @Override
  134 + public void messageSent(IoSession session, Object message) {
  135 +
  136 + log.info("--- abstractVirtual 发送数据成功!{}", message);
  137 + }
  138 +
  139 +}
src/main/java/com/example/mina/config/AeroflexVirtualBoxConfiguration.java 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  1 +package com.example.mina.config;
  2 +
  3 +import com.example.mina.box1.AeroflexVirtualBoxHandler;
  4 +import com.example.mina.property.AeroflexVirtualProperties;
  5 +import lombok.extern.slf4j.Slf4j;
  6 +import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
  7 +import org.springframework.context.annotation.Configuration;
  8 +
  9 +import javax.annotation.PostConstruct;
  10 +import java.net.InetSocketAddress;
  11 +
  12 +/**
  13 + * @author 杜云山
  14 + * @date 21/03/05
  15 + */
  16 +@Slf4j
  17 +@Configuration(proxyBeanMethods = false)
  18 +public class AeroflexVirtualBoxConfiguration {
  19 +
  20 + private final AeroflexVirtualProperties aeroflexVirtualProperties;
  21 +
  22 + public AeroflexVirtualBoxConfiguration(AeroflexVirtualProperties aeroflexVirtualProperties) {
  23 + this.aeroflexVirtualProperties = aeroflexVirtualProperties;
  24 + }
  25 +
  26 + @PostConstruct
  27 + public void init() {
  28 +
  29 + if (!aeroflexVirtualProperties.getEnable()) {
  30 + log.info("AeroflexVirtual服务端 配置未开启");
  31 + return;
  32 + }
  33 +
  34 + if (aeroflexVirtualProperties.getPort() == null) {
  35 + log.info("AeroflexVirtual服务端 端口未配置");
  36 + return;
  37 + }
  38 +
  39 + try {
  40 + NioSocketAcceptor acceptor = new NioSocketAcceptor();
  41 + acceptor.setHandler(new AeroflexVirtualBoxHandler());
  42 + acceptor.setReuseAddress(true);
  43 + acceptor.bind(new InetSocketAddress(aeroflexVirtualProperties.getPort()));
  44 + log.info("AeroflexVirtual服务端已经启动,监听端口: {}", aeroflexVirtualProperties.getPort());
  45 + } catch (Exception e) {
  46 + log.error("无法启动AeroflexVirtual服务端, {}", e.getMessage(), e);
  47 + }
  48 + }
  49 +
  50 +}
src/main/java/com/example/mina/config/ConfigMina.java
@@ -1,97 +0,0 @@ @@ -1,97 +0,0 @@
1 -package com.example.mina.config;  
2 -  
3 -import com.example.mina.mina.code.ByteFactory;  
4 -import com.example.mina.mina.server.MinaServerHandler;  
5 -import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;  
6 -import org.apache.mina.core.service.IoAcceptor;  
7 -import org.apache.mina.core.session.IdleStatus;  
8 -import org.apache.mina.filter.codec.ProtocolCodecFilter;  
9 -import org.apache.mina.filter.executor.ExecutorFilter;  
10 -import org.apache.mina.filter.logging.LoggingFilter;  
11 -import org.apache.mina.transport.socket.nio.NioSocketAcceptor;  
12 -import org.springframework.context.annotation.Bean;  
13 -import org.springframework.context.annotation.Configuration;  
14 -  
15 -import java.io.IOException;  
16 -import java.net.InetSocketAddress;  
17 -  
18 -/**  
19 - * @author dy  
20 - * @date 2021/3/3  
21 - */  
22 -@Configuration  
23 -public class ConfigMina {  
24 -  
25 - /**  
26 - * 配置mina的多线程过滤器  
27 - *  
28 - * @return  
29 - */  
30 - @Bean  
31 - public ExecutorFilter executorFilter() {  
32 - //设置初始化线程数,最大线程数  
33 - ExecutorFilter executorFilter = new ExecutorFilter(10, 20);  
34 - return executorFilter;  
35 - }  
36 -  
37 - /**  
38 - * 配置mina的转码过滤器  
39 - *  
40 - * @return  
41 - */  
42 - @Bean  
43 - public ProtocolCodecFilter protocolCodecFilter() {  
44 -// TextLineCodecFactory factory = new TextLineCodecFactory(Charset.forName("UTF-8"),  
45 -// LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue());  
46 -  
47 -  
48 - //TextLineCodecFactory factory = new TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue());  
49 - ProtocolCodecFilter pcf = new ProtocolCodecFilter(new ByteFactory());  
50 - //ProtocolCodecFilter pcf = new ProtocolCodecFilter(factory);  
51 - return pcf;  
52 - }  
53 -  
54 - /**  
55 - * 配置mina的日志过滤器  
56 - *  
57 - * @return  
58 - */  
59 - @Bean  
60 - public LoggingFilter loggingFilter() {  
61 - return new LoggingFilter();  
62 - }  
63 -  
64 - /**  
65 - * 将过滤器注入到mina的链式管理器中  
66 - *  
67 - * @return  
68 - */  
69 - @Bean  
70 - public DefaultIoFilterChainBuilder defaultIoFilterChainBuilder() {  
71 - DefaultIoFilterChainBuilder def = new DefaultIoFilterChainBuilder();  
72 - def.addLast("executor", executorFilter());  
73 - def.addLast("logger", loggingFilter());  
74 - def.addLast("protocol", protocolCodecFilter());  
75 - return def;  
76 - }  
77 -  
78 - /**  
79 - * 开启mina的server服务,并设置对应的参数  
80 - *  
81 - * @return  
82 - * @throws IOException  
83 - */  
84 - @Bean  
85 - public IoAcceptor ioAcceptor() throws IOException {  
86 - IoAcceptor nio = new NioSocketAcceptor();  
87 - //设置缓冲区大小  
88 - nio.getSessionConfig().setReadBufferSize(2048);  
89 - //设置空闲状态时间,10秒没操作就进入空闲状态  
90 - nio.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);  
91 - nio.setFilterChainBuilder(defaultIoFilterChainBuilder());  
92 - nio.setHandler(new MinaServerHandler());  
93 - nio.bind(new InetSocketAddress(9098));  
94 - return nio;  
95 - }  
96 -  
97 -}  
src/main/java/com/example/mina/config/SecurityConfig.java
@@ -1,27 +0,0 @@ @@ -1,27 +0,0 @@
1 -package com.example.mina.config;  
2 -  
3 -import org.springframework.context.annotation.Configuration;  
4 -import org.springframework.security.config.annotation.web.builders.HttpSecurity;  
5 -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;  
6 -  
7 -/**  
8 - * @author dy  
9 - * @date 2021/2/25  
10 - */  
11 -@Configuration  
12 -public class SecurityConfig extends WebSecurityConfigurerAdapter {  
13 -  
14 - @Override  
15 - protected void configure(HttpSecurity http) throws Exception {  
16 - // 首页所有人都可以访问,功能也只有对应有权限的人才能访问到  
17 - // 请求授权的规则  
18 -  
19 -// http.authorizeRequests()  
20 -// .antMatchers("/").permitAll()  
21 -// .antMatchers("/level1/**").hasRole("vip1")  
22 -// .antMatchers("/level2/**").hasRole("vip2")  
23 -// .antMatchers("/level3/**").hasRole("vip3");  
24 - // 开启自动配置的登录功能  
25 - http.formLogin();  
26 - }  
27 -}  
src/main/java/com/example/mina/controller/RouterController.java
@@ -1,41 +0,0 @@ @@ -1,41 +0,0 @@
1 -package com.example.mina.controller;  
2 -  
3 -import lombok.extern.slf4j.Slf4j;  
4 -import org.springframework.stereotype.Controller;  
5 -import org.springframework.web.bind.annotation.GetMapping;  
6 -import org.springframework.web.bind.annotation.PathVariable;  
7 -  
8 -/**  
9 - * @author dy  
10 - * @date 2021/2/22  
11 - */  
12 -@Controller  
13 -@Slf4j  
14 -public class RouterController {  
15 -  
16 - @GetMapping({"/", "/index"})  
17 - public String index() {  
18 - log.info("是否进入程序");  
19 - return "/index";  
20 - }  
21 -  
22 - @GetMapping("/toLogin")  
23 - public String toLogin() {  
24 - return "views/login";  
25 - }  
26 -  
27 - @GetMapping("/level1/{id}")  
28 - public String level1(@PathVariable("id") int id) {  
29 - return "views/level1/" + id;  
30 - }  
31 -  
32 - @GetMapping("/level2/{id}")  
33 - public String level2(@PathVariable("id") int id) {  
34 - return "views/level2/" + id;  
35 - }  
36 -  
37 - @GetMapping("/level3/{id}")  
38 - public String level3(@PathVariable("id") int id) {  
39 - return "views/level3/" + id;  
40 - }  
41 -}  
src/main/java/com/example/mina/entity/AeroflexDataBuffer.java 0 → 100644
@@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
  1 +package com.example.mina.entity;
  2 +
  3 +import com.example.mina.base.AbstractHardwareDataBuffer;
  4 +
  5 +/**
  6 + * @author 杜云山
  7 + * @date 2021/03/05
  8 + */
  9 +public class AeroflexDataBuffer extends AbstractHardwareDataBuffer {
  10 +
  11 + public AeroflexDataBuffer(int row, int maxAtten) {
  12 + super(row, row, row, maxAtten);
  13 +
  14 + matrixData = new Entry[row][row];
  15 + offsetData = new Entry[row];
  16 +
  17 + for (int i = 0; i < row; i++) {
  18 + for (int k = 0; k < row; k++) {
  19 + matrixData[i][k] = new Entry(i, k, "kk", maxAtten, false);
  20 + }
  21 + }
  22 +
  23 + for (int i = 0; i < row; i++) {
  24 + offsetData[i] = new Entry(i, 0, "rr", maxAtten, false);
  25 + }
  26 +
  27 + }
  28 +
  29 +}
src/main/java/com/example/mina/entity/Entry.java 0 → 100644
@@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
  1 +package com.example.mina.entity;
  2 +
  3 +/**
  4 + * @author 杜云山
  5 + * @date 2021/03/05
  6 + */
  7 +public class Entry {
  8 +
  9 + private final int row;
  10 +
  11 + private final int col;
  12 +
  13 + private final String name;
  14 +
  15 + private int value;
  16 +
  17 + private final boolean booked;
  18 +
  19 + private final long timestamp;
  20 +
  21 + public static final Entry EMPTY = new Entry(0, 0, null, 0, false);
  22 +
  23 + public Entry(int row, int col, String name, int value, boolean booked) {
  24 + this.row = row;
  25 + this.col = col;
  26 + this.name = name;
  27 + this.value = value;
  28 + this.booked = booked;
  29 + this.timestamp = System.nanoTime();
  30 + }
  31 +
  32 + public int getRow() {
  33 + return row;
  34 + }
  35 +
  36 + public int getCol() {
  37 + return col;
  38 + }
  39 +
  40 + public String getName() {
  41 + return name;
  42 + }
  43 +
  44 + public int getValue() {
  45 + return value;
  46 + }
  47 +
  48 + public boolean isBooked() {
  49 + return booked;
  50 + }
  51 +
  52 + public void setValue(int v) {
  53 + this.value = v;
  54 + }
  55 +
  56 + public long getTimestamp() {
  57 + return this.timestamp;
  58 + }
  59 +
  60 +}
src/main/java/com/example/mina/http/HttpSimulator.java
@@ -1,136 +0,0 @@ @@ -1,136 +0,0 @@
1 -package com.example.mina.http;  
2 -  
3 -import java.io.*;  
4 -import java.net.InetSocketAddress;  
5 -import java.net.Socket;  
6 -  
7 -/**  
8 - * @author dy  
9 - * @date 2021/3/4  
10 - */  
11 -public class HttpSimulator {  
12 -  
13 - private Socket socket;  
14 -  
15 - private int port = 80;  
16 -  
17 - private String host = "localhost";  
18 -  
19 - private String request = ""; // HTTP请求消息  
20 -  
21 - private boolean isPost, isHead;  
22 -  
23 -  
24 - public void run() throws Exception {  
25 - BufferedReader reader = new BufferedReader(new InputStreamReader(  
26 - System.in));  
27 - while (true) // 开始大循环  
28 - {  
29 - try {  
30 - if (!readHostAndPort(reader)) {  
31 - break;  
32 - }  
33 - readHttpRequest(reader);  
34 - sendHttpRequest();  
35 - readHttpResponse(reader);  
36 -  
37 - } catch (Exception e) {  
38 - System.out.println("err:" + e.getMessage());  
39 -  
40 - }  
41 -  
42 - }  
43 -  
44 - }  
45 -  
46 -  
47 - public static void main(String[] args) throws Exception {  
48 - new HttpSimulator().run();  
49 -  
50 - }  
51 -  
52 - private boolean readHostAndPort(BufferedReader consoleReader)  
53 - throws Exception {  
54 - System.out.print("host:port>");  
55 - String[] ss = null;  
56 - String s = consoleReader.readLine();  
57 - if (s.equals("q")) {  
58 - return false;  
59 - } else {  
60 - ss = s.split("[:]");  
61 - if (!ss[0].equals("")) {  
62 - host = ss[0];  
63 - }  
64 - if (ss.length > 1) {  
65 - port = Integer.parseInt(ss[1]);  
66 - }  
67 - System.out.println(host + ":" + String.valueOf(port));  
68 - return true;  
69 - }  
70 - }  
71 -  
72 - private void readHttpRequest(BufferedReader consoleReader)  
73 - throws Exception {  
74 - System.out.println("请输入HTTP请求:");  
75 - String s = consoleReader.readLine();  
76 - request = s + "\r\n";  
77 - boolean isPost = s.substring(0, 4).equals("POST");  
78 - boolean isHead = s.substring(0, 4).equals("HEAD");  
79 - while (!(s = consoleReader.readLine()).equals("")) {  
80 - request = request + s + "\r\n";  
81 - }  
82 - request = request + "\r\n";  
83 - if (isPost) {  
84 - System.out.println("请输入POST方法的内容:");  
85 - s = consoleReader.readLine();  
86 - request = request + s;  
87 - }  
88 - }  
89 -  
90 - private void sendHttpRequest() throws Exception {  
91 - socket = new Socket();  
92 - socket.setSoTimeout(10 * 1000);  
93 - System.out.println("正在连接服务器");  
94 - socket.connect(new InetSocketAddress(host, port), 10 * 1000);  
95 - System.out.println("服务器连接成功!");  
96 - OutputStream out = socket.getOutputStream();  
97 - OutputStreamWriter writer = new OutputStreamWriter(out);  
98 - writer.write(request);  
99 - writer.flush();  
100 - }  
101 -  
102 - private void readHttpResponse(BufferedReader consoleReader) {  
103 - String s = "";  
104 - try {  
105 - InputStream in = socket.getInputStream();  
106 - InputStreamReader inReader = new InputStreamReader(in);  
107 - BufferedReader socketReader = new BufferedReader(inReader);  
108 - System.out.println("---------HTTP头---------");  
109 - boolean b = true; // true: 未读取消息头 false: 已经读取消息头  
110 - while ((s = socketReader.readLine()) != null) {  
111 - if (s.equals("") && b == true && !isHead) {  
112 - System.out.println("------------------------");  
113 - b = false;  
114 - System.out.print("是否显示HTTP的内容(Y/N):");  
115 - String choice = consoleReader.readLine();  
116 - if (choice.equals("Y") || choice.equals("y")) {  
117 - System.out.println("---------HTTP内容---------");  
118 - continue;  
119 - } else {  
120 - break;  
121 - }  
122 - } else {  
123 - System.out.println(s);  
124 - }  
125 - }  
126 - } catch (Exception e) {  
127 - System.out.println("err:" + e.getMessage());  
128 - } finally {  
129 - try {  
130 - socket.close();  
131 - } catch (Exception e) {  
132 - }  
133 - }  
134 - System.out.println("------------------------");  
135 - }  
136 -}  
src/main/java/com/example/mina/mina/client/MinaClient.java
@@ -1,40 +0,0 @@ @@ -1,40 +0,0 @@
1 -package com.example.mina.mina.client;  
2 -  
3 -import org.apache.mina.core.service.IoConnector;  
4 -import org.apache.mina.filter.codec.ProtocolCodecFilter;  
5 -import org.apache.mina.filter.codec.textline.LineDelimiter;  
6 -import org.apache.mina.filter.codec.textline.TextLineCodecFactory;  
7 -import org.apache.mina.transport.socket.nio.NioSocketConnector;  
8 -  
9 -import java.net.InetSocketAddress;  
10 -import java.nio.charset.Charset;  
11 -  
12 -/**  
13 - * @author dy  
14 - * @date 2021/3/3  
15 - */  
16 -public class MinaClient {  
17 -  
18 - public static void main(String[] args) {  
19 - //1、创建客户端IoService  
20 - IoConnector connector = new NioSocketConnector();  
21 - //客户端链接超时时间  
22 - connector.setConnectTimeoutMillis(30000);  
23 - //2、客户端过滤器  
24 - connector.getFilterChain().addLast("test",  
25 - new ProtocolCodecFilter(  
26 - new TextLineCodecFactory(  
27 - Charset.forName("UTF-8"),  
28 - LineDelimiter.WINDOWS.getValue(),  
29 - LineDelimiter.WINDOWS.getValue()  
30 - )  
31 - )  
32 - );  
33 - //3、客户端IoHandler,发生消息  
34 - connector.setHandler(new MinaClientHandler("2"));  
35 - //连接服务端  
36 - connector.connect(new InetSocketAddress("localhost", 9098));  
37 -  
38 - }  
39 -  
40 -}  
src/main/java/com/example/mina/mina/client/MinaClientHandler.java
@@ -1,39 +0,0 @@ @@ -1,39 +0,0 @@
1 -package com.example.mina.mina.client;  
2 -  
3 -import org.apache.mina.core.service.IoHandlerAdapter;  
4 -import org.apache.mina.core.session.IoSession;  
5 -  
6 -/**  
7 - * @author dy  
8 - * @date 2021/3/3  
9 - */  
10 -public class MinaClientHandler extends IoHandlerAdapter {  
11 -  
12 - private final String values;  
13 -  
14 - public MinaClientHandler(String values) {  
15 - this.values = values;  
16 - }  
17 -  
18 - @Override  
19 - public void sessionOpened(IoSession session) {  
20 - session.write(values);  
21 -// //调用IoService的dispose方法关闭线程,这样每次调用client方法发送数据之后就会关闭client  
22 -// IoService service = session.getService();  
23 -// service.dispose();  
24 -  
25 - }  
26 -  
27 - /**  
28 - * 接收服务器端反馈消息  
29 - *  
30 - * @param session  
31 - * @param message  
32 - * @throws Exception  
33 - */  
34 - @Override  
35 - public void messageReceived(IoSession session, Object message) throws Exception {  
36 - System.out.println("收到服务器响应消息:" + message);  
37 - }  
38 -  
39 -}  
src/main/java/com/example/mina/mina/code/ByteDecoder.java
@@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
1 -package com.example.mina.mina.code;  
2 -  
3 -import org.apache.mina.core.buffer.IoBuffer;  
4 -import org.apache.mina.core.session.IoSession;  
5 -import org.apache.mina.filter.codec.ProtocolDecoder;  
6 -import org.apache.mina.filter.codec.ProtocolDecoderAdapter;  
7 -import org.apache.mina.filter.codec.ProtocolDecoderOutput;  
8 -import org.slf4j.Logger;  
9 -import org.slf4j.LoggerFactory;  
10 -  
11 -/**  
12 - * @author dy  
13 - * @date 2021/3/3  
14 - */  
15 -public class ByteDecoder extends ProtocolDecoderAdapter {  
16 - //打印日志信息  
17 - private final static Logger log = LoggerFactory  
18 - .getLogger(ProtocolDecoder.class);  
19 -  
20 - @Override  
21 - public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {  
22 - int limit = in.limit();  
23 - byte[] bytes = new byte[limit];  
24 -  
25 - in.get(bytes);  
26 -  
27 - out.write(bytes);  
28 - }  
29 -}  
src/main/java/com/example/mina/mina/code/ByteEnCoder.java
@@ -1,37 +0,0 @@ @@ -1,37 +0,0 @@
1 -package com.example.mina.mina.code;  
2 -  
3 -import org.apache.mina.core.buffer.IoBuffer;  
4 -import org.apache.mina.core.session.IoSession;  
5 -import org.apache.mina.filter.codec.ProtocolEncoder;  
6 -import org.apache.mina.filter.codec.ProtocolEncoderAdapter;  
7 -import org.apache.mina.filter.codec.ProtocolEncoderOutput;  
8 -import org.slf4j.Logger;  
9 -import org.slf4j.LoggerFactory;  
10 -  
11 -/**  
12 - * @author dy  
13 - * @date 2021/3/3  
14 - */  
15 -public class ByteEnCoder extends ProtocolEncoderAdapter {  
16 - //用于打印日志信息  
17 - private final static Logger log = LoggerFactory  
18 - .getLogger(ProtocolEncoder.class);  
19 -  
20 - //编码 将数据包转成字节数组  
21 - @Override  
22 - public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {  
23 - byte[] bytes = (byte[]) message;  
24 -  
25 - IoBuffer buffer = IoBuffer.allocate(256);  
26 - buffer.setAutoExpand(true);  
27 -  
28 - buffer.put(bytes);  
29 - buffer.flip();  
30 -  
31 - out.write(buffer);  
32 - out.flush();  
33 -  
34 - buffer.free();  
35 - }  
36 -  
37 -}  
src/main/java/com/example/mina/mina/code/ByteFactory.java
@@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
1 -package com.example.mina.mina.code;  
2 -  
3 -import org.apache.mina.core.session.IoSession;  
4 -import org.apache.mina.filter.codec.ProtocolCodecFactory;  
5 -import org.apache.mina.filter.codec.ProtocolDecoder;  
6 -import org.apache.mina.filter.codec.ProtocolEncoder;  
7 -  
8 -/**  
9 - * @author dy  
10 - * @date 2021/3/3  
11 - */  
12 -public class ByteFactory implements ProtocolCodecFactory {  
13 - private final ByteDecoder decoder;  
14 - private final ByteEnCoder encoder;  
15 -  
16 - //构造  
17 - public ByteFactory() {  
18 - encoder = new ByteEnCoder();  
19 - decoder = new ByteDecoder();  
20 - }  
21 -  
22 - @Override  
23 - public ProtocolDecoder getDecoder(IoSession arg0) throws Exception {  
24 - // TODO Auto-generated method stub  
25 - return decoder;  
26 - }  
27 -  
28 - @Override  
29 - public ProtocolEncoder getEncoder(IoSession arg0) throws Exception {  
30 - // TODO Auto-generated method stub  
31 - return encoder;  
32 - }  
33 -  
34 -}  
src/main/java/com/example/mina/mina/server/MinaServer.java
@@ -1,92 +0,0 @@ @@ -1,92 +0,0 @@
1 -package com.example.mina.mina.server;  
2 -  
3 -import com.example.mina.mina.code.ByteFactory;  
4 -import org.apache.mina.core.service.IoAcceptor;  
5 -import org.apache.mina.core.session.IdleStatus;  
6 -import org.apache.mina.filter.codec.ProtocolCodecFilter;  
7 -import org.apache.mina.filter.codec.textline.LineDelimiter;  
8 -import org.apache.mina.filter.codec.textline.TextLineCodecFactory;  
9 -import org.apache.mina.filter.executor.ExecutorFilter;  
10 -import org.apache.mina.filter.logging.LogLevel;  
11 -import org.apache.mina.filter.logging.LoggingFilter;  
12 -import org.apache.mina.transport.socket.nio.NioSocketAcceptor;  
13 -  
14 -import java.io.IOException;  
15 -import java.net.InetSocketAddress;  
16 -import java.nio.charset.Charset;  
17 -  
18 -/**  
19 - * @author dy  
20 - * @date 2021/3/3  
21 - */  
22 -public class MinaServer {  
23 -  
24 - public static ExecutorFilter executorFilter() {  
25 - //设置初始化线程数,最大线程数  
26 - ExecutorFilter executorFilter = new ExecutorFilter(10, 20);  
27 - return executorFilter;  
28 - }  
29 -  
30 - public static LoggingFilter loggingFilter() {  
31 - return new LoggingFilter();  
32 - }  
33 -  
34 - public static ProtocolCodecFilter protocolCodecFilter() {  
35 -// TextLineCodecFactory factory = new TextLineCodecFactory(Charset.forName("UTF-8"),  
36 -// LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue());  
37 -  
38 -  
39 - //TextLineCodecFactory factory = new TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue());  
40 - ProtocolCodecFilter pcf = new ProtocolCodecFilter(new ByteFactory());  
41 - //ProtocolCodecFilter pcf = new ProtocolCodecFilter(factory);  
42 - return pcf;  
43 - }  
44 -  
45 - public static void main(String[] args) throws IOException {  
46 - /*IoAcceptor nio = new NioSocketAcceptor();  
47 - //设置缓冲区大小  
48 - nio.getSessionConfig().setReadBufferSize(2048);  
49 - //设置空闲状态时间,10秒没操作就进入空闲状态  
50 - nio.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);  
51 -  
52 - DefaultIoFilterChainBuilder def = new DefaultIoFilterChainBuilder();  
53 - def.addLast("executor", executorFilter());  
54 - def.addLast("logger", loggingFilter());  
55 - def.addLast("protocol", protocolCodecFilter());  
56 -  
57 - nio.setFilterChainBuilder(def);  
58 - nio.setHandler(new MinaServerHandler());  
59 - nio.bind(new InetSocketAddress(9098));*/  
60 -  
61 -  
62 -  
63 -  
64 -  
65 - //1、创建IoService,拥有监听是否有客户端链接  
66 - IoAcceptor acceptor = new NioSocketAcceptor();  
67 - //设置缓冲区大小  
68 - acceptor.getSessionConfig().setReadBufferSize(2048);  
69 - //设置空闲状态时间,10秒没操作就进入空闲状态  
70 - acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);  
71 -  
72 - //创建日志过滤器,mina内部使用的是slf4j日志,加入日志之后可以查看mina的运行细节信息  
73 - LoggingFilter log = new LoggingFilter();  
74 - log.setSessionOpenedLogLevel(LogLevel.INFO);  
75 - acceptor.getFilterChain().addLast("logger", log);  
76 -  
77 - //2、实现过滤器  
78 - //acceptor.getFilterChain().addLast("protocol", protocolCodecFilter());  
79 - acceptor.getFilterChain().addLast("protocol",  
80 - new ProtocolCodecFilter(  
81 - new TextLineCodecFactory(Charset.forName("UTF-8"), LineDelimiter.WINDOWS.getValue(), LineDelimiter.WINDOWS.getValue())  
82 - )  
83 - );  
84 - //3、实现IoHandler,并注册到IoService  
85 - acceptor.setHandler(new MinaServerHandler());  
86 - //绑定端口,绑定之前必须设置handler实现类  
87 - acceptor.bind(new InetSocketAddress(9098));  
88 -  
89 -  
90 - }  
91 -  
92 -}  
src/main/java/com/example/mina/mina/server/MinaServerHandler.java
@@ -1,141 +0,0 @@ @@ -1,141 +0,0 @@
1 -package com.example.mina.mina.server;  
2 -  
3 -import org.apache.mina.core.service.IoHandlerAdapter;  
4 -import org.apache.mina.core.session.IoSession;  
5 -  
6 -import java.io.ByteArrayOutputStream;  
7 -import java.io.ObjectOutputStream;  
8 -import java.net.SocketAddress;  
9 -import java.nio.charset.Charset;  
10 -import java.nio.charset.StandardCharsets;  
11 -  
12 -/**  
13 - * @author dy  
14 - * @date 2021/3/3  
15 - */  
16 -public class MinaServerHandler extends IoHandlerAdapter {  
17 -  
18 - @Override  
19 - public void messageReceived(IoSession session, Object message) throws Exception {  
20 -// String command = new String(ObjectToByte(message)).trim();  
21 -//  
22 -// if (command.startsWith("ATTN ALL MAX")) {//set all to max  
23 -// for (int i = 1; i < dataBuffer.getMaxRow(); i++) {  
24 -// dataBuffer.setOffset(i, dataBuffer.getMaxAtten());  
25 -// }  
26 -//  
27 -// return NONE;  
28 -// } else if (command.startsWith("ATTN?")) {//get  
29 -// String[] sss = command.split(" ");  
30 -// if (sss.length >= 2) {  
31 -// LogUtils.println(sss[0], sss[1]);  
32 -//  
33 -// int row = StrUtil.toInt(sss[1]);  
34 -// if (row >= 0 && row <= dataBuffer.getMaxRow()) {  
35 -// String str = String.valueOf(dataBuffer.getOffset(row));  
36 -// LogUtils.println("AeroflexVirtualBoxService::handleCommand return : ", str);  
37 -// return str.getBytes();  
38 -// }  
39 -// }  
40 -//  
41 -// return ERROR;  
42 -// } else if (command.startsWith("ATTN")) {//Set, Follow by ATTN?  
43 -// LogUtils.println("command.startsWith(\"ATTN\")");  
44 -// String[] aa = command.split(";");  
45 -//  
46 -// LogUtils.println(aa[0], aa[1]);  
47 -//  
48 -// String[] sss = aa[0].split(" ");  
49 -// StrUtil.printArray(sss);  
50 -//  
51 -// if (sss.length >= 3) {  
52 -// int row = StrUtil.toInt(sss[1]);  
53 -// int val = StrUtil.toInt(sss[2]);  
54 -//  
55 -// System.out.println(row + "/" + val);  
56 -//  
57 -//  
58 -// if (row >= 0 && row <= dataBuffer.getMaxRow()) {  
59 -// if (val >= 0 && val <= dataBuffer.getMaxAtten()) {  
60 -// dataBuffer.setOffset(row, val);  
61 -//  
62 -// String str = String.valueOf(dataBuffer.getOffset(row));  
63 -// LogUtils.println("handleCommand return =====> ", str);  
64 -// return str.getBytes();  
65 -// }  
66 -// }  
67 -// }  
68 -  
69 - //业务代码在这里编写处理  
70 - String str = new String((byte[])message);  
71 - System.out.println("The message received is [" + str + "]");  
72 - //获取客户端的连接地址  
73 - SocketAddress socketAddress = session.getRemoteAddress();  
74 - System.out.println(socketAddress);  
75 - String send = "消息已处理,你可以去玩了。。。";  
76 - //响应给对应客户端信息  
77 - session.write(send.getBytes());  
78 - session.closeNow();  
79 -// // 此处关闭session后客户端无法接收到服务器反馈的消息  
80 -// if (str.endsWith("quit")) {  
81 -// //注意:在这里调用close方法之后,只是关闭当前的tcp连接,server端还正常运行,  
82 -// //需要调用IoService的dispose方法才能关闭server端,client端同理  
83 -//  
84 -// return;  
85 -// }  
86 - }  
87 -  
88 - @Override  
89 - public void sessionCreated(IoSession session) throws Exception {  
90 - System.out.println("server session created");  
91 - super.sessionCreated(session);  
92 - }  
93 -  
94 - @Override  
95 - public void sessionOpened(IoSession session) throws Exception {  
96 - System.out.println("server session Opened");  
97 - super.sessionOpened(session);  
98 - }  
99 -  
100 - @Override  
101 - public void sessionClosed(IoSession session) throws Exception {  
102 - System.out.println("server session Closed");  
103 - super.sessionClosed(session);  
104 - }  
105 -  
106 - /**  
107 - * 在IoHandlerAdapter中有一个messageSent的方法,但是重写这个方法之后,不会发送数据,该方法只有数据发送成功之后才会调用,  
108 - * 所以在 messageReceived 方法中使用 session.write("消息已处理,你可以去玩了。。。"); 给客户端响应数据  
109 - *  
110 - * @param session  
111 - * @param message  
112 - * @throws Exception  
113 - */  
114 - @Override  
115 - public void messageSent(IoSession session, Object message) throws Exception {  
116 - // TODO Auto-generated method stub  
117 - System.out.println("发送数据成功了。。。" + message);  
118 - // session.write("testSent");  
119 - super.messageSent(session, message);  
120 - }  
121 -  
122 - private byte[] ObjectToByte(Object obj) {  
123 - byte[] bytes = null;  
124 - try {  
125 - // object to bytearray  
126 - ByteArrayOutputStream bo = new ByteArrayOutputStream();  
127 - ObjectOutputStream oo = new ObjectOutputStream(bo);  
128 - oo.writeObject(obj);  
129 -  
130 - bytes = bo.toByteArray();  
131 -  
132 - bo.close();  
133 - oo.close();  
134 - } catch (Exception e) {  
135 - System.out.println("translation" + e.getMessage());  
136 - e.printStackTrace();  
137 - }  
138 - return bytes;  
139 - }  
140 -  
141 -}  
src/main/java/com/example/mina/property/AeroflexVirtualProperties.java 0 → 100644
@@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
  1 +package com.example.mina.property;
  2 +
  3 +import lombok.Getter;
  4 +import lombok.Setter;
  5 +import lombok.ToString;
  6 +import org.springframework.boot.context.properties.ConfigurationProperties;
  7 +import org.springframework.boot.context.properties.EnableConfigurationProperties;
  8 +import org.springframework.context.annotation.Configuration;
  9 +
  10 +/**
  11 + * @author 杜云山
  12 + * @date 2021/03/05
  13 + */
  14 +@Getter
  15 +@Setter
  16 +@ToString
  17 +@ConfigurationProperties(prefix = "aeroflex-virtual")
  18 +@Configuration
  19 +@EnableConfigurationProperties(AeroflexVirtualProperties.class)
  20 +public class AeroflexVirtualProperties {
  21 +
  22 + private Boolean enable = false;
  23 +
  24 + private Integer port = null;
  25 +
  26 +}
0 \ No newline at end of file 27 \ No newline at end of file
src/main/java/com/example/mina/util/StrUtil.java 0 → 100644
@@ -0,0 +1,63 @@ @@ -0,0 +1,63 @@
  1 +package com.example.mina.util;
  2 +
  3 +import lombok.extern.slf4j.Slf4j;
  4 +
  5 +/**
  6 + * @author 杜云山
  7 + * @date 2021/03/05
  8 + */
  9 +@Slf4j
  10 +public class StrUtil {
  11 +
  12 + public static int[] parseCommaInts(String str) {
  13 + if (str == null) {
  14 + return new int[0];
  15 + }
  16 +
  17 + String[] ss = str.split(",");
  18 + int[] ids = new int[ss.length];
  19 +
  20 + int count = 0;
  21 + for (int i = 0; i < ss.length; i++) {
  22 + int p = toInt(ss[i]);
  23 + ids[i] = p;
  24 + if (p >= 0) {
  25 + count++;
  26 + }
  27 + }
  28 +
  29 + if (count < ss.length) {
  30 + int[] ids2 = new int[count];
  31 + count = 0;
  32 + for (int i = 0; i < ss.length; i++) {
  33 + if (ids[i] >= 0) {
  34 + ids2[count++] = ids[i];
  35 + }
  36 + }
  37 +
  38 + ids = ids2;
  39 + }
  40 +
  41 + return ids;
  42 + }
  43 +
  44 + public static int toInt(String str) {
  45 + if (isEmpty(str)) {
  46 + return -1;
  47 + }
  48 +
  49 + try {
  50 + float f = Float.parseFloat(str.trim());
  51 + return (int) f;
  52 + } catch (Exception e) {
  53 + log.error("{}, 无法转换为数字", str, e);
  54 + return -1;
  55 + }
  56 +
  57 + }
  58 +
  59 + public static boolean isEmpty(String str) {
  60 + return str == null || str.trim().isEmpty();
  61 + }
  62 +
  63 +}
src/main/resources/application.yml
1 -server:  
2 - port: 8080  
3 - servlet:  
4 - context-path: /test  
5 -  
6 -# rabbitmq配置  
7 - #spring:  
8 - # rabbitmq:  
9 - # host: localhost  
10 - # port: 5672  
11 - # username: guest  
12 - # password: guest  
13 - # virtual-host: /  
14 \ No newline at end of file 1 \ No newline at end of file
  2 +aeroflex-virtual:
  3 + enable: true
  4 + port: 9100
15 \ No newline at end of file 5 \ No newline at end of file
src/main/resources/templates/index.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是首页</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level1/1.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level1-1</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level1/2.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level1-2</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level1/3.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level1-3</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level2/1.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level2-1</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level2/2.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level2-2</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level2/3.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level2-3</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level3/1.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level3-1</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level3/2.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level3-2</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/level3/3.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是level3-3</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file
src/main/resources/templates/views/login.html
@@ -1,10 +0,0 @@ @@ -1,10 +0,0 @@
1 -<!DOCTYPE html>  
2 -<html lang="en">  
3 -<head>  
4 - <meta charset="UTF-8">  
5 - <title>Title</title>  
6 -</head>  
7 -<body>  
8 -<div>我是登录页</div>  
9 -</body>  
10 -</html>  
11 \ No newline at end of file 0 \ No newline at end of file