Watch组件增加可以获取指定Servie中某个可序列化的字段的值
This commit is contained in:
@@ -17,4 +17,7 @@ public abstract class AbstractWatchService extends AbstractService implements Wa
|
|||||||
|
|
||||||
@Comment("缺少参数")
|
@Comment("缺少参数")
|
||||||
public static final int RET_WATCH_PARAMS_ILLEGAL = 1600_0001;
|
public static final int RET_WATCH_PARAMS_ILLEGAL = 1600_0001;
|
||||||
|
|
||||||
|
@Comment("执行异常")
|
||||||
|
public static final int RET_WATCH_RUN_EXCEPTION = 1600_0002;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class FilterWatchService extends AbstractWatchService {
|
|||||||
public static final int RET_FILTER_JAR_ILLEGAL = 1601_0005;
|
public static final int RET_FILTER_JAR_ILLEGAL = 1601_0005;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
protected Application application;
|
||||||
|
|
||||||
@RestMapping(name = "addfilter", auth = false, comment = "动态增加Filter")
|
@RestMapping(name = "addfilter", auth = false, comment = "动态增加Filter")
|
||||||
public RetResult addFilter(@RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar,
|
public RetResult addFilter(@RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class ServerWatchService extends AbstractWatchService {
|
|||||||
public static final int RET_SERVER_NOT_EXISTS = 1602_0001;
|
public static final int RET_SERVER_NOT_EXISTS = 1602_0001;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
protected Application application;
|
||||||
|
|
||||||
@RestMapping(name = "info", comment = "单个Server信息查询")
|
@RestMapping(name = "info", comment = "单个Server信息查询")
|
||||||
public RetResult info(@RestParam(name = "#port:") int port) {
|
public RetResult info(@RestParam(name = "#port:") int port) {
|
||||||
|
|||||||
@@ -5,10 +5,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.boot.watch;
|
package org.redkale.boot.watch;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
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.http.*;
|
import org.redkale.net.http.*;
|
||||||
|
import org.redkale.service.RetResult;
|
||||||
|
import org.redkale.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -19,12 +22,52 @@ import org.redkale.net.http.*;
|
|||||||
@RestService(name = "service", catalog = "watch", repair = false)
|
@RestService(name = "service", catalog = "watch", repair = false)
|
||||||
public class ServiceWatchService extends AbstractWatchService {
|
public class ServiceWatchService extends AbstractWatchService {
|
||||||
|
|
||||||
@Resource
|
@Comment("没有找到目标Service")
|
||||||
private Application application;
|
public static final int RET_SERVICE_DEST_NOT_EXISTS = 1603_0001;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TransportFactory transportFactory;
|
protected Application application;
|
||||||
|
|
||||||
|
@RestMapping(name = "findfield", auth = false, comment = "查询Service中指定字段的内容")
|
||||||
|
@RestConvert(type = void.class)
|
||||||
|
public RetResult findfield(String name, String type, String field) {
|
||||||
|
if (name == null) name = "";
|
||||||
|
if (type == null) type = "";
|
||||||
|
if (field == null) field = "";
|
||||||
|
type = type.trim();
|
||||||
|
field = field.trim();
|
||||||
|
if (type.isEmpty()) return new RetResult(RET_WATCH_PARAMS_ILLEGAL, "not found param `type`");
|
||||||
|
if (field.isEmpty()) return new RetResult(RET_WATCH_PARAMS_ILLEGAL, "not found param `field`");
|
||||||
|
final String name0 = name;
|
||||||
|
final String type0 = type;
|
||||||
|
Object dest = null;
|
||||||
|
for (NodeServer ns : application.getNodeServers()) {
|
||||||
|
ResourceFactory resFactory = ns.getResourceFactory();
|
||||||
|
List list = resFactory.query((n, s) -> name0.equals(n) && s.getClass().getName().endsWith(type0));
|
||||||
|
if (list == null || list.isEmpty()) continue;
|
||||||
|
dest = list.get(0);
|
||||||
|
}
|
||||||
|
if (dest == null) return new RetResult(RET_SERVICE_DEST_NOT_EXISTS, "not found servie (name=" + name + ", type=" + type + ")");
|
||||||
|
Class clazz = dest.getClass();
|
||||||
|
Throwable t = null;
|
||||||
|
try {
|
||||||
|
Field fieldObj = null;
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
fieldObj = clazz.getDeclaredField(field);
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (t == null) t = e;
|
||||||
|
}
|
||||||
|
} while ((clazz = clazz.getSuperclass()) != Object.class);
|
||||||
|
if (fieldObj == null) return new RetResult(RET_WATCH_RUN_EXCEPTION, "run exception (" + String.valueOf(t) + ")");
|
||||||
|
fieldObj.setAccessible(true);
|
||||||
|
return new RetResult(fieldObj.get(dest));
|
||||||
|
} catch (Throwable t2) {
|
||||||
|
return new RetResult(RET_WATCH_RUN_EXCEPTION, "run exception (" + t2.toString() + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
// @RestMapping(name = "load", auth = false, comment = "动态增加Service")
|
// @RestMapping(name = "load", auth = false, comment = "动态增加Service")
|
||||||
// public RetResult loadService(String type, @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) {
|
// public RetResult loadService(String type, @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) {
|
||||||
// //待开发
|
// //待开发
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import org.redkale.net.http.*;
|
|||||||
public class ServletWatchService extends AbstractWatchService {
|
public class ServletWatchService extends AbstractWatchService {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
protected Application application;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TransportFactory transportFactory;
|
protected TransportFactory transportFactory;
|
||||||
//
|
//
|
||||||
// @RestMapping(name = "load", auth = false, comment = "动态增加Servlet")
|
// @RestMapping(name = "load", auth = false, comment = "动态增加Servlet")
|
||||||
// public RetResult loadServlet(String type, @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) {
|
// public RetResult loadServlet(String type, @RestUploadFile(maxLength = 10 * 1024 * 1024, fileNameReg = "\\.jar$") byte[] jar) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class SourceWatchService extends AbstractWatchService {
|
|||||||
public static final int RET_SOURCE_METHOD_INVOKE_NOT_EXISTS = 1605_0003;
|
public static final int RET_SOURCE_METHOD_INVOKE_NOT_EXISTS = 1605_0003;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
protected Application application;
|
||||||
|
|
||||||
@RestMapping(name = "change", auth = false, comment = "动态更改DataSource的配置")
|
@RestMapping(name = "change", auth = false, comment = "动态更改DataSource的配置")
|
||||||
public RetResult addNode(@RestParam(name = "name", comment = "DataSource的标识") final String name,
|
public RetResult addNode(@RestParam(name = "name", comment = "DataSource的标识") final String name,
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ public class TransportWatchService extends AbstractWatchService {
|
|||||||
public static final int RET_TRANSPORT_ADDR_EXISTS = 1606_0003;
|
public static final int RET_TRANSPORT_ADDR_EXISTS = 1606_0003;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private Application application;
|
protected Application application;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private TransportFactory transportFactory;
|
protected TransportFactory transportFactory;
|
||||||
|
|
||||||
@RestMapping(name = "listnodes", auth = false, comment = "获取所有Node节点")
|
@RestMapping(name = "listnodes", auth = false, comment = "获取所有Node节点")
|
||||||
public List<TransportGroupInfo> listNodes() {
|
public List<TransportGroupInfo> listNodes() {
|
||||||
|
|||||||
Reference in New Issue
Block a user