This commit is contained in:
@@ -513,6 +513,10 @@ public abstract class NodeServer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWATCH() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceFactory getResourceFactory() {
|
public ResourceFactory getResourceFactory() {
|
||||||
return resourceFactory;
|
return resourceFactory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,4 +42,9 @@ public class NodeWatchServer extends NodeHttpServer {
|
|||||||
protected ClassFilter createOtherClassFilter() {
|
protected ClassFilter createOtherClassFilter() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isWATCH() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package org.redkale.boot.watch;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import org.redkale.boot.Application;
|
import org.redkale.boot.*;
|
||||||
import org.redkale.net.TransportFactory;
|
import org.redkale.net.TransportFactory;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.service.RetResult;
|
import org.redkale.service.RetResult;
|
||||||
@@ -29,6 +29,9 @@ public class FilterWatchService extends AbstractWatchService {
|
|||||||
@Comment("Node节点IP地址已存在")
|
@Comment("Node节点IP地址已存在")
|
||||||
public static final int RET_FILTER_EXISTS = 1601_0003;
|
public static final int RET_FILTER_EXISTS = 1601_0003;
|
||||||
|
|
||||||
|
@Comment("Node节点IP地址已存在")
|
||||||
|
public static final int RET_JAR_ILLEGAL = 1601_0004;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
private Application application;
|
||||||
|
|
||||||
@@ -36,9 +39,14 @@ public class FilterWatchService extends AbstractWatchService {
|
|||||||
private TransportFactory transportFactory;
|
private TransportFactory transportFactory;
|
||||||
|
|
||||||
@RestMapping(name = "addfilter", auth = false, comment = "动态增加Filter")
|
@RestMapping(name = "addfilter", auth = false, comment = "动态增加Filter")
|
||||||
public RetResult addFilter(@RestParam(name = "server", comment = "Server节点名, 不指定名称则所有符合条件的Server都会增加Filter") final String serverName,
|
public RetResult addFilter(@RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar,
|
||||||
|
@RestParam(name = "server", comment = "Server节点名, 不指定名称则所有符合条件的Server都会增加Filter") final String serverName,
|
||||||
@RestParam(name = "type", comment = "Filter类名") final String filterType) throws IOException {
|
@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");
|
if (filterType == null) return new RetResult(RET_FILTER_TYPE_ILLEGAL, "Filter Type (" + filterType + ") is illegal");
|
||||||
|
if (jar == null) return new RetResult(RET_JAR_ILLEGAL, "Not found jar file");
|
||||||
|
for (NodeServer node : application.getNodeServers()) {
|
||||||
|
if (node.getServer().containsFilter(filterType)) return new RetResult(RET_JAR_ILLEGAL, "Filter(" + filterType + ") exists");
|
||||||
|
}
|
||||||
return RetResult.success();
|
return RetResult.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,15 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsServlet(String servletClassName) {
|
||||||
|
synchronized (lock1) {
|
||||||
|
for (S servlet : new HashSet<>(servlets)) {
|
||||||
|
if (servlet.getClass().getName().equals(servletClassName)) 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);
|
||||||
@@ -144,11 +153,11 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Filter<C, R, P> removeFilter(Class<? extends Filter<C, R, P>> filterClass) {
|
public <T extends Filter<C, R, P>> T removeFilter(Class<T> filterClass) {
|
||||||
return removeFilter(f -> filterClass.equals(f.getClass()));
|
return removeFilter(f -> filterClass.equals(f.getClass()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean containsFilter(Class<? extends Filter<C, R, P>> filterClass) {
|
public boolean containsFilter(Class<? extends Filter> filterClass) {
|
||||||
if (this.headFilter == null || filterClass == null) return false;
|
if (this.headFilter == null || filterClass == null) return false;
|
||||||
Filter filter = this.headFilter;
|
Filter filter = this.headFilter;
|
||||||
do {
|
do {
|
||||||
@@ -157,13 +166,22 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Filter<C, R, P> removeFilter(Predicate<Filter<C, R, P>> predicate) {
|
public boolean containsFilter(String filterClassName) {
|
||||||
|
if (this.headFilter == null || filterClassName == null) return false;
|
||||||
|
Filter filter = this.headFilter;
|
||||||
|
do {
|
||||||
|
if (filter.getClass().getName().equals(filterClassName)) return true;
|
||||||
|
} while ((filter = filter._next) != null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends Filter<C, R, P>> T removeFilter(Predicate<T> predicate) {
|
||||||
if (this.headFilter == null || predicate == null) return null;
|
if (this.headFilter == null || predicate == null) return null;
|
||||||
synchronized (filters) {
|
synchronized (filters) {
|
||||||
Filter filter = this.headFilter;
|
Filter filter = this.headFilter;
|
||||||
Filter prev = null;
|
Filter prev = null;
|
||||||
do {
|
do {
|
||||||
if (predicate.test(filter)) break;
|
if (predicate.test((T) filter)) break;
|
||||||
prev = filter;
|
prev = filter;
|
||||||
} while ((filter = filter._next) != null);
|
} while ((filter = filter._next) != null);
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
@@ -175,7 +193,7 @@ public abstract class PrepareServlet<K extends Serializable, C extends Context,
|
|||||||
filter._next = null;
|
filter._next = null;
|
||||||
this.filters.remove(filter);
|
this.filters.remove(filter);
|
||||||
}
|
}
|
||||||
return filter;
|
return (T) filter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,52 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
|
|||||||
logger.info(this.getClass().getSimpleName() + " shutdown in " + e + " ms");
|
logger.info(this.getClass().getSimpleName() + " shutdown in " + e + " ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否存在Filter
|
||||||
|
*
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @param filterClass Filter类
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public <T extends Filter> boolean containsFilter(Class<T> filterClass) {
|
||||||
|
return this.prepare.containsFilter(filterClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否存在Filter
|
||||||
|
*
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @param filterClassName Filter类
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public <T extends Filter> boolean containsFilter(String filterClassName) {
|
||||||
|
return this.prepare.containsFilter(filterClassName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否存在Servlet
|
||||||
|
*
|
||||||
|
* @param servletClass Servlet类
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean containsServlet(Class<? extends S> servletClass) {
|
||||||
|
return this.prepare.containsServlet(servletClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否存在Servlet
|
||||||
|
*
|
||||||
|
* @param servletClassName Servlet类
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public boolean containsServlet(String servletClassName) {
|
||||||
|
return this.prepare.containsServlet(servletClassName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 销毁Servlet
|
* 销毁Servlet
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -162,6 +162,24 @@ public class HttpResourceServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void serRoot(String rootstr) {
|
||||||
|
if (rootstr == null) return;
|
||||||
|
try {
|
||||||
|
this.root = new File(rootstr).getCanonicalFile();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
this.root = new File(rootstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void serRoot(File file) {
|
||||||
|
if (file == null) return;
|
||||||
|
try {
|
||||||
|
this.root = file.getCanonicalFile();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
this.root = file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected static long parseLenth(String value, long defValue) {
|
protected static long parseLenth(String value, long defValue) {
|
||||||
if (value == null) return defValue;
|
if (value == null) return defValue;
|
||||||
value = value.toUpperCase().replace("B", "");
|
value = value.toUpperCase().replace("B", "");
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
|||||||
*
|
*
|
||||||
* @return HttpServlet
|
* @return HttpServlet
|
||||||
*/
|
*/
|
||||||
public HttpServlet getResourceServlet() {
|
public HttpResourceServlet getResourceServlet() {
|
||||||
return ((HttpPrepareServlet) this.prepare).resourceHttpServlet;
|
return (HttpResourceServlet) ((HttpPrepareServlet) this.prepare).resourceHttpServlet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,22 +100,10 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
|||||||
*
|
*
|
||||||
* @return HttpFilter
|
* @return HttpFilter
|
||||||
*/
|
*/
|
||||||
public <T extends HttpFilter> T removeFilter(Class<T> filterClass) {
|
public <T extends HttpFilter> T removeHttpFilter(Class<T> filterClass) {
|
||||||
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
|
||||||
*
|
*
|
||||||
@@ -171,18 +159,6 @@ 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
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class SncpServer extends Server<DLong, SncpContext, SncpRequest, SncpResp
|
|||||||
*
|
*
|
||||||
* @return SncpFilter
|
* @return SncpFilter
|
||||||
*/
|
*/
|
||||||
public <T extends SncpFilter> T removeFilter(Class<T> filterClass) {
|
public <T extends SncpFilter> T removeSncpFilter(Class<T> filterClass) {
|
||||||
return (T) this.prepare.removeFilter(filterClass);
|
return (T) this.prepare.removeFilter(filterClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,18 +62,6 @@ 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
|
||||||
*
|
*
|
||||||
@@ -94,18 +82,6 @@ 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