Ver código fonte

1. 优化知识库缓存实现
2. 优化依赖配置,避免启动时的日志配置异常

Chery 8 anos atrás
pai
commit
defe8dc433

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+.idea/
+*.iml
+urule-console/target/
+urule-core/target/
+urule-springboot/target/

+ 28 - 23
urule-core/src/main/java/com/bstek/urule/runtime/cache/MemoryKnowledgeCache.java

@@ -1,12 +1,12 @@
 /*******************************************************************************
  * Copyright 2017 Bstek
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License.  You may obtain a copy
  * of the License at
- * 
+ *
  *   http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
@@ -15,32 +15,37 @@
  ******************************************************************************/
 package com.bstek.urule.runtime.cache;
 
-import java.util.Hashtable;
-import java.util.Map;
-
 import com.bstek.urule.runtime.KnowledgePackage;
 
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
 /**
  * @author Jacky.gao
  * @since 2015年1月28日
  */
-public class MemoryKnowledgeCache implements KnowledgeCache{
-	private Map<String,Object> map=new Hashtable<String,Object>();
-	public KnowledgePackage getKnowledge(String packageId) {
-		if(packageId.startsWith("/")){
-			packageId=packageId.substring(1,packageId.length());
-		}
-		return (KnowledgePackage)map.get(packageId);
-	}
+public class MemoryKnowledgeCache implements KnowledgeCache {
+
+    private Map<String, KnowledgePackage> map = new ConcurrentHashMap<String, KnowledgePackage>();
+
+    @Override
+    public KnowledgePackage getKnowledge(String packageId) {
+        if (packageId.startsWith("/")) {
+            packageId = packageId.substring(1, packageId.length());
+        }
+        return map.get(packageId);
+    }
 
-	public void putKnowledge(String packageId,KnowledgePackage knowledgePackage) {
-		if(packageId.startsWith("/")){
-			packageId=packageId.substring(1,packageId.length());
-		}
-		map.put(packageId, knowledgePackage);
-	}
+    @Override
+    public void putKnowledge(String packageId, KnowledgePackage knowledgePackage) {
+        if (packageId.startsWith("/")) {
+            packageId = packageId.substring(1, packageId.length());
+        }
+        map.put(packageId, knowledgePackage);
+    }
 
-	public void removeKnowledge(String packageId) {
-		map.remove(packageId);
-	}
+    @Override
+    public void removeKnowledge(String packageId) {
+        map.remove(packageId);
+    }
 }

+ 85 - 80
urule-springboot/pom.xml

@@ -1,84 +1,89 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-	<modelVersion>4.0.0</modelVersion>
-	<groupId>com.bstek.urule</groupId>
-	<artifactId>urule-springboot</artifactId>
-	<version>0.0.1-SNAPSHOT</version>
-	<properties>
-		<java.version>1.7</java.version>
-		<tomcat.version>8.5.5</tomcat.version>
-		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-	</properties>
-	<licenses>
-		<license>
-			<name>The Apache License, Version 2.0</name>
-			<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
-		</license>
-	</licenses>
-	<developers>
-		<developer>
-			<name>Gaojie</name>
-			<email>jacky.gao@bstek.com</email>
-			<organization>Bstek</organization>
-			<organizationUrl>http://www.bstek.com</organizationUrl>
-		</developer>
-	</developers>
-	<scm>
-		<connection>https://github.com/youseries/urule.git</connection>
-		<developerConnection>https://github.com/youseries/urule.git</developerConnection>
-		<url>https://github.com/youseries/urule</url>
-	</scm>
-	<organization>
-		<name>Bstek</name>
-		<url>http://www.bstek.com</url>
-	</organization>  	
-	<parent>
-	    <groupId>org.springframework.boot</groupId>
-	    <artifactId>spring-boot-starter-parent</artifactId>
-	    <version>1.5.8.RELEASE</version>
-	</parent>
-	<dependencies>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-web</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>com.bstek.urule</groupId>
-			<artifactId>urule-console</artifactId>
-			<version>2.1.1-SNAPSHOT</version>
-		</dependency>
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.bstek.urule</groupId>
+    <artifactId>urule-springboot</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <properties>
+        <java.version>1.7</java.version>
+        <tomcat.version>8.5.5</tomcat.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+    <licenses>
+        <license>
+            <name>The Apache License, Version 2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+        </license>
+    </licenses>
+    <developers>
+        <developer>
+            <name>Gaojie</name>
+            <email>jacky.gao@bstek.com</email>
+            <organization>Bstek</organization>
+            <organizationUrl>http://www.bstek.com</organizationUrl>
+        </developer>
+    </developers>
+    <scm>
+        <connection>https://github.com/youseries/urule.git</connection>
+        <developerConnection>https://github.com/youseries/urule.git</developerConnection>
+        <url>https://github.com/youseries/urule</url>
+    </scm>
+    <organization>
+        <name>Bstek</name>
+        <url>http://www.bstek.com</url>
+    </organization>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>1.5.8.RELEASE</version>
+    </parent>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.bstek.urule</groupId>
+            <artifactId>urule-console</artifactId>
+            <version>2.1.1-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.slf4j</groupId>
+                    <artifactId>slf4j-jdk14</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>javax.servlet</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>2.5</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
 
-		<dependency>
-			<groupId>javax.servlet</groupId>
-			<artifactId>servlet-api</artifactId>
-			<version>2.5</version>
-			<scope>provided</scope>
-		</dependency>
-	</dependencies>
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.springframework.boot</groupId>
-				<artifactId>spring-boot-maven-plugin</artifactId>
-			</plugin>
-		</plugins>
-	</build>
+    <distributionManagement>
+        <snapshotRepository>
+            <id>ossrh</id>
+            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+        </snapshotRepository>
+        <repository>
+            <id>ossrh</id>
+            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
+        </repository>
+    </distributionManagement>
 
-	<distributionManagement>
-		<snapshotRepository>
-			<id>ossrh</id>
-			<url>https://oss.sonatype.org/content/repositories/snapshots</url>
-		</snapshotRepository>
-		<repository>
-			<id>ossrh</id>
-			<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
-		</repository>
-	</distributionManagement>
-
-	<name>Urule Springboot Project</name>
-	<url>https://github.com/youseries/urule/tree/master/urule-springboot</url>
-	<issueManagement>
-		<url>https://github.com/youseries/urule/issues</url>
-	</issueManagement>
-	<description>Urule Springboot Project</description>  
+    <name>Urule Springboot Project</name>
+    <url>https://github.com/youseries/urule/tree/master/urule-springboot</url>
+    <issueManagement>
+        <url>https://github.com/youseries/urule/issues</url>
+    </issueManagement>
+    <description>Urule Springboot Project</description>
 </project>

+ 2 - 4
urule-springboot/src/main/java/com/bstek/urule/springboot/Application.java

@@ -1,16 +1,14 @@
 package com.bstek.urule.springboot;
 
 import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.context.annotation.ComponentScan;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ImportResource;
 
 /**
  * @author Jacky.gao
  * @since 2016年10月12日
  */
-@ComponentScan
-@EnableAutoConfiguration
+@SpringBootApplication
 @ImportResource({"classpath:urule-console-context.xml"})
 public class Application {
 	public static void main(String[] args) {