Răsfoiți Sursa

在springboot环境下启动时加载配置
监控队列的线程安全问题修复

bryan.zhang 6 ani în urmă
părinte
comite
311fe14868

+ 4 - 4
liteflow-core/src/main/java/com/thebeastshop/liteflow/spring/ComponentScaner.java

@@ -22,15 +22,15 @@ import com.thebeastshop.liteflow.entity.config.Node;
 import com.thebeastshop.liteflow.util.LOGOPrinter;
 
 public class ComponentScaner implements BeanPostProcessor, PriorityOrdered {
-	
+
 	private static final Logger LOG = LoggerFactory.getLogger(ComponentScaner.class);
-	
+
 	public static Map<String, NodeComponent> nodeComponentMap = new HashMap<String, NodeComponent>();
 
 	static {
 		LOGOPrinter.print();
 	}
-	
+
 	@Override
 	public int getOrder() {
 		return Ordered.LOWEST_PRECEDENCE;
@@ -48,7 +48,7 @@ public class ComponentScaner implements BeanPostProcessor, PriorityOrdered {
 		}
 		return bean;
 	}
-	
+
 	@Override
 	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
 		return bean;

+ 4 - 3
liteflow-core/src/main/java/com/thebeastshop/liteflow/util/LimitQueue.java

@@ -13,6 +13,7 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
 
 public class LimitQueue<E> implements Queue<E> {
 
@@ -21,7 +22,7 @@ public class LimitQueue<E> implements Queue<E> {
 	 */
 	private int limit;
 
-	Queue<E> queue = new LinkedList<E>();
+	Queue<E> queue = new ConcurrentLinkedQueue<>();
 
 	public LimitQueue(int limit) {
 		this.limit = limit;
@@ -49,7 +50,7 @@ public class LimitQueue<E> implements Queue<E> {
 
 	/**
 	 * 获取队列
-	 * 
+	 *
 	 * @return
 	 * @author SHANHY
 	 * @date 2015年11月9日
@@ -60,7 +61,7 @@ public class LimitQueue<E> implements Queue<E> {
 
 	/**
 	 * 获取限制大小
-	 * 
+	 *
 	 * @return
 	 * @author SHANHY
 	 * @date 2015年11月9日

+ 0 - 7
liteflow-spring-boot-starter/src/main/java/com/thebeastshop/liteflow/springboot/LiteflowAutoConfiguration.java

@@ -4,16 +4,9 @@ import com.google.common.collect.Lists;
 import com.thebeastshop.liteflow.core.FlowExecutor;
 import com.thebeastshop.liteflow.spring.ComponentScaner;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Component;
 
 import java.util.List;
 

+ 15 - 0
liteflow-spring-boot-starter/src/main/java/com/thebeastshop/liteflow/springboot/LiteflowExecutorInit.java

@@ -0,0 +1,15 @@
+package com.thebeastshop.liteflow.springboot;
+
+import com.thebeastshop.liteflow.core.FlowExecutor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class LiteflowExecutorInit {
+
+    @Bean
+    public String initExecutor(FlowExecutor flowExecutor){
+        flowExecutor.init();
+        return "init";
+    }
+}

+ 4 - 1
liteflow-spring-boot-starter/src/main/resources/META-INF/spring.factories

@@ -1,3 +1,6 @@
 org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
   com.thebeastshop.liteflow.springboot.LiteflowProperty,\
-  com.thebeastshop.liteflow.springboot.LiteflowAutoConfiguration
+  com.thebeastshop.liteflow.springboot.LiteflowAutoConfiguration,\
+  com.thebeastshop.liteflow.springboot.LiteflowExecutorInit
+
+