This commit is contained in:
Redkale
2016-08-27 15:07:34 +08:00
parent bfe78a805e
commit 4647545ff5
4 changed files with 22 additions and 35 deletions

View File

@@ -79,7 +79,8 @@
host: 服务所占address 默认: 0.0.0.0
port: required 服务所占端口
root: 如果是web类型服务则包含页面 默认:{APP_HOME}/root
lib: server额外的class目录 默认为空
lib: server额外的class目录 默认为空
excludelibs: 排除lib.path与excludes中的正则表达式匹配的路径, 多个正则表达式用分号;隔开
charset: 文本编码, 默认: UTF-8
backlog: 默认10K
threads 线程总数, 默认: CPU核数*16

View File

@@ -475,7 +475,7 @@ public final class Application {
synchronized (nodeClasses) {
if (!inited.getAndSet(true)) { //加载自定义的协议SOCKS
ClassFilter profilter = new ClassFilter(NodeProtocol.class, NodeServer.class);
ClassFilter.Loader.load(home, profilter);
ClassFilter.Loader.load(home, serconf.getValue("excludelibs", "").split(";"), profilter);
final Set<FilterEntry<NodeServer>> entrys = profilter.getFilterEntrys();
for (FilterEntry<NodeServer> entry : entrys) {
final Class<? extends NodeServer> type = entry.getType();

View File

@@ -421,18 +421,30 @@ public final class ClassFilter<T> {
/**
* 加载当前线程的classpath扫描所有class进行过滤
*
* @param exclude 不需要扫描的文件夹, 可以为null
* @param filters 过滤器
* @param excludeFile 不需要扫描的文件夹, 可以为null
* @param excludeRegs 包含此关键字的文件将被跳过, 可以为null
* @param filters 过滤器
*
* @throws IOException 异常
*/
public static void load(final File exclude, final ClassFilter... filters) throws IOException {
public static void load(final File excludeFile, final String[] excludeRegs, final ClassFilter... filters) throws IOException {
URLClassLoader loader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
List<URL> urlfiles = new ArrayList<>(2);
List<URL> urljares = new ArrayList<>(2);
final URL exurl = exclude != null ? exclude.toURI().toURL() : null;
final URL exurl = excludeFile != null ? excludeFile.toURI().toURL() : null;
final Pattern[] excludePatterns = toPattern(excludeRegs);
for (URL url : loader.getURLs()) {
if (exurl != null && exurl.sameFile(url)) continue;
if (excludePatterns != null) {
boolean skip = false;
for (Pattern p : excludePatterns) {
if (p.matcher(url.toString()).matches()) {
skip = false;
break;
}
}
if (skip) continue;
}
if (url.getPath().endsWith(".jar")) {
urljares.add(url);
} else {
@@ -477,7 +489,7 @@ public final class ClassFilter<T> {
files.clear();
File root = new File(url.getFile());
String rootpath = root.getPath();
loadClassFiles(exclude, root, files);
loadClassFiles(excludeFile, root, files);
for (File f : files) {
String classname = f.getPath().substring(rootpath.length() + 1, f.getPath().length() - 6).replace(File.separatorChar, '.');
if (classname.startsWith("javax.") || classname.startsWith("com.sun.")) continue;

View File

@@ -27,32 +27,6 @@ import org.redkale.service.*;
import org.redkale.source.*;
import org.redkale.util.AnyValue.DefaultAnyValue;
import org.redkale.util.*;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
import static java.lang.Class.forName;
/**
* Server节点的初始化配置类
@@ -200,9 +174,9 @@ public abstract class NodeServer {
ClassFilter<Service> serviceFilter = createServiceClassFilter();
long s = System.currentTimeMillis();
if (servletFilter == null) {
ClassFilter.Loader.load(application.getHome(), serviceFilter);
ClassFilter.Loader.load(application.getHome(), serverConf.getValue("excludelibs", "").split(";"), serviceFilter);
} else {
ClassFilter.Loader.load(application.getHome(), serviceFilter, servletFilter);
ClassFilter.Loader.load(application.getHome(), serverConf.getValue("excludelibs", "").split(";"), serviceFilter, servletFilter);
}
long e = System.currentTimeMillis() - s;
logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");