This commit is contained in:
@@ -135,6 +135,7 @@
|
|||||||
<!--
|
<!--
|
||||||
name: 显式指定name,覆盖默认的空字符串值。 注意: name不能包含$符号。
|
name: 显式指定name,覆盖默认的空字符串值。 注意: name不能包含$符号。
|
||||||
groups: 显式指定groups,覆盖<services>节点的groups默认值。
|
groups: 显式指定groups,覆盖<services>节点的groups默认值。
|
||||||
|
ignore: 是否禁用, 默认为false。
|
||||||
-->
|
-->
|
||||||
<service value="com.xxx.XXX2Service" name="" groups="xxx;yyy"/>
|
<service value="com.xxx.XXX2Service" name="" groups="xxx;yyy"/>
|
||||||
<!-- 给Service增加配置属性 -->
|
<!-- 给Service增加配置属性 -->
|
||||||
@@ -153,7 +154,12 @@
|
|||||||
excludes: 当autoload="true", 排除类名与excludes中的正则表达式匹配的类, 多个正则表达式用分号;隔开
|
excludes: 当autoload="true", 排除类名与excludes中的正则表达式匹配的类, 多个正则表达式用分号;隔开
|
||||||
-->
|
-->
|
||||||
<filters autoload="true" includes="" excludes="">
|
<filters autoload="true" includes="" excludes="">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
显著加载指定的Filter类
|
||||||
|
value=: Filter类名。必须与Server的协议层相同,HTTP必须是HttpFilter
|
||||||
|
ignore: 是否禁用, 默认为false。
|
||||||
|
-->
|
||||||
<!-- 显著加载指定的Filter类 -->
|
<!-- 显著加载指定的Filter类 -->
|
||||||
<filter value="com.xxx.XXX1Filter"/>
|
<filter value="com.xxx.XXX1Filter"/>
|
||||||
|
|
||||||
@@ -247,7 +253,11 @@
|
|||||||
excludes: 当autoload="true", 排除类名与excludes中的正则表达式匹配的类, 多个正则表达式用分号;隔开
|
excludes: 当autoload="true", 排除类名与excludes中的正则表达式匹配的类, 多个正则表达式用分号;隔开
|
||||||
-->
|
-->
|
||||||
<servlets path="/pipes" autoload="true" includes="" excludes="">
|
<servlets path="/pipes" autoload="true" includes="" excludes="">
|
||||||
<!-- 显著加载指定的Servlet -->
|
<!--
|
||||||
|
显著加载指定的Servlet类
|
||||||
|
value=: Servlet类名。必须与Server的协议层相同,HTTP必须是HttpServlet
|
||||||
|
ignore: 是否禁用, 默认为false。
|
||||||
|
-->
|
||||||
<servlet value="com.xxx.XXX1Servlet" />
|
<servlet value="com.xxx.XXX1Servlet" />
|
||||||
<servlet value="com.xxx.XXX2Servlet" />
|
<servlet value="com.xxx.XXX2Servlet" />
|
||||||
<servlet value="com.xxx.XXX3Servlet" >
|
<servlet value="com.xxx.XXX3Servlet" >
|
||||||
|
|||||||
@@ -450,62 +450,6 @@ public abstract class NodeServer {
|
|||||||
maxClassNameLength = Math.max(maxClassNameLength, Sncp.getResourceType(y).getName().length() + 1);
|
maxClassNameLength = Math.max(maxClassNameLength, Sncp.getResourceType(y).getName().length() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* protected List<Transport> loadTransports(final HashSet<String> groups) {
|
|
||||||
* if (groups == null) return null;
|
|
||||||
* final List<Transport> transports = new ArrayList<>();
|
|
||||||
* for (String group : groups) {
|
|
||||||
* if (this.sncpGroup == null || !this.sncpGroup.equals(group)) {
|
|
||||||
* transports.add(loadTransport(group));
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* return transports;
|
|
||||||
* }
|
|
||||||
* protected Transport loadTransport(final HashSet<String> groups) {
|
|
||||||
* if (groups == null || groups.isEmpty()) return null;
|
|
||||||
* final String groupid = new ArrayList<>(groups).stream().sorted().collect(Collectors.joining(";")); //按字母排列顺序
|
|
||||||
* Transport transport = application.resourceFactory.find(groupid, Transport.class);
|
|
||||||
* if (transport != null) return transport;
|
|
||||||
* final List<Transport> transports = new ArrayList<>();
|
|
||||||
* for (String group : groups) {
|
|
||||||
* transports.add(loadTransport(group));
|
|
||||||
* }
|
|
||||||
* Set<InetSocketAddress> addrs = new HashSet();
|
|
||||||
* transports.forEach(t -> addrs.addAll(Arrays.asList(t.getRemoteAddresses())));
|
|
||||||
* Transport first = transports.get(0);
|
|
||||||
* TransportGroupInfo ginfo = application.transportFactory.findGroupInfo(first.getName());
|
|
||||||
* Transport newTransport = new Transport(groupid, ginfo.getProtocol(),
|
|
||||||
* ginfo.getSubprotocol(), application.transportBufferPool, application.transportChannelGroup, this.sncpAddress, addrs);
|
|
||||||
* synchronized (application.resourceFactory) {
|
|
||||||
* transport = application.resourceFactory.find(groupid, Transport.class);
|
|
||||||
* if (transport == null) {
|
|
||||||
* transport = newTransport;
|
|
||||||
* application.resourceFactory.register(groupid, transport);
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* return transport;
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* protected Transport loadTransport(final String group) {
|
|
||||||
* if (group == null) return null;
|
|
||||||
* Transport transport;
|
|
||||||
* synchronized (application.resourceFactory) {
|
|
||||||
* transport = application.resourceFactory.find(group, Transport.class);
|
|
||||||
* if (transport != null) {
|
|
||||||
* if (this.sncpAddress != null && !this.sncpAddress.equals(transport.getClientAddress())) {
|
|
||||||
* throw new RuntimeException(transport + "repeat create on newClientAddress = " + this.sncpAddress + ", oldClientAddress = " + transport.getClientAddress());
|
|
||||||
* }
|
|
||||||
* return transport;
|
|
||||||
* }
|
|
||||||
* TransportGroupInfo ginfo = application.findGroupInfo(group);
|
|
||||||
* Set<InetSocketAddress> addrs = ginfo.copyAddresses();
|
|
||||||
* if (addrs == null) throw new RuntimeException("Not found <group> = " + group + " on <resources> ");
|
|
||||||
* transport = new Transport(group, ginfo.getProtocol(), ginfo.getSubprotocol(), application.transportBufferPool, application.transportChannelGroup, this.sncpAddress, addrs);
|
|
||||||
* application.resourceFactory.register(group, transport);
|
|
||||||
* }
|
|
||||||
* return transport;
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
protected abstract ClassFilter<Filter> createFilterClassFilter();
|
protected abstract ClassFilter<Filter> createFilterClassFilter();
|
||||||
|
|
||||||
protected abstract ClassFilter<Servlet> createServletClassFilter();
|
protected abstract ClassFilter<Servlet> createServletClassFilter();
|
||||||
@@ -571,7 +515,9 @@ public abstract class NodeServer {
|
|||||||
dav.addValue("properties", ps);
|
dav.addValue("properties", ps);
|
||||||
av = dav;
|
av = dav;
|
||||||
}
|
}
|
||||||
filter.filter(av, av.getValue("value"), false);
|
if (!av.getBoolValue("ignore", false)) {
|
||||||
|
filter.filter(av, av.getValue("value"), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (list.getBoolValue("autoload", true)) {
|
if (list.getBoolValue("autoload", true)) {
|
||||||
String includes = list.getValue("includes", "");
|
String includes = list.getValue("includes", "");
|
||||||
|
|||||||
17
src/org/redkale/boot/watch/AbstractWatchService.java
Normal file
17
src/org/redkale/boot/watch/AbstractWatchService.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.redkale.boot.watch;
|
||||||
|
|
||||||
|
import org.redkale.service.AbstractService;
|
||||||
|
import org.redkale.watch.WatchService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
*/
|
||||||
|
public abstract class AbstractWatchService extends AbstractService implements WatchService {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,14 +5,40 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.boot.watch;
|
package org.redkale.boot.watch;
|
||||||
|
|
||||||
import org.redkale.net.http.RestService;
|
import java.io.IOException;
|
||||||
import org.redkale.watch.WatchService;
|
import javax.annotation.Resource;
|
||||||
|
import org.redkale.boot.Application;
|
||||||
|
import org.redkale.net.TransportFactory;
|
||||||
|
import org.redkale.net.http.*;
|
||||||
|
import org.redkale.service.RetResult;
|
||||||
|
import org.redkale.util.Comment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@RestService(name = "filter", catalog = "watch", repair = false)
|
@RestService(name = "filter", catalog = "watch", repair = false)
|
||||||
public class FilterWatchService implements WatchService {
|
public class FilterWatchService extends AbstractWatchService {
|
||||||
|
|
||||||
|
@Comment("不存在的Group节点")
|
||||||
|
public static final int RET_NO_GROUP = 1601_0001;
|
||||||
|
|
||||||
|
@Comment("Filter类名不存在")
|
||||||
|
public static final int RET_FILTER_TYPE_ILLEGAL = 1601_0002;
|
||||||
|
|
||||||
|
@Comment("Node节点IP地址已存在")
|
||||||
|
public static final int RET_FILTER_EXISTS = 1601_0003;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private Application application;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TransportFactory transportFactory;
|
||||||
|
|
||||||
|
@RestMapping(name = "addfilter", auth = false, comment = "动态增加Filter")
|
||||||
|
public RetResult addFilter(@RestParam(name = "server", comment = "Server节点名, 不指定名称则所有符合条件的Server都会增加Filter") final String serverName,
|
||||||
|
@RestParam(name = "type", comment = "Filter类名") final String filterType) throws IOException {
|
||||||
|
if (filterType == null) return new RetResult(RET_FILTER_TYPE_ILLEGAL, "Filter Type (" + filterType + ") is illegal");
|
||||||
|
return RetResult.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,12 @@
|
|||||||
package org.redkale.boot.watch;
|
package org.redkale.boot.watch;
|
||||||
|
|
||||||
import org.redkale.net.http.RestService;
|
import org.redkale.net.http.RestService;
|
||||||
import org.redkale.watch.WatchService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@RestService(name = "server", catalog = "watch", repair = false)
|
@RestService(name = "server", catalog = "watch", repair = false)
|
||||||
public class ServerWatchService implements WatchService {
|
public class ServerWatchService extends AbstractWatchService {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import javax.annotation.Resource;
|
|||||||
import org.redkale.boot.Application;
|
import org.redkale.boot.Application;
|
||||||
import org.redkale.net.TransportFactory;
|
import org.redkale.net.TransportFactory;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.watch.WatchService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -18,7 +17,7 @@ import org.redkale.watch.WatchService;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@RestService(name = "service", catalog = "watch", repair = false)
|
@RestService(name = "service", catalog = "watch", repair = false)
|
||||||
public class ServiceWatchService implements WatchService {
|
public class ServiceWatchService extends AbstractWatchService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
private Application application;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import javax.annotation.Resource;
|
|||||||
import org.redkale.boot.Application;
|
import org.redkale.boot.Application;
|
||||||
import org.redkale.net.TransportFactory;
|
import org.redkale.net.TransportFactory;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.watch.WatchService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -18,7 +17,7 @@ import org.redkale.watch.WatchService;
|
|||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@RestService(name = "servlet", catalog = "watch", repair = false)
|
@RestService(name = "servlet", catalog = "watch", repair = false)
|
||||||
public class ServletWatchService implements WatchService {
|
public class ServletWatchService extends AbstractWatchService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
private Application application;
|
||||||
|
|||||||
26
src/org/redkale/boot/watch/SourceWatchService.java
Normal file
26
src/org/redkale/boot/watch/SourceWatchService.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.redkale.boot.watch;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.redkale.boot.Application;
|
||||||
|
import org.redkale.net.TransportFactory;
|
||||||
|
import org.redkale.net.http.RestService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
*/
|
||||||
|
@RestService(name = "source", catalog = "watch", repair = false)
|
||||||
|
public class SourceWatchService extends AbstractWatchService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private Application application;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TransportFactory transportFactory;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,23 +18,22 @@ import org.redkale.net.sncp.*;
|
|||||||
import org.redkale.service.*;
|
import org.redkale.service.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||||
import org.redkale.watch.WatchService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@RestService(name = "transport", catalog = "watch", repair = false)
|
@RestService(name = "transport", catalog = "watch", repair = false)
|
||||||
public class TransportWatchService implements WatchService {
|
public class TransportWatchService extends AbstractWatchService {
|
||||||
|
|
||||||
@Comment("不存在的Group节点")
|
@Comment("不存在的Group节点")
|
||||||
public static final int RET_NO_GROUP = 1605_0001;
|
public static final int RET_NO_GROUP = 1606_0001;
|
||||||
|
|
||||||
@Comment("非法的Node节点IP地址")
|
@Comment("非法的Node节点IP地址")
|
||||||
public static final int RET_ADDR_ILLEGAL = 1605_0002;
|
public static final int RET_ADDR_ILLEGAL = 1606_0002;
|
||||||
|
|
||||||
@Comment("Node节点IP地址已存在")
|
@Comment("Node节点IP地址已存在")
|
||||||
public static final int RET_ADDR_EXISTS = 1605_0003;
|
public static final int RET_ADDR_EXISTS = 1606_0003;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
private Application application;
|
||||||
|
|||||||
@@ -63,6 +63,15 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsServlet(Class<? extends S> servletClass) {
|
||||||
|
synchronized (lock1) {
|
||||||
|
for (S servlet : new HashSet<>(servlets)) {
|
||||||
|
if (servlet.getClass().equals(servletClass)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void putMapping(K key, S servlet) {
|
protected void putMapping(K key, S servlet) {
|
||||||
synchronized (lock2) {
|
synchronized (lock2) {
|
||||||
Map<K, S> newmappings = new HashMap<>(mappings);
|
Map<K, S> newmappings = new HashMap<>(mappings);
|
||||||
@@ -139,6 +148,15 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
return removeFilter(f -> filterClass.equals(f.getClass()));
|
return removeFilter(f -> filterClass.equals(f.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsFilter(Class<? extends Filter<C, R, P>> filterClass) {
|
||||||
|
if (this.headFilter == null || filterClass == null) return false;
|
||||||
|
Filter filter = this.headFilter;
|
||||||
|
do {
|
||||||
|
if (filter.getClass().equals(filterClass)) return true;
|
||||||
|
} while ((filter = filter._next) != null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public Filter<C, R, P> removeFilter(Predicate<Filter<C, R, P>> predicate) {
|
public Filter<C, R, P> removeFilter(Predicate<Filter<C, R, P>> predicate) {
|
||||||
if (this.headFilter == null || predicate == null) return null;
|
if (this.headFilter == null || predicate == null) return null;
|
||||||
synchronized (filters) {
|
synchronized (filters) {
|
||||||
|
|||||||
@@ -104,6 +104,18 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
|||||||
return (T) this.prepare.removeFilter(filterClass);
|
return (T) this.prepare.removeFilter(filterClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否存在HttpFilter
|
||||||
|
*
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @param filterClass HttpFilter类
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public <T extends HttpFilter> boolean containsHttpFilter(Class<T> filterClass) {
|
||||||
|
return this.prepare.containsFilter(filterClass);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加HttpFilter
|
* 添加HttpFilter
|
||||||
*
|
*
|
||||||
@@ -159,6 +171,18 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否存在HttpServlet
|
||||||
|
*
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @param servletClass HttpServlet类
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public <T extends HttpServlet> boolean containsHttpServlet(Class<T> servletClass) {
|
||||||
|
return this.prepare.containsServlet(servletClass);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加WebSocketServlet
|
* 添加WebSocketServlet
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -62,6 +62,18 @@ public class SncpServer extends Server<DLong, SncpContext, SncpRequest, SncpResp
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否存在SncpFilter
|
||||||
|
*
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @param filterClass SncpFilter类
|
||||||
|
*
|
||||||
|
* @return SncpFilter
|
||||||
|
*/
|
||||||
|
public <T extends SncpFilter> boolean containsSncpFilter(Class<T> filterClass) {
|
||||||
|
return this.prepare.containsFilter(filterClass);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除SncpServlet
|
* 删除SncpServlet
|
||||||
*
|
*
|
||||||
@@ -82,6 +94,18 @@ public class SncpServer extends Server<DLong, SncpContext, SncpRequest, SncpResp
|
|||||||
return ((SncpPrepareServlet) this.prepare).getSncpServlets();
|
return ((SncpPrepareServlet) this.prepare).getSncpServlets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否存在SncpServlet
|
||||||
|
*
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @param servletClass SncpServlet类
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public <T extends SncpServlet> boolean containsSncpServlet(Class<T> servletClass) {
|
||||||
|
return this.prepare.containsServlet(servletClass);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
protected SncpContext createContext() {
|
protected SncpContext createContext() {
|
||||||
|
|||||||
Reference in New Issue
Block a user