<commit_before>package org.voovan.http.server.module.annontationRouter;

import org.voovan.Global;
import org.voovan.http.server.HttpModule;
import org.voovan.http.server.module.annontationRouter.router.AnnotationRouter;
import org.voovan.http.server.module.annontationRouter.router.AnnotationRouterFilter;
import org.voovan.http.server.module.annontationRouter.swagger.SwaggerApi;
import org.voovan.http.server.module.annontationRouter.swagger.entity.Swagger;
import org.voovan.tools.TObject;
import org.voovan.tools.TString;
import org.voovan.tools.hashwheeltimer.HashWheelTask;
import org.voovan.tools.log.Logger;
import org.voovan.tools.reflect.TReflect;

import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 注解路由模块
 *
 * @author: helyho
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class AnnotationModule extends HttpModule {
    public ConcurrentHashMap<Method, String> METHOD_URL_MAP = new ConcurrentHashMap<Method, String>();
    public ConcurrentHashMap<String, Method> URL_METHOD_MAP = new ConcurrentHashMap<String, Method>();
    public static String DEFAULT_SCAN_ROUTER_PACKAGE = "com;org;net;io";
    public static int DEFAULT_SCAN_ROUTER_INTERVAL = 30;

    private HashWheelTask scanRouterTask;
    private AnnotationRouterFilter annotationRouterFilter;

    /**
     * 获取扫描注解路由的包路径
     * @return 注解路由的包路劲
     */
    public String getScanRouterPackage(){
        return TObject.nullDefault ((String)getParamters("ScanRouterPackage"), DEFAULT_SCAN_ROUTER_PACKAGE);
    }

    /**
     * 获取注解路由的扫描时间间隔
     * @return 注解路由的扫描时间间隔
     */
    public int getScanRouterInterval(){
        return (int) TObject.nullDefault(getParamters("ScanRouterInterval"), DEFAULT_SCAN_ROUTER_INTERVAL);
    }

    /**
     * 获取注解路由过滤器
     * @return 注解路由的扫描时间间隔
     */
    public AnnotationRouterFilter getAnnotationRouterFilter(){
        if(annotationRouterFilter == null) {
            try {
                annotationRouterFilter = TReflect.newInstance(getParamters("Filter").toString());
            } catch (Exception e) {
                annotationRouterFilter = AnnotationRouterFilter.EMPYT;
            }
        }

        return annotationRouterFilter == AnnotationRouterFilter.EMPYT ? null : annotationRouterFilter;
    }

    @Override
    public void install() {
        final AnnotationModule annotationModule = this;
        String scanRouterPackage = getScanRouterPackage();
        if (scanRouterPackage != null) {
            AnnotationRouter.scanRouterClassAndRegister(annotationModule);
        }


        if(scanRouterPackage != null && getScanRouterInterval() > 0){

            scanRouterTask = new HashWheelTask() {
                @Override
                public void run() {
                    //查找并刷新新的@Route 注解类
                    AnnotationRouter.scanRouterClassAndRegister(annotationModule);
                }
            };

            //更新 ClassPath, 步长1秒, 槽数60个;
            Global.getHashWheelTimer().addTask(scanRouterTask, getScanRouterInterval());

            Logger.simple("[HTTP] Module ["+this.getModuleConfig().getName()+"] Router scan package: "+ this.getScanRouterPackage());
            Logger.simple("[HTTP] Module ["+this.getModuleConfig().getName()+"] Router scan interval: "+ this.getScanRouterInterval());

            Logger.simple("[HTTP] Module ["+this.getModuleConfig().getName()+"] Start auto scan annotation router.");
        }

        SwaggerApi.init(this);
    }

    @Override
    public void unInstall() {
        if(scanRouterTask!=null) {
            scanRouterTask.cancel();
        }
    }
}<commit_msg>fix: swagger 异常捕获处理, 避免因 swagger 导致进程服务发启动<commit_after>package org.voovan.http.server.module.annontationRouter;

import org.voovan.Global;
import org.voovan.http.server.HttpModule;
import org.voovan.http.server.module.annontationRouter.router.AnnotationRouter;
import org.voovan.http.server.module.annontationRouter.router.AnnotationRouterFilter;
import org.voovan.http.server.module.annontationRouter.swagger.SwaggerApi;
import org.voovan.http.server.module.annontationRouter.swagger.entity.Swagger;
import org.voovan.tools.TObject;
import org.voovan.tools.TString;
import org.voovan.tools.hashwheeltimer.HashWheelTask;
import org.voovan.tools.log.Logger;
import org.voovan.tools.reflect.TReflect;

import java.lang.reflect.Method;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 注解路由模块
 *
 * @author: helyho
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class AnnotationModule extends HttpModule {
    public ConcurrentHashMap<Method, String> METHOD_URL_MAP = new ConcurrentHashMap<Method, String>();
    public ConcurrentHashMap<String, Method> URL_METHOD_MAP = new ConcurrentHashMap<String, Method>();
    public static String DEFAULT_SCAN_ROUTER_PACKAGE = "com;org;net;io";
    public static int DEFAULT_SCAN_ROUTER_INTERVAL = 30;

    private HashWheelTask scanRouterTask;
    private AnnotationRouterFilter annotationRouterFilter;

    /**
     * 获取扫描注解路由的包路径
     * @return 注解路由的包路劲
     */
    public String getScanRouterPackage(){
        return TObject.nullDefault ((String)getParamters("ScanRouterPackage"), DEFAULT_SCAN_ROUTER_PACKAGE);
    }

    /**
     * 获取注解路由的扫描时间间隔
     * @return 注解路由的扫描时间间隔
     */
    public int getScanRouterInterval(){
        return (int) TObject.nullDefault(getParamters("ScanRouterInterval"), DEFAULT_SCAN_ROUTER_INTERVAL);
    }

    /**
     * 获取注解路由过滤器
     * @return 注解路由的扫描时间间隔
     */
    public AnnotationRouterFilter getAnnotationRouterFilter(){
        if(annotationRouterFilter == null) {
            try {
                annotationRouterFilter = TReflect.newInstance(getParamters("Filter").toString());
            } catch (Exception e) {
                annotationRouterFilter = AnnotationRouterFilter.EMPYT;
            }
        }

        return annotationRouterFilter == AnnotationRouterFilter.EMPYT ? null : annotationRouterFilter;
    }

    @Override
    public void install() {
        final AnnotationModule annotationModule = this;
        String scanRouterPackage = getScanRouterPackage();
        if (scanRouterPackage != null) {
            AnnotationRouter.scanRouterClassAndRegister(annotationModule);
        }


        if(scanRouterPackage != null && getScanRouterInterval() > 0){

            scanRouterTask = new HashWheelTask() {
                @Override
                public void run() {
                    //查找并刷新新的@Route 注解类
                    AnnotationRouter.scanRouterClassAndRegister(annotationModule);
                }
            };

            //更新 ClassPath, 步长1秒, 槽数60个;
            Global.getHashWheelTimer().addTask(scanRouterTask, getScanRouterInterval());

            Logger.simple("[HTTP] Module ["+this.getModuleConfig().getName()+"] Router scan package: "+ this.getScanRouterPackage());
            Logger.simple("[HTTP] Module ["+this.getModuleConfig().getName()+"] Router scan interval: "+ this.getScanRouterInterval());

            Logger.simple("[HTTP] Module ["+this.getModuleConfig().getName()+"] Start auto scan annotation router.");
        }

        try {
            SwaggerApi.init(this);
        } catch (Throwable e) {
            Logger.error("[SWAGGER] error: ", e);
        }
    }

    @Override
    public void unInstall() {
        if(scanRouterTask!=null) {
            scanRouterTask.cancel();
        }
    }
}
{'fraction_non_alphanumeric': 0.10455943307928868, 'fraction_numerical': 0.0018719080090921247, 'mean_word_length': 3.130314743235781, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6893503', 'n_tokens_mistral': 2248, 'n_tokens_neox': 2258, 'n_words': 370}