yangyoupeng

重构,增加LRU缓存

...@@ -7,13 +7,9 @@ import java.util.Collection; ...@@ -7,13 +7,9 @@ import java.util.Collection;
7 import java.util.List; 7 import java.util.List;
8 import java.util.concurrent.ConcurrentHashMap; 8 import java.util.concurrent.ConcurrentHashMap;
9 9
10 -import org.apache.catalina.loader.WebappClassLoader;
11 -import org.apache.catalina.loader.WebappClassLoaderBase;
12 import org.slf4j.Logger; 10 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
14 12
15 -import com.zhaoonline.support.gateway.servlet.ApiManagerServlet;
16 -
17 public enum ApiClassLoaderManager { 13 public enum ApiClassLoaderManager {
18 INSTANCE; 14 INSTANCE;
19 private static Logger LOG=LoggerFactory.getLogger(ApiClassLoaderManager.class); 15 private static Logger LOG=LoggerFactory.getLogger(ApiClassLoaderManager.class);
......
...@@ -3,12 +3,8 @@ package com.zhaoonline.support.gateway.apijar; ...@@ -3,12 +3,8 @@ package com.zhaoonline.support.gateway.apijar;
3 import java.io.File; 3 import java.io.File;
4 import java.io.FileFilter; 4 import java.io.FileFilter;
5 import java.io.IOException; 5 import java.io.IOException;
6 -import java.net.URISyntaxException;
7 -import java.net.URL;
8 -import java.net.URLClassLoader;
9 import java.nio.file.Path; 6 import java.nio.file.Path;
10 import java.nio.file.Paths; 7 import java.nio.file.Paths;
11 -import java.util.ArrayList;
12 import java.util.List; 8 import java.util.List;
13 import java.util.jar.JarFile; 9 import java.util.jar.JarFile;
14 import java.util.zip.ZipFile; 10 import java.util.zip.ZipFile;
......
1 package com.zhaoonline.support.gateway.apijar; 1 package com.zhaoonline.support.gateway.apijar;
2 2
3 -import java.io.File;
4 -import java.io.FileInputStream;
5 import java.io.FileNotFoundException; 3 import java.io.FileNotFoundException;
6 import java.io.IOException; 4 import java.io.IOException;
7 import java.io.InputStream; 5 import java.io.InputStream;
...@@ -12,8 +10,6 @@ import java.util.Properties; ...@@ -12,8 +10,6 @@ import java.util.Properties;
12 import org.slf4j.Logger; 10 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
14 import org.springframework.core.io.Resource; 12 import org.springframework.core.io.Resource;
15 -import org.springframework.util.ResourceUtils;
16 -
17 import com.zhaoonline.support.gateway.utils.IOUtils; 13 import com.zhaoonline.support.gateway.utils.IOUtils;
18 14
19 /** 15 /**
...@@ -78,7 +74,7 @@ public class ApiManagerConfiguration { ...@@ -78,7 +74,7 @@ public class ApiManagerConfiguration {
78 try { 74 try {
79 // File file = ResourceUtils.getFile(fileName); 75 // File file = ResourceUtils.getFile(fileName);
80 Resource file = IOUtils.getFile(fileName); 76 Resource file = IOUtils.getFile(fileName);
81 - LOG.info("ResourceUtils.getFile {} with fileNama{}",file,fileName); 77 + LOG.info("IOUtils.getFile {} with fileNama{}",file,fileName);
82 reader =file.getInputStream(); 78 reader =file.getInputStream();
83 propeties.load(reader); 79 propeties.load(reader);
84 Map<String, String> map = (Map)propeties; 80 Map<String, String> map = (Map)propeties;
......
...@@ -13,8 +13,6 @@ import java.util.ArrayList; ...@@ -13,8 +13,6 @@ import java.util.ArrayList;
13 import org.slf4j.Logger; 13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 14 import org.slf4j.LoggerFactory;
15 15
16 -import sun.tools.jar.resources.jar;
17 -
18 public class JarLoader { 16 public class JarLoader {
19 private static Logger LOGGER =LoggerFactory.getLogger(JarLoader.class); 17 private static Logger LOGGER =LoggerFactory.getLogger(JarLoader.class);
20 18
......
...@@ -19,7 +19,6 @@ import java.util.Set; ...@@ -19,7 +19,6 @@ import java.util.Set;
19 import org.slf4j.Logger; 19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory; 20 import org.slf4j.LoggerFactory;
21 21
22 -import com.zhaoonline.support.gateway.config.GWConstants;
23 import com.zhaoonline.support.gateway.listener.GWEventConstants; 22 import com.zhaoonline.support.gateway.listener.GWEventConstants;
24 import com.zhaoonline.support.gateway.listener.GWEventListenerRegistry; 23 import com.zhaoonline.support.gateway.listener.GWEventListenerRegistry;
25 import com.zhaoonline.support.gateway.listener.NewJarAddEvent; 24 import com.zhaoonline.support.gateway.listener.NewJarAddEvent;
......
...@@ -72,6 +72,22 @@ public enum ServiceManager{ ...@@ -72,6 +72,22 @@ public enum ServiceManager{
72 DubboService cachedService = (DubboService) dubboServiceCache.get(serviceName); 72 DubboService cachedService = (DubboService) dubboServiceCache.get(serviceName);
73 if(cachedService == null){ 73 if(cachedService == null){
74 LOG.info("no cache for dubbo service [{}],create new instance for service",serviceInfo.getServiceName()); 74 LOG.info("no cache for dubbo service [{}],create new instance for service",serviceInfo.getServiceName());
75 + return createNewDubboService(serviceInfo, config, serviceName);
76 + }else{
77 + LOG.info("get dubbo service from cache with key [{}]",serviceName);
78 + if(cachedService.isClosed()){
79 + LOG.info("the cached dubbo service interface {} is closed by {},just return null",serviceInfo.getServiceInterface(),LifeCycleCheckerManager.class.getName());
80 + dubboServiceCache.remove(serviceName);
81 + cachedService=null;
82 + return createNewDubboService(serviceInfo, config, serviceName);
83 + }
84 +
85 + }
86 + return cachedService;
87 + }
88 +
89 + private DubboService createNewDubboService(ServiceInfo serviceInfo, GateWayConfiguration config,
90 + String serviceName) {
75 DubboService dubboSerivce=new DubboService(serviceInfo); 91 DubboService dubboSerivce=new DubboService(serviceInfo);
76 try { 92 try {
77 dubboSerivce.init(); 93 dubboSerivce.init();
...@@ -84,15 +100,6 @@ public enum ServiceManager{ ...@@ -84,15 +100,6 @@ public enum ServiceManager{
84 LOG.info("cache dubbo service with key [{}]",serviceName); 100 LOG.info("cache dubbo service with key [{}]",serviceName);
85 dubboServiceCache.put(serviceName,dubboSerivce); 101 dubboServiceCache.put(serviceName,dubboSerivce);
86 return dubboSerivce; 102 return dubboSerivce;
87 - }else{
88 - LOG.info("get dubbo service from cache with key [{}]",serviceName);
89 - if(cachedService.isClosed()){
90 - LOG.info("the cached dubbo service interface {} is closed by {},just return null",serviceInfo.getServiceInterface(),LifeCycleCheckerManager.class.getName());
91 - dubboServiceCache.remove(serviceName);
92 - cachedService=null;
93 - }
94 - }
95 - return cachedService;
96 } 103 }
97 104
98 private void monitorStatus(DubboService dubboSerivce,GateWayConfiguration config) { 105 private void monitorStatus(DubboService dubboSerivce,GateWayConfiguration config) {
......
1 package com.zhaoonline.support.gateway.main; 1 package com.zhaoonline.support.gateway.main;
2 2
3 +import org.slf4j.LoggerFactory;
4 +
5 +import ch.qos.logback.classic.Logger;
3 6
4 public class ApplicationIT { 7 public class ApplicationIT {
5 public static void main(String[] args) throws InterruptedException { 8 public static void main(String[] args) throws InterruptedException {
6 Application.main(args); 9 Application.main(args);
10 + Logger root = (Logger)LoggerFactory.getLogger("com.zhaoonline");
11 + System.out.println("------getLevel().levelStr---------"+root.getLevel().levelStr);
12 + System.out.println("------appenderName---------"+root.getAppender("addfa").getName());
13 + root.warn("this is a test ");
14 + root.getAppender("addfa").addWarn("this is a test11111");
7 } 15 }
8 } 16 }
......