From 8516925537902ece40f813c5ebf478796434eb82 Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Tue, 16 Jun 2020 17:48:19 +0800 Subject: [PATCH] =?UTF-8?q?Service=20=E5=A2=9E=E5=8A=A0=20stop=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/net/http/Rest.java | 8 +++++--- src/org/redkale/net/sncp/Sncp.java | 6 ++++++ src/org/redkale/net/sncp/SncpClient.java | 6 ++++-- src/org/redkale/net/sncp/SncpDynServlet.java | 6 ++++-- src/org/redkale/service/Service.java | 12 ++++++++++++ 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/org/redkale/net/http/Rest.java b/src/org/redkale/net/http/Rest.java index a1785ae30..549a623ef 100644 --- a/src/org/redkale/net/http/Rest.java +++ b/src/org/redkale/net/http/Rest.java @@ -827,9 +827,11 @@ public final class Rest { if (Modifier.isStatic(method.getModifiers())) continue; if (method.isSynthetic()) continue; if (EXCLUDERMETHODS.contains(method.getName())) continue; - if ("init".equals(method.getName())) continue; - if ("destroy".equals(method.getName())) continue; - if ("version".equals(method.getName())) continue; + if (method.getParameterCount() == 1 && method.getParameterTypes()[0] == AnyValue.class) { + if ("init".equals(method.getName())) continue; + if ("stop".equals(method.getName())) continue; + if ("destroy".equals(method.getName())) continue; + } if (controller == null) continue; RestMapping[] mappings = method.getAnnotationsByType(RestMapping.class); diff --git a/src/org/redkale/net/sncp/Sncp.java b/src/org/redkale/net/sncp/Sncp.java index b6b39fb5d..00f76942e 100644 --- a/src/org/redkale/net/sncp/Sncp.java +++ b/src/org/redkale/net/sncp/Sncp.java @@ -688,6 +688,12 @@ public abstract class Sncp { mv.visitMaxs(0, 2); mv.visitEnd(); } + { //stop + mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "stop", "(" + anyValueDesc + ")V", null, null)); + mv.visitInsn(RETURN); + mv.visitMaxs(0, 2); + mv.visitEnd(); + } { //destroy mv = new MethodDebugVisitor(cw.visitMethod(ACC_PUBLIC, "destroy", "(" + anyValueDesc + ")V", null, null)); mv.visitInsn(RETURN); diff --git a/src/org/redkale/net/sncp/SncpClient.java b/src/org/redkale/net/sncp/SncpClient.java index 6e176eae8..4aab90060 100644 --- a/src/org/redkale/net/sncp/SncpClient.java +++ b/src/org/redkale/net/sncp/SncpClient.java @@ -183,9 +183,11 @@ public final class SncpClient { if (method.getName().equals("getClass") || method.getName().equals("toString")) continue; if (method.getName().equals("equals") || method.getName().equals("hashCode")) continue; if (method.getName().equals("notify") || method.getName().equals("notifyAll") || method.getName().equals("wait")) continue; - if (method.getName().equals("init") || method.getName().equals("destroy")) continue; - //if (method.getName().equals("version") || method.getName().equals("name")) continue; + if (method.getParameterCount() == 1 && method.getParameterTypes()[0] == AnyValue.class) { + if (method.getName().equals("init") || method.getName().equals("stop") || method.getName().equals("destroy")) continue; + } //if (onlySncpDyn && method.getAnnotation(SncpDyn.class) == null) continue; + DLong actionid = Sncp.hash(method); Method old = actionids.get(actionid); if (old != null) { diff --git a/src/org/redkale/net/sncp/SncpDynServlet.java b/src/org/redkale/net/sncp/SncpDynServlet.java index f4f1b88d5..5c3d97629 100644 --- a/src/org/redkale/net/sncp/SncpDynServlet.java +++ b/src/org/redkale/net/sncp/SncpDynServlet.java @@ -63,8 +63,10 @@ public final class SncpDynServlet extends SncpServlet { if (method.getName().equals("getClass") || method.getName().equals("toString")) continue; if (method.getName().equals("equals") || method.getName().equals("hashCode")) continue; if (method.getName().equals("notify") || method.getName().equals("notifyAll") || method.getName().equals("wait")) continue; - if (method.getName().equals("init") || method.getName().equals("destroy")) continue; - //if (method.getName().equals("version") || method.getName().equals("name")) continue; + if (method.getParameterCount() == 1 && method.getParameterTypes()[0] == AnyValue.class) { + if (method.getName().equals("init") || method.getName().equals("stop") || method.getName().equals("destroy")) continue; + } + final DLong actionid = Sncp.hash(method); SncpServletAction action = SncpServletAction.create(service, actionid, method); action.convert = convert; diff --git a/src/org/redkale/service/Service.java b/src/org/redkale/service/Service.java index 19a235139..550b28776 100644 --- a/src/org/redkale/service/Service.java +++ b/src/org/redkale/service/Service.java @@ -46,6 +46,18 @@ public interface Service { } + /** + * 进程退出前会进行stop动作 + * 远程模式下该方法会重载成空方法 + * + * @param config 配置参数 + * + * @since 2.1.0 + */ + default void stop(AnyValue config) { + + } + /** * 进程退出时,调用Service销毁 * 远程模式下该方法会重载成空方法