This commit is contained in:
@@ -41,9 +41,16 @@ public final class ClassFilter<T> {
|
|||||||
|
|
||||||
private List<ClassFilter> ands;
|
private List<ClassFilter> ands;
|
||||||
|
|
||||||
|
private AnyValue conf;
|
||||||
|
|
||||||
public ClassFilter(Class<? extends Annotation> annotationClass, Class superClass) {
|
public ClassFilter(Class<? extends Annotation> annotationClass, Class superClass) {
|
||||||
|
this(annotationClass, superClass, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassFilter(Class<? extends Annotation> annotationClass, Class superClass, AnyValue conf) {
|
||||||
this.annotationClass = annotationClass;
|
this.annotationClass = annotationClass;
|
||||||
this.superClass = superClass;
|
this.superClass = superClass;
|
||||||
|
this.conf = conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassFilter<T> or(ClassFilter<T> filter) {
|
public ClassFilter<T> or(ClassFilter<T> filter) {
|
||||||
@@ -90,6 +97,11 @@ public final class ClassFilter<T> {
|
|||||||
try {
|
try {
|
||||||
Class clazz = Class.forName(clazzname);
|
Class clazz = Class.forName(clazzname);
|
||||||
if (accept(property, clazz, autoscan)) {
|
if (accept(property, clazz, autoscan)) {
|
||||||
|
if (conf != null) {
|
||||||
|
if (property == null) {
|
||||||
|
property = conf;
|
||||||
|
}
|
||||||
|
}
|
||||||
entrys.add(new FilterEntry(clazz, property));
|
entrys.add(new FilterEntry(clazz, property));
|
||||||
}
|
}
|
||||||
} catch (Throwable cfe) {
|
} catch (Throwable cfe) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public final class NodeHttpServer extends NodeServer {
|
|||||||
ClassFilter.Loader.load(home, serviceFilter, httpFilter);
|
ClassFilter.Loader.load(home, serviceFilter, httpFilter);
|
||||||
long e = System.currentTimeMillis() - s;
|
long e = System.currentTimeMillis() - s;
|
||||||
logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");
|
logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");
|
||||||
loadService(config.getAnyValue("services"), serviceFilter); //必须在servlet之前
|
loadService(serviceFilter); //必须在servlet之前
|
||||||
initWebSocketService();
|
initWebSocketService();
|
||||||
if (server != null) loadHttpServlet(config.getAnyValue("servlets"), httpFilter);
|
if (server != null) loadHttpServlet(config.getAnyValue("servlets"), httpFilter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.wentch.redkale.boot.ClassFilter.FilterEntry;
|
|||||||
import com.wentch.redkale.net.*;
|
import com.wentch.redkale.net.*;
|
||||||
import com.wentch.redkale.source.*;
|
import com.wentch.redkale.source.*;
|
||||||
import com.wentch.redkale.util.*;
|
import com.wentch.redkale.util.*;
|
||||||
|
import com.wentch.redkale.util.AnyValue.DefaultAnyValue;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
@@ -186,7 +187,7 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected void loadService(final AnyValue servicesConf, ClassFilter serviceFilter) throws Exception {
|
protected void loadService(ClassFilter serviceFilter) throws Exception {
|
||||||
if (serviceFilter == null) return;
|
if (serviceFilter == null) return;
|
||||||
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
final String threadName = "[" + Thread.currentThread().getName() + "] ";
|
||||||
final Set<FilterEntry<Service>> entrys = serviceFilter.getFilterEntrys();
|
final Set<FilterEntry<Service>> entrys = serviceFilter.getFilterEntrys();
|
||||||
@@ -287,14 +288,20 @@ public abstract class NodeServer {
|
|||||||
|
|
||||||
protected static ClassFilter createClassFilter(final String localGroup, final AnyValue config, Class<? extends Annotation> ref,
|
protected static ClassFilter createClassFilter(final String localGroup, final AnyValue config, Class<? extends Annotation> ref,
|
||||||
Class inter, Class<? extends Annotation> ref2, String properties, String property) {
|
Class inter, Class<? extends Annotation> ref2, String properties, String property) {
|
||||||
ClassFilter cf = new ClassFilter(ref, inter);
|
ClassFilter cf = new ClassFilter(ref, inter, null);
|
||||||
if (properties == null && properties == null) return cf;
|
if (properties == null && properties == null) return cf;
|
||||||
if (config == null) return cf;
|
if (config == null) return cf;
|
||||||
AnyValue[] proplist = config.getAnyValues(properties);
|
AnyValue[] proplist = config.getAnyValues(properties);
|
||||||
if (proplist == null || proplist.length < 1) return cf;
|
if (proplist == null || proplist.length < 1) return cf;
|
||||||
cf = null;
|
cf = null;
|
||||||
for (AnyValue list : proplist) {
|
for (AnyValue list : proplist) {
|
||||||
ClassFilter filter = new ClassFilter(ref, inter);
|
DefaultAnyValue prop = null;
|
||||||
|
String sc = list.getValue("group", "");
|
||||||
|
if (!sc.isEmpty()) {
|
||||||
|
prop = new AnyValue.DefaultAnyValue();
|
||||||
|
prop.addValue("group", sc);
|
||||||
|
}
|
||||||
|
ClassFilter filter = new ClassFilter(ref, inter, prop);
|
||||||
for (AnyValue av : list.getAnyValues(property)) {
|
for (AnyValue av : list.getAnyValues(property)) {
|
||||||
filter.filter(av, av.getValue("value"), false);
|
filter.filter(av, av.getValue("value"), false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public final class NodeSncpServer extends NodeServer {
|
|||||||
ClassFilter.Loader.load(home, serviceFilter);
|
ClassFilter.Loader.load(home, serviceFilter);
|
||||||
long e = System.currentTimeMillis() - s;
|
long e = System.currentTimeMillis() - s;
|
||||||
logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");
|
logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");
|
||||||
loadService(config.getAnyValue("services"), serviceFilter); //必须在servlet之前
|
loadService(serviceFilter); //必须在servlet之前
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
if (server == null) return; //调试时server才可能为null
|
if (server == null) return; //调试时server才可能为null
|
||||||
final StringBuilder sb = logger.isLoggable(Level.FINE) ? new StringBuilder() : null;
|
final StringBuilder sb = logger.isLoggable(Level.FINE) ? new StringBuilder() : null;
|
||||||
|
|||||||
Reference in New Issue
Block a user