Sfoglia il codice sorgente

文档补充、代码升级

liukx 3 anni fa
parent
commit
b9c9517eec
33 ha cambiato i file con 460 aggiunte e 177 eliminazioni
  1. 3 0
      README.md
  2. 1 1
      elab-alert/pom.xml
  3. 1 1
      elab-annotation/pom.xml
  4. 4 3
      elab-cache/README.md
  5. 1 1
      elab-cache/pom.xml
  6. 1 1
      elab-core/pom.xml
  7. 1 1
      elab-db/pom.xml
  8. 1 1
      elab-db/src/main/java/com/elab/core/aop/annotations/EnableElabDB.java
  9. 3 3
      elab-db/src/main/java/com/elab/core/dao/BasicBaseDao.java
  10. 1 1
      elab-db/src/main/java/com/elab/core/spring/config/TransactionConfigBean.java
  11. 1 1
      elab-es/pom.xml
  12. 1 1
      elab-kafka/pom.xml
  13. 25 2
      elab-log/pom.xml
  14. 3 2
      elab-log/src/main/java/com/elab/log/asepct/LogResponseBodyAdvice.java
  15. 53 20
      elab-log/src/main/java/com/elab/log/log4j/CatLogbackLog.java
  16. 20 0
      elab-log/src/test/java/com/elab/log/log4j/CatLogbackLogTest.java
  17. 4 3
      elab-log/src/test/resources/logback.xml
  18. 1 1
      elab-mongodb/pom.xml
  19. 1 1
      elab-mq/pom.xml
  20. 14 0
      elab-redis/README.md
  21. 1 1
      elab-redis/pom.xml
  22. 1 1
      elab-rocketMQ/pom.xml
  23. 10 6
      elab-spring/pom.xml
  24. 9 5
      elab-spring/src/main/java/com/elab/spring/anno/AuthorDescription.java
  25. 56 56
      elab-spring/src/main/java/com/elab/spring/componts/endpoints/CatEndpoint.java
  26. 40 40
      elab-spring/src/main/java/com/elab/spring/intercept/AuthorDescriptionAnnotationProcess.java
  27. 17 12
      elab-spring/src/main/java/com/elab/spring/intercept/CheckAnnotationProcess.java
  28. 7 8
      elab-spring/src/main/java/com/elab/spring/utils/RestTemplateUtils.java
  29. 1 1
      elab-test/pom.xml
  30. 114 0
      elab-test/src/main/java/com/elab/test/guava/EventBusSample.java
  31. 21 0
      elab-test/src/main/java/com/elab/test/guava/IpSample.java
  32. 39 0
      elab-test/src/main/java/com/elab/test/netty/HashedWheelTimerSample.java
  33. 4 3
      pom.xml

+ 3 - 0
README.md

@@ -19,8 +19,11 @@
 - 将elab-spring的功能组件拆分成`@EnableElabSpring` 注解化,根据注解的启用来调整是否开启特定功能
 - 集成redis的配置中心化功能
 - 将AOP注解拦截功能功能化,通过实现`AnnotationProcessService`接口来完成代理业务处理,默认实现类`AuthorDescriptionAnnotationProcess`
+    - 通过`@AuthorDescription`注解来完成业务逻辑的埋点,通过集成数据收集器来完成告警功能。
 - 新增功能类
   - `LoadContextTool` : 确定资源加载完毕之后被唤醒。
+  - `SpringEventUtils` : 相当于本地消息队列的模型,通过数据订阅的方式,将发送特定的数据结构,去容器中查找关于该数据的消费逻辑器。
+  
 #### elab-redis
 - 新增配置中心化的功能
 

+ 1 - 1
elab-alert/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <artifactId>elab-alert</artifactId>

+ 1 - 1
elab-annotation/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 4 - 3
elab-cache/README.md

@@ -2,7 +2,7 @@
 
 #### 使用步骤:
 1. 引入maven的依赖
-```
+```xml
 <dependency>
     <groupId>com.elab.cache</groupId>
     <artifactId>elab-cache</artifactId>
@@ -11,7 +11,7 @@
 ```
 
 2. 在配置文件中配置使用的对象
-```
+```xml
      <!-- 默认生成的缓存key的实现策略 -->
     <bean id="defaultCacheKeyGenerator" class="com.elab.cache.spring.generator.DefaultCacheKeyGenerator">
         <property name="prefix" value="demo"/>
@@ -98,7 +98,7 @@
     </bean>
 ```
 3. 代码层面如何使用,具体需要
-```
+```java
 
 // 这里需要注意的是定义了CacheConfig相当于对这个类定义了全局的缓存配置
 // 下面的value可以不用定义了 -> @Cacheable(value = "redisClient")
@@ -140,6 +140,7 @@ public class ServiceImpl implements IService {
     }
 ```
 **注意**
+
 1. 集合如何更新  
     自定义的key的话最好有规律可循,例如再缓存了多个集合的情况出现数据更新就比较麻烦了,
     所以推荐key的定义方式[project_class_list_method],这种的话,在更新缓存的时候,方便通过[project_class_list]为前缀的key全部删除掉,重新加载

+ 1 - 1
elab-cache/pom.xml

@@ -6,7 +6,7 @@
     <parent>
         <groupId>com.elab.core</groupId>
         <artifactId>elab-parent</artifactId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>2.0.5.4-SNAPSHOT</version>
     </parent>
     <groupId>com.elab.cache</groupId>
     <artifactId>elab-cache</artifactId>

+ 1 - 1
elab-core/pom.xml

@@ -7,7 +7,7 @@
     <parent>
         <groupId>com.elab.core</groupId>
         <artifactId>elab-parent</artifactId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
 
     <groupId>com.elab.core</groupId>

+ 1 - 1
elab-db/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <groupId>com.elab.core</groupId>
         <artifactId>elab-parent</artifactId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
     <artifactId>elab-db</artifactId>

+ 1 - 1
elab-db/src/main/java/com/elab/core/aop/annotations/EnableElabDB.java

@@ -11,7 +11,7 @@ import java.lang.annotation.*;
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.TYPE)
 @Documented
-@Import({DaoScannerRegister.class, DataSourceConfigBean.class, BasicDaoConfig.class, TransactionConfigBean.class})
+@Import({DaoScannerRegister.class, DataSourceConfigBean.class, BasicDaoConfig.class})
 public @interface EnableElabDB {
     /**
      * Alias for the {@link #basePackages()} attribute. Allows for more concise annotation

+ 3 - 3
elab-db/src/main/java/com/elab/core/dao/BasicBaseDao.java

@@ -66,9 +66,9 @@ public class BasicBaseDao implements ApplicationContextAware, InitializingBean {
 
     @Override
     public void afterPropertiesSet() throws Exception {
-        Map<String, CheckSqlProcess> beansOfType = this.applicationContext.getBeansOfType(CheckSqlProcess.class);
+        // Map<String, CheckSqlProcess> beansOfType = this.applicationContext.getBeansOfType(CheckSqlProcess.class);
         Map<String, SQLEventHandler> SQLEventHandlerMap = this.applicationContext.getBeansOfType(SQLEventHandler.class);
-        if (SQLEventHandlerMap != null && SQLEventHandlerMap.size() > 0) {
+        if (SQLEventHandlerMap.size() > 0) {
             this.sqlEventHandlerList = new ArrayList<>();
             SQLEventHandlerMap.forEach((K, V) -> {
                 this.sqlEventHandlerList.add(V);
@@ -76,7 +76,7 @@ public class BasicBaseDao implements ApplicationContextAware, InitializingBean {
         }
 
         Map<String, SQLPostProcess> sqlPostProcessMap = this.applicationContext.getBeansOfType(SQLPostProcess.class);
-        if (sqlPostProcessMap != null && sqlPostProcessMap.size() > 0) {
+        if (sqlPostProcessMap.size() > 0) {
             this.sqlPostProcessorList = new ArrayList<>();
             sqlPostProcessMap.forEach((K, V) -> {
                 this.sqlPostProcessorList.add(V);

+ 1 - 1
elab-db/src/main/java/com/elab/core/spring/config/TransactionConfigBean.java

@@ -26,6 +26,7 @@ public class TransactionConfigBean implements TransactionManagementConfigurer {
 
     @Override
     public PlatformTransactionManager annotationDrivenTransactionManager() {
+        System.out.println("====");
         return getDataSourceTransactionManager();
     }
 
@@ -35,7 +36,6 @@ public class TransactionConfigBean implements TransactionManagementConfigurer {
 //        return springUtils;
 //    }
 
-    @Bean
     public DataSourceTransactionManager getDataSourceTransactionManager() {
         DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
         transactionManager.setDataSource(dataSource);

+ 1 - 1
elab-es/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
elab-kafka/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 25 - 2
elab-log/pom.xml

@@ -7,12 +7,16 @@
     <parent>
         <groupId>com.elab.core</groupId>
         <artifactId>elab-parent</artifactId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
 
     <groupId>com.elab.log</groupId>
     <artifactId>elab-log</artifactId>
 
+    <properties>
+        <logback.version>1.2.10</logback.version>
+    </properties>
+
     <dependencies>
         <dependency>
             <groupId>com.elab.core</groupId>
@@ -40,7 +44,7 @@
         <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
-            <version>1.2.3</version>
+            <version>${logback.version}</version>
             <!--<scope>provided</scope>-->
         </dependency>
 
@@ -122,6 +126,25 @@
                     <target>1.8</target>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>3.3.0</version>
+                <configuration>
+                    <descriptorRefs>
+                        <descriptorRef>jar-with-dependencies</descriptorRef>
+                    </descriptorRefs>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>make-assembly</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
         </plugins>
     </build>
 

+ 3 - 2
elab-log/src/main/java/com/elab/log/asepct/LogResponseBodyAdvice.java

@@ -60,11 +60,12 @@ public class LogResponseBodyAdvice implements ResponseBodyAdvice {
      * @return
      */
     @Override
-    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
+    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType,
+        Class selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
         try {
             if (body != null) {
                 if (body instanceof Info) {
-                    Info info = (Info) body;
+                    Info info = (Info)body;
                     String currentMessageId = Cat.getCurrentMessageId();
                     Map<String, Object> extension = info.getExtension();
                     if (extension == null) {

+ 53 - 20
elab-log/src/main/java/com/elab/log/log4j/CatLogbackLog.java

@@ -18,19 +18,53 @@ import java.io.StringWriter;
  **/
 public class CatLogbackLog extends AppenderBase<ILoggingEvent> {
 
-    private final int lineLength = 200;
     private final String type = "Logback";
 
+    /**
+     * 字符达到多少长度进行换行
+     * <code>
+     *     <appender name="cat" class="com.elab.log.log4j.CatLogbackLog">
+     *         <newLineNumber>255</newLineNumber>
+     *         <maxCharNumber>2888</maxCharNumber>
+     *     </appender>
+     * </code>
+     *
+     */
+    private int newLineNumber = 200;
+    /**
+     * 字符达到多少长度则告警
+     */
+    private int maxCharNumber = 2000;
+
+    /**
+     * 字符超过最大长度
+     */
+    private String charOverflowName = "charOverflow";
+
+    public void setCharOverflowName(String charOverflowName) {
+        this.charOverflowName = charOverflowName;
+    }
+
+    public void setNewLineNumber(int newLineNumber) {
+        this.newLineNumber = newLineNumber;
+    }
+
+    public void setMaxCharNumber(int maxCharNumber) {
+        this.maxCharNumber = maxCharNumber;
+    }
+
     @Override
     protected void append(ILoggingEvent event) {
+        // 判断配置
         boolean isTraceMode = Cat.getManager().isTraceMode();
+
         Level level = event.getLevel();
+
         if (level.isGreaterOrEqual(Level.ERROR)) {
             this.logError(event);
         } else if (!isTraceMode) {
             this.logTrace(event);
         }
-
     }
 
     /**
@@ -55,7 +89,7 @@ public class CatLogbackLog extends AppenderBase<ILoggingEvent> {
      * @param event
      */
     private void logError(ILoggingEvent event) {
-        ThrowableProxy info = (ThrowableProxy) event.getThrowableProxy();
+        ThrowableProxy info = (ThrowableProxy)event.getThrowableProxy();
         if (info != null) {
             Throwable exception = info.getThrowable();
             Object message = event.getMessage();
@@ -70,21 +104,15 @@ public class CatLogbackLog extends AppenderBase<ILoggingEvent> {
 
     private void logTrace(ILoggingEvent event) {
         String name = event.getLevel().toString();
-        Object message = event.getMessage();
-        String data;
-        if (message instanceof Throwable) {
-            data = this.buildExceptionStack((Throwable) message);
-        } else {
-            data = event.getMessage().toString();
+        String message = event.getMessage();
+        int length = message.length();
+        if (length > maxCharNumber) {
+            // 将范围控制在20个区间范围内
+            int eventValue = Math.floorMod(length, 20);
+            Cat.logEvent(charOverflowName, eventValue + "");
         }
-// DEBUG 的异常不打印
-//        ThrowableProxy info = (ThrowableProxy) event.getThrowableProxy();
-//        if (info != null) {
-//            data = data + '\n' + this.buildExceptionStack(info.getThrowable());
-//            Cat.logError(data, info.getThrowable());
-//            return;
-//        }
-        Cat.logEvent(type, name, "0", formatShowData(data));
+
+        Cat.logEvent(type, name, "0", formatShowData(message));
     }
 
     /**
@@ -96,22 +124,27 @@ public class CatLogbackLog extends AppenderBase<ILoggingEvent> {
     public String formatShowData(String msg) {
         int length = msg.length();
 
+        int lineLength = newLineNumber;
+
         if (length < lineLength) {
             return msg;
         }
 
         int maxSplit = length / lineLength;
         int mo = length % lineLength;
+
         if (length % lineLength > 0) {
             maxSplit++;
         }
-        StringBuffer sb = new StringBuffer();
+
+        StringBuilder sb = new StringBuilder();
+
         for (int i = 0; i < maxSplit; i++) {
             int index = i * lineLength;
             if (maxSplit == (i + 1)) {
-                sb.append(msg.substring(index, index + mo) + "\n");
+                sb.append(msg, index, index + mo).append("\n");
             } else {
-                sb.append(msg.substring(index, index + lineLength) + "\n");
+                sb.append(msg, index, index + lineLength).append("\n");
             }
         }
         return sb.toString();

+ 20 - 0
elab-log/src/test/java/com/elab/log/log4j/CatLogbackLogTest.java

@@ -0,0 +1,20 @@
+package com.elab.log.log4j;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CatLogbackLogTest {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Test
+    public void testAppend() {
+        int number = Math.floorMod(2888, 20);
+        int n2 = 2888 % 20;
+        System.out.println(number + "\t" + n2);
+        logger.info("这是一个测试");
+
+        logger.error(" 测试异常 ", new NullPointerException());
+
+    }
+}

+ 4 - 3
elab-log/src/test/resources/logback.xml

@@ -3,7 +3,7 @@
     <include resource="org/springframework/boot/logging/logback/base.xml"/>
     <jmxConfigurator/>
     <property name="LOG_PATH" value="logs"/>
-    <property name="APPLICATION" value="elab-log" />
+    <property name="APPLICATION" value="elab-log"/>
 
     <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
         <encoder charset="UTF-8">
@@ -16,11 +16,12 @@
     </logger>
 
     <appender name="cat" class="com.elab.log.log4j.CatLogbackLog">
-
+        <newLineNumber>255</newLineNumber>
+        <maxCharNumber>2888</maxCharNumber>
     </appender>
 
     <root level="INFO">
-<!--        <appender-ref ref="cat"/>-->
+        <!--        <appender-ref ref="cat"/>-->
         <appender-ref ref="stdout"/>
     </root>
 

+ 1 - 1
elab-mongodb/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
elab-mq/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 14 - 0
elab-redis/README.md

@@ -147,6 +147,20 @@ spring.redis.elab.config-refresh.enable: true
 
 此时会注册 : `RedisRefreshConfigure` 配置
 
+
+
+直接使用: 
+
+当你类中的某个变量希望与Redis中的key进行绑定时,请在类中加入
+
+```java
+@Scope(CacheConstants.REFRESH_CONFIG_SCOPE_NAME)
+```
+
+
+
+
+
 大概流程图:
 
 ![image-20210901172831387](https://gitee.com/liukaixiong/drawing-bed/raw/master/image/image-20210901172831387.png)

+ 1 - 1
elab-redis/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 1 - 1
elab-rocketMQ/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 10 - 6
elab-spring/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
@@ -80,24 +80,28 @@
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-core</artifactId>
+            <optional>true</optional>
         </dependency>
 
         <!-- context -->
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
+            <optional>true</optional>
         </dependency>
 
         <!-- context -->
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context-support</artifactId>
+            <optional>true</optional>
         </dependency>
 
         <!-- jdbc -->
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-jdbc</artifactId>
+            <optional>true</optional>
             <scope>provided</scope>
         </dependency>
 
@@ -105,30 +109,35 @@
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-tx</artifactId>  <!--spring transaction-->
+            <optional>true</optional>
         </dependency>
 
         <!-- beans -->
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-beans</artifactId>
+            <optional>true</optional>
         </dependency>
 
         <!-- aop -->
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-aop</artifactId>
+            <optional>true</optional>
         </dependency>
 
         <!-- webmvc -->
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-webmvc</artifactId>
+            <optional>true</optional>
         </dependency>
 
         <!-- web -->
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-web</artifactId>
+            <optional>true</optional>
         </dependency>
         <!--<dependency>-->
         <!--<groupId>com.elab.core</groupId>-->
@@ -158,11 +167,6 @@
             <artifactId>springfox-swagger-ui</artifactId>
             <scope>compile</scope>
         </dependency>
-        <dependency>
-            <groupId>javax.validation</groupId>
-            <artifactId>validation-api</artifactId>
-            <scope>compile</scope>
-        </dependency>
         <dependency>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-validator</artifactId>

+ 9 - 5
elab-spring/src/main/java/com/elab/spring/anno/AuthorDescription.java

@@ -26,21 +26,24 @@ public @interface AuthorDescription {
      *
      * @return
      */
-    @AliasFor(annotation = Author.class, attribute = "nickname") String[] nickname() default {};
+    @AliasFor(annotation = Author.class,
+        attribute = "nickname") String[] nickname() default {};
 
     /**
      * 功能描述
      *
      * @return
      */
-    @AliasFor(annotation = Description.class, attribute = "describe") String describe();
+    @AliasFor(annotation = Description.class,
+        attribute = "describe") String describe();
 
     /**
      * 模块名称
      *
      * @return
      */
-    @AliasFor(annotation = Description.class, attribute = "modulesName") String modulesName();
+    @AliasFor(annotation = Description.class,
+        attribute = "modulesName") String modulesName();
 
     /**
      * 查找索引,可以通过参数中的内容来定义,方便通过控制台来搜索内容
@@ -65,11 +68,12 @@ public @interface AuthorDescription {
      * userModel.setUsername("liukx");
      * <p>
      * String test = testAnnotation.test(request, userModel);
-     *
+     * <p>
      * 得到结果: 1314-liukx
      *
      * </code>
      */
-    @AliasFor(annotation = Description.class, attribute = "searchKey") String searchKey();
+    @AliasFor(annotation = Description.class,
+        attribute = "searchKey") String searchKey();
 
 }

+ 56 - 56
elab-spring/src/main/java/com/elab/spring/componts/endpoints/CatEndpoint.java

@@ -1,56 +1,56 @@
-package com.elab.spring.componts.endpoints;
-
-import com.dianping.cat.message.io.DefaultMessageQueue;
-import com.dianping.cat.message.io.TcpSocketSender;
-import com.dianping.cat.message.spi.MessageTree;
-import com.elab.spring.utils.SpringUtils;
-import org.codehaus.plexus.PlexusContainer;
-import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
-import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
-import org.unidal.initialization.DefaultModuleContext;
-import org.unidal.initialization.ModuleContext;
-import org.unidal.lookup.ContainerLoader;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-
-/**
- * Cat排查端点暴露
- *
- * @author liukaixiong
- * @Email liukx@elab-plus.com
- * @date 2021/9/6 - 13:45
- */
-@Endpoint(id = "cat")
-public class CatEndpoint {
-
-    @ReadOperation
-    public Object analyseLocalQueue() {
-        PlexusContainer container = ContainerLoader.getDefaultContainer();
-        ModuleContext ctx = new DefaultModuleContext(container);
-        TcpSocketSender tcpSocketSender = ctx.lookup(TcpSocketSender.class);
-        DefaultMessageQueue atomicQueue =
-            SpringUtils.getFieldObjectValue(tcpSocketSender.getClass(), "m_atomicQueue", DefaultMessageQueue.class);
-
-        BlockingQueue m_queue = SpringUtils.getFieldObjectValue(atomicQueue.getClass(), "m_queue", BlockingQueue.class);
-
-        List<MessageTree> messageTrees = new ArrayList<>();
-
-        m_queue.drainTo(messageTrees);
-        // todo 未完成,目的是希望在队列满了的时候,分析队列中到底是哪些埋点造成的。
-        Map<String, Map<String, Object>> resultMap = new HashMap<>();
-
-        return null;
-        //        messageTrees.forEach((tree) -> {
-        //            String type = tree.getMessage().getType();
-        //            String name = tree.getMessage().getName();
-        //            String key = type + "-" + name;
-        //            Map<String, Object> map = resultMap.computeIfAbsent(key, k -> new HashMap<>());
-        //
-        //        });
-    }
-
-}
+//package com.elab.spring.componts.endpoints;
+//
+//import com.dianping.cat.message.io.DefaultMessageQueue;
+//import com.dianping.cat.message.io.TcpSocketSender;
+//import com.dianping.cat.message.spi.MessageTree;
+//import com.elab.spring.utils.SpringUtils;
+//import org.codehaus.plexus.PlexusContainer;
+//import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
+//import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
+//import org.unidal.initialization.DefaultModuleContext;
+//import org.unidal.initialization.ModuleContext;
+//import org.unidal.lookup.ContainerLoader;
+//
+//import java.util.ArrayList;
+//import java.util.HashMap;
+//import java.util.List;
+//import java.util.Map;
+//import java.util.concurrent.BlockingQueue;
+//
+///**
+// * Cat排查端点暴露
+// *
+// * @author liukaixiong
+// * @Email liukx@elab-plus.com
+// * @date 2021/9/6 - 13:45
+// */
+//@Endpoint(id = "cat")
+//public class CatEndpoint {
+//
+//    @ReadOperation
+//    public Object analyseLocalQueue() {
+//        PlexusContainer container = ContainerLoader.getDefaultContainer();
+//        ModuleContext ctx = new DefaultModuleContext(container);
+//        TcpSocketSender tcpSocketSender = ctx.lookup(TcpSocketSender.class);
+//        DefaultMessageQueue atomicQueue =
+//            SpringUtils.getFieldObjectValue(tcpSocketSender.getClass(), "m_atomicQueue", DefaultMessageQueue.class);
+//
+//        BlockingQueue m_queue = SpringUtils.getFieldObjectValue(atomicQueue.getClass(), "m_queue", BlockingQueue.class);
+//
+//        List<MessageTree> messageTrees = new ArrayList<>();
+//
+//        m_queue.drainTo(messageTrees);
+//        // todo 未完成,目的是希望在队列满了的时候,分析队列中到底是哪些埋点造成的。
+//        Map<String, Map<String, Object>> resultMap = new HashMap<>();
+//
+//        return null;
+//        //        messageTrees.forEach((tree) -> {
+//        //            String type = tree.getMessage().getType();
+//        //            String name = tree.getMessage().getName();
+//        //            String key = type + "-" + name;
+//        //            Map<String, Object> map = resultMap.computeIfAbsent(key, k -> new HashMap<>());
+//        //
+//        //        });
+//    }
+//
+//}

+ 40 - 40
elab-spring/src/main/java/com/elab/spring/intercept/AuthorDescriptionAnnotationProcess.java

@@ -16,48 +16,48 @@ import java.lang.reflect.Method;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-    /**
-     * 对于功能定义的一些拦截描述
-     *
-     * @author liukaixiong
-     * @Email liukx@elab-plus.com
-     * @date 2021/9/27 - 11:10
-     */
-    public class AuthorDescriptionAnnotationProcess implements AnnotationProcessService {
-        private Logger logger = LoggerFactory.getLogger(getClass());
-        @Autowired
-        private DefaultExpression defaultExpression;
+/**
+ * 对于功能定义的一些拦截描述
+ *
+ * @author liukaixiong
+ * @Email liukx@elab-plus.com
+ * @date 2021/9/27 - 11:10
+ */
+public class AuthorDescriptionAnnotationProcess implements AnnotationProcessService {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+    @Autowired
+    private DefaultExpression defaultExpression;
 
-        @Override
-        public Class<? extends Annotation> annotation() {
-            return AuthorDescription.class;
-        }
-
-        @Override
-        public Object invokeWithinTransaction(ReflectiveMethodInvocation invocation) throws Throwable {
-            Method method = invocation.getMethod();
-            AuthorDescription authorDescription = AnnotationUtils.getAnnotation(method, AuthorDescription.class);
-            String clazzName = method.getDeclaringClass().getSimpleName();
-            String name = method.getName();
-            String methodName = clazzName + "." + name;
-            Object[] arguments = invocation.getArguments();
-            Map<String, Object> request = new LinkedHashMap<>();
-            request.put("request", arguments);
+    @Override
+    public Class<? extends Annotation> annotation() {
+        return AuthorDescription.class;
+    }
 
-            // 用于关键搜索
-            String searchKey = authorDescription.searchKey();
-            if (!StringUtils.isEmpty(searchKey)) {
-                searchKey = defaultExpression.getValue(request, searchKey, String.class);
-            }
+    @Override
+    public Object invokeWithinTransaction(ReflectiveMethodInvocation invocation) throws Throwable {
+        Method method = invocation.getMethod();
+        AuthorDescription authorDescription = AnnotationUtils.getAnnotation(method, AuthorDescription.class);
+        String clazzName = method.getDeclaringClass().getSimpleName();
+        String name = method.getName();
+        String methodName = clazzName + "." + name;
+        Object[] arguments = invocation.getArguments();
+        Map<String, Object> request = new LinkedHashMap<>();
+        request.put("request", arguments);
 
-            // 发送数据埋点
-            return MonitorCollect.SERVICE.send(authorDescription.nickname(), methodName, authorDescription.modulesName(),
-                authorDescription.describe(), searchKey, request, () -> {
-                    try {
-                        return invocation.proceed();
-                    } catch (Throwable throwable) {
-                        throw new Exception(throwable);
-                    }
-                });
+        // 用于关键搜索
+        String searchKey = authorDescription.searchKey();
+        if (!StringUtils.isEmpty(searchKey)) {
+            searchKey = defaultExpression.getValue(request, searchKey, String.class);
         }
+
+        // 发送数据埋点
+        return MonitorCollect.SERVICE.send(authorDescription.nickname(), methodName, authorDescription.modulesName(),
+            authorDescription.describe(), searchKey, request, () -> {
+                try {
+                    return invocation.proceed();
+                } catch (Throwable throwable) {
+                    throw new Exception(throwable);
+                }
+            });
     }
+}

+ 17 - 12
elab-spring/src/main/java/com/elab/spring/intercept/CheckAnnotationProcess.java

@@ -9,9 +9,11 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.aop.support.AopUtils;
 import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
 import org.springframework.beans.factory.config.BeanPostProcessor;
 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+import org.springframework.context.EnvironmentAware;
 import org.springframework.core.env.Environment;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -22,31 +24,32 @@ import java.lang.reflect.Method;
  * @Author : liukx
  * @time : 2019/3/6 - 11:44
  */
-public class CheckAnnotationProcess implements BeanPostProcessor, BeanFactoryPostProcessor {
+public class CheckAnnotationProcess implements BeanPostProcessor, EnvironmentAware, InitializingBean {
 
-    private Logger logger = LoggerFactory.getLogger(com.elab.spring.intercept.CheckAnnotationProcess.class);
+    private Logger logger = LoggerFactory.getLogger(CheckAnnotationProcess.class);
     private ConfigurableListableBeanFactory beanFactory;
 
     private Environment environment;
+
     private boolean isException = false;
     /**
      * 排除不需要扫描验证的包名
      */
     private String excludePackage;
 
-    public CheckAnnotationProcess(Environment environment) {
-        this.environment = environment;
-        this.isException = ObjectUtils.isNotEmpty(environment.getProperty("elab.isException")) ? Boolean.parseBoolean(environment.getProperty("elab.isException")) : false;
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        this.isException = this.environment.getProperty("elab.isException", Boolean.class, false);
         this.excludePackage = environment.getProperty("elab.excludePackage", "");
     }
 
-    public void setException(boolean exception) {
-        isException = exception;
+    @Override
+    public void setEnvironment(Environment environment) {
+        this.environment = environment;
     }
 
-    @Override
-    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
-        this.beanFactory = beanFactory;
+    public void setException(boolean exception) {
+        isException = exception;
     }
 
     @Override
@@ -93,11 +96,13 @@ public class CheckAnnotationProcess implements BeanPostProcessor, BeanFactoryPos
                 ExceptionHandle exceptionHandle = declaredMethod.getAnnotation(ExceptionHandle.class);
                 if (exceptionHandle != null) {
                     if (StringUtils.isEmpty(exceptionHandle.username())) {
-                        String message = "请在" + name + " \t " + declaredMethod.getName() + " --> " + author + " 方法头的@ExceptionHandle 加上username属性";
+                        String message = "请在" + name + " \t " + declaredMethod.getName() + " --> " + author
+                            + " 方法头的@ExceptionHandle 加上username属性";
                         notifyWarning(message);
                     }
                 } else {
-                    String message = "请在" + name + " \t " + declaredMethod.getName() + " --> " + author + " 方法头加上 @ExceptionHandle(username = '')";
+                    String message = "请在" + name + " \t " + declaredMethod.getName() + " --> " + author
+                        + " 方法头加上 @ExceptionHandle(username = '')";
                     notifyWarning(message);
                 }
             }

+ 7 - 8
elab-spring/src/main/java/com/elab/spring/utils/RestTemplateUtils.java

@@ -32,7 +32,6 @@ import java.util.Map;
  **/
 public class RestTemplateUtils {
 
-
     private Logger logger = LoggerFactory.getLogger(RestTemplateUtils.class);
     public RestTemplate restTemplate;
 
@@ -91,13 +90,14 @@ public class RestTemplateUtils {
         // 读取超时
         requestFactory.setReadTimeout(getReadTimeout());
 
-//        restTemplate = new RestTemplate(requestFactory);
+        //        restTemplate = new RestTemplate(requestFactory);
         restTemplate = new RestTemplate(requestFactory);
-//         替换String的默认字符集
+        //         替换String的默认字符集
         restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
 
         //get请求适配body的请求工厂,内部采用httpclient
-        HttpComponentsClientRestfulHttpRequestFactory getRequestFactory = new HttpComponentsClientRestfulHttpRequestFactory();
+        HttpComponentsClientRestfulHttpRequestFactory getRequestFactory =
+            new HttpComponentsClientRestfulHttpRequestFactory();
         // 设置超时
         requestFactory.setConnectTimeout(getConnectTimeout());
         // 读取超时
@@ -108,7 +108,6 @@ public class RestTemplateUtils {
         //         替换String的默认字符集
         getRestTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
 
-
         //设置HTTP请求头信息,实现编码等
         headers = new HttpHeaders();
         MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
@@ -292,7 +291,7 @@ public class RestTemplateUtils {
             }
         } catch (Exception e) {
             if (!(e instanceof CoolingException)) {
-                logger.warn("第三方调用异常:"+e.getMessage());
+                logger.warn("第三方调用异常:" + e.getMessage());
             }
             t.setStatus(e.getClass().getSimpleName());
             if (restFallback != null) {
@@ -368,7 +367,7 @@ public class RestTemplateUtils {
             }
         } catch (Exception e) {
             if (!(e instanceof CoolingException)) {
-                logger.warn("第三方调用异常:"+ e.getMessage());
+                logger.warn("第三方调用异常:" + e.getMessage());
             }
             t.setStatus(e.getClass().getSimpleName());
             if (restFallback != null) {
@@ -411,7 +410,7 @@ public class RestTemplateUtils {
             }
             t.setStatus(Transaction.SUCCESS);
         } catch (Exception e) {
-            logger.warn("------ 第三方接口调用失败 : "+ e.getMessage());
+            logger.warn("------ 第三方接口调用失败 : " + e.getMessage());
             t.setStatus(e.getClass().getSimpleName());
         } finally {
             t.complete();

+ 1 - 1
elab-test/pom.xml

@@ -5,7 +5,7 @@
     <parent>
         <artifactId>elab-parent</artifactId>
         <groupId>com.elab.core</groupId>
-        <version>2.0.5.3-SNAPSHOT</version>
+        <version>4.0.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 

+ 114 - 0
elab-test/src/main/java/com/elab/test/guava/EventBusSample.java

@@ -0,0 +1,114 @@
+package com.elab.test.guava;
+
+import com.google.common.eventbus.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * EventBus 消息总线
+ *
+ * @author liukaixiong
+ * @Email liukx@elab-plus.com
+ * @date 2021/12/3 - 13:47
+ */
+public class EventBusSample {
+    private static Logger logger = LoggerFactory.getLogger(EventBusSample.class);
+
+    @Subscribe
+    public void A(AModel model) {
+        logger.info("A : " + model.toString());
+    }
+
+    @Subscribe
+    public void A1(AModel model) {
+        logger.info("A1 : " + model.toString());
+    }
+
+    @Subscribe
+    @AllowConcurrentEvents
+    public void B(BModel model) {
+        logger.info("B : " + model.toString());
+    }
+
+    @Subscribe
+    public void C(CModel model) {
+        logger.info("C : " + model.toString());
+    }
+
+    /**
+     * 这里代表死信事件,代表内部没有找到对应的订阅者
+     *
+     * @param event
+     */
+    @Subscribe
+    public void handle(DeadEvent event) {
+        //获取事件源
+        logger.info(event.getSource().toString());
+        //获取事件
+        logger.info(event.getEvent() + toString());
+    }
+
+    public static class AModel {
+        private String username;
+
+        public String getUsername() {
+            return username;
+        }
+
+        public void setUsername(String username) {
+            this.username = username;
+        }
+    }
+
+    public static class BModel {
+        private String username;
+
+        public String getUsername() {
+            return username;
+        }
+
+        public void setUsername(String username) {
+            this.username = username;
+        }
+    }
+
+    public static class CModel {
+        private String username;
+
+        public String getUsername() {
+            return username;
+        }
+
+        public void setUsername(String username) {
+            this.username = username;
+        }
+    }
+
+    public static class DModel extends AModel {
+
+    }
+
+    public static void main(String[] args) {
+        EventBus eventBus = new EventBus((exception, context) -> {
+            System.out.println(exception.getMessage());
+        });
+        logger.info("主线程开始A");
+        eventBus.register(new EventBusSample());
+        eventBus.post(new DModel());
+        eventBus.post(new BModel());
+        logger.info("主线程结束A");
+
+        ExecutorService executorService = Executors.newFixedThreadPool(5);
+        // 异步处理
+        AsyncEventBus asyncEventBus = new AsyncEventBus(executorService);
+        logger.info("主线程开始B");
+        asyncEventBus.register(new EventBusSample());
+        asyncEventBus.post(new DModel());
+        asyncEventBus.post(new BModel());
+        logger.info("主线程结束B");
+    }
+
+}

+ 21 - 0
elab-test/src/main/java/com/elab/test/guava/IpSample.java

@@ -0,0 +1,21 @@
+package com.elab.test.guava;
+
+import com.google.common.net.InetAddresses;
+
+import java.net.InetAddress;
+
+/**
+ * @author liukaixiong
+ * @Email liukx@elab-plus.com
+ * @date 2021/12/3 - 15:10
+ */
+public class IpSample {
+    public static void main(String[] args) {
+        String ip = "192.168.0.11";
+        InetAddress inetAddress = InetAddresses.forString(ip);
+        System.out.println(InetAddresses.coerceToInteger(inetAddress));
+        System.out.println(InetAddresses.toAddrString(inetAddress));
+
+    }
+
+}

+ 39 - 0
elab-test/src/main/java/com/elab/test/netty/HashedWheelTimerSample.java

@@ -0,0 +1,39 @@
+package com.elab.test.netty;
+
+import io.netty.util.HashedWheelTimer;
+import io.netty.util.Timeout;
+import io.netty.util.TimerTask;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 时间轮
+ *
+ * @author liukaixiong
+ * @Email liukx@elab-plus.com
+ * @date 2021/12/3 - 14:57
+ */
+public class HashedWheelTimerSample {
+
+    public static void main(String[] args) {
+        final HashedWheelTimer timer =
+            new HashedWheelTimer(Executors.defaultThreadFactory(), 100, TimeUnit.MILLISECONDS, 32);
+
+        timer.newTimeout(new TimerTask() {
+            @Override
+            public void run(final Timeout timeout) throws Exception {
+                System.out.println("lee");   //打印名字
+            }
+        }, 1000, TimeUnit.MILLISECONDS);
+
+        timer.newTimeout(new TimerTask() {
+            @Override
+            public void run(final Timeout timeout) throws Exception {
+                System.out.println("lee2");   //打印名字
+            }
+        }, 5000, TimeUnit.MILLISECONDS);
+
+        timer.start();
+    }
+}

+ 4 - 3
pom.xml

@@ -7,10 +7,10 @@
     <groupId>com.elab.core</groupId>
     <artifactId>elab-parent</artifactId>
     <packaging>pom</packaging>
-    <version>2.0.5.3-SNAPSHOT</version>
+    <version>4.0.0-SNAPSHOT</version>
     <modules>
         <module>elab-core</module>
-        <module>elab-cache</module>
+<!--        <module>elab-cache</module>-->
         <module>elab-log</module>
         <module>elab-spring</module>
         <module>elab-db</module>
@@ -49,6 +49,7 @@
             <dependency>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-autoconfigure-processor</artifactId>
+                <optional>true</optional>
                 <version>${springboot.version}</version>
             </dependency>
             <dependency>
@@ -335,7 +336,7 @@
             <dependency>
                 <groupId>com.jay.monitor.data</groupId>
                 <artifactId>jay-monitor-data-client</artifactId>
-                <version>1.1-SNAPSHOT</version>
+                <version>1.2-SNAPSHOT</version>
             </dependency>
         </dependencies>
     </dependencyManagement>