From 31316014770cef75d1d6c3f8237254c46d73dce7 Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Thu, 17 Sep 2020 15:41:14 +0800 Subject: [PATCH] --- src/org/redkale/boot/Application.java | 4 +++ .../redkale/net/http/RestDyncListener.java | 27 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/org/redkale/boot/Application.java b/src/org/redkale/boot/Application.java index da7ff2458..277cd1149 100644 --- a/src/org/redkale/boot/Application.java +++ b/src/org/redkale/boot/Application.java @@ -737,6 +737,7 @@ public final class Application { Class clazz = classLoader.loadClass(listenClass); if (RestDyncListener.class.isAssignableFrom(clazz)) { RestDyncListener listener = (RestDyncListener) clazz.getDeclaredConstructor().newInstance(); + listener.init(config); this.restListeners.add(listener); continue; } @@ -917,6 +918,9 @@ public final class Application { //if (!singletonrun) signalHandle(); //if (!singletonrun) clearPersistData(); logger.info(this.getClass().getSimpleName() + " started in " + (System.currentTimeMillis() - startTime) + " ms\r\n"); + for (RestDyncListener listener : this.restListeners) { + listener.postApplicationStarted(this); + } if (!singletonrun) this.serversLatch.await(); } diff --git a/src/org/redkale/net/http/RestDyncListener.java b/src/org/redkale/net/http/RestDyncListener.java index 5414d82a2..0dbb07ffe 100644 --- a/src/org/redkale/net/http/RestDyncListener.java +++ b/src/org/redkale/net/http/RestDyncListener.java @@ -6,7 +6,9 @@ package org.redkale.net.http; import java.lang.reflect.Method; +import org.redkale.boot.Application; import org.redkale.service.Service; +import org.redkale.util.AnyValue; /** * Application进程启动后动态创建RestServlet时调用
@@ -20,6 +22,31 @@ import org.redkale.service.Service; */ public interface RestDyncListener { + /** + * 初始化方法 + * + * @param config 配置参数 + */ + default void init(AnyValue config) { + + } + + /** + * Application 初始化完所有Server后调用 + * + * @param application Application + */ + default void postApplicationStarted(Application application) { + } + + /** + * 动态生成RestMapping方法后调用 + * + * @param classLoader ClassLoader + * @param baseServletType Rest的Servlet基类 + * @param serviceType Service类 + * @param method Service的RestMapping方法 + */ public void invoke(final ClassLoader classLoader, final Class baseServletType, final Class serviceType, final Method method); }