This commit is contained in:
@@ -29,7 +29,7 @@ import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* Server节点的初始化配置类
|
||||
*
|
||||
* <p>
|
||||
* <p>
|
||||
* 详情见: http://redkale.org
|
||||
*
|
||||
@@ -61,22 +61,22 @@ public abstract class NodeServer {
|
||||
|
||||
//当前Server的SNCP协议的组
|
||||
private String sncpGroup = null;
|
||||
|
||||
|
||||
//SNCP服务的地址, 非SNCP为null
|
||||
private InetSocketAddress sncpAddress;
|
||||
|
||||
|
||||
//加载Service时的处理函数
|
||||
protected Consumer<ServiceWrapper> consumer;
|
||||
|
||||
|
||||
//server节点的配置
|
||||
protected AnyValue serverConf;
|
||||
|
||||
|
||||
//加载server节点后的拦截器
|
||||
protected NodeInterceptor interceptor;
|
||||
|
||||
//本地模式的Service对象集合
|
||||
protected final Set<ServiceWrapper> localServiceWrappers = new LinkedHashSet<>();
|
||||
|
||||
|
||||
//远程模式的Service对象集合
|
||||
protected final Set<ServiceWrapper> remoteServiceWrappers = new LinkedHashSet<>();
|
||||
|
||||
@@ -157,7 +157,7 @@ public abstract class NodeServer {
|
||||
Class clazz = forName(interceptorClass);
|
||||
this.interceptor = (NodeInterceptor) clazz.newInstance();
|
||||
}
|
||||
|
||||
|
||||
ClassFilter<Servlet> servletFilter = createServletClassFilter();
|
||||
ClassFilter<Service> serviceFilter = createServiceClassFilter();
|
||||
long s = System.currentTimeMillis();
|
||||
@@ -170,6 +170,8 @@ public abstract class NodeServer {
|
||||
logger.info(this.getClass().getSimpleName() + " load filter class in " + e + " ms");
|
||||
loadService(serviceFilter); //必须在servlet之前
|
||||
loadServlet(servletFilter);
|
||||
|
||||
if (this.interceptor != null) this.resourceFactory.inject(this.interceptor);
|
||||
}
|
||||
|
||||
protected abstract void loadServlet(ClassFilter<? extends Servlet> servletFilter) throws Exception;
|
||||
@@ -384,7 +386,7 @@ public abstract class NodeServer {
|
||||
}
|
||||
|
||||
protected ClassFilter createClassFilter(final String localGroup, 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, null);
|
||||
if (properties == null && properties == null) return cf;
|
||||
if (this.serverConf == null) return cf;
|
||||
@@ -454,6 +456,10 @@ public abstract class NodeServer {
|
||||
return sncpAddress;
|
||||
}
|
||||
|
||||
public AnyValue getServerConf() {
|
||||
return serverConf;
|
||||
}
|
||||
|
||||
public String getSncpGroup() {
|
||||
return sncpGroup;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
|
||||
|
||||
private HttpServlet resourceHttpServlet = new HttpResourceServlet();
|
||||
|
||||
private final Map<String, Class> mapStrings = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void init(HttpContext context, AnyValue config) {
|
||||
this.servlets.forEach(s -> {
|
||||
@@ -89,6 +91,10 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
|
||||
if (prefix == null) prefix = "";
|
||||
for (String mapping : mappings) {
|
||||
if (!prefix.toString().isEmpty()) mapping = prefix + mapping;
|
||||
if (this.mapStrings.containsKey(mapping)) {
|
||||
Class old = this.mapStrings.get(mapping);
|
||||
throw new RuntimeException("mapping [" + mapping + "] repeat on " + old.getName() + " and " + servlet.getClass().getName());
|
||||
}
|
||||
if (contains(mapping, '.', '*', '{', '[', '(', '|', '^', '$', '+', '?', '\\')) { //是否是正则表达式))
|
||||
if (mapping.charAt(0) != '^') mapping = '^' + mapping;
|
||||
if (mapping.endsWith("/*")) {
|
||||
@@ -104,11 +110,12 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
|
||||
regArray[regArray.length - 1] = new SimpleEntry<>(Pattern.compile(mapping).asPredicate(), servlet);
|
||||
}
|
||||
} else if (mapping != null && !mapping.isEmpty()) {
|
||||
this.mappings.put(mapping, servlet);
|
||||
super.mappings.put(mapping, servlet);
|
||||
}
|
||||
this.mapStrings.put(mapping, servlet.getClass());
|
||||
}
|
||||
setServletConf(servlet, conf);
|
||||
servlet._prefix = prefix == null ? "" : prefix.toString();
|
||||
servlet._prefix = prefix.toString();
|
||||
this.servlets.add(servlet);
|
||||
}
|
||||
|
||||
@@ -139,6 +146,7 @@ public final class HttpPrepareServlet extends PrepareServlet<String, HttpContext
|
||||
((BasedHttpServlet) s).postDestroy(context, getServletConf(s));
|
||||
}
|
||||
});
|
||||
this.mapStrings.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user