This commit is contained in:
Redkale
2020-09-17 15:41:14 +08:00
parent 5921cf5f0d
commit 3131601477
2 changed files with 31 additions and 0 deletions

View File

@@ -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();
}

View File

@@ -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时调用 <br>
@@ -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<? extends Service> serviceType, final Method method);
}