/** * 启动Bootstrap */ public static void start() { if (STATE.compareAndSet(false, true)) { log.info("starting bootstrap ..."); initConfig(); addSystemPlugin(); initPlugins(); registerShutdownHook(); log.info("bootstrap has started ! have fun"); } }
/** * 关闭Bootstrap */ public static synchronized void close() { doClose(); Runtime.getRuntime().removeShutdownHook(SHUTDOWN_HOOK); }
@Override public void onStartup(ServletContext context) { Bootstrap.start(); Dynamic dynamic = context .addServlet(DispatcherServlet.class.getSimpleName(), DispatcherServlet.class); dynamic.setLoadOnStartup(0); dynamic.addMapping(Constants.ROOT_PATH); dynamic.setAsyncSupported(true); }
private void doService(HttpServletRequest req, HttpServletResponse resp, HttpMethod httpMethod) { String requestPath = req.getServletPath(); if (log.isDebugEnabled()) { log.debug("DispatcherServlet accept request for [{}] on method [{}]", requestPath, httpMethod); } Request.set(req); Response.set(resp); if (requestPath.length() > 1) { if (requestPath.endsWith(Constants.ROOT_PATH)) { requestPath = requestPath.substring(0, requestPath.length() - 1); } } try { Action action = WebPlugin.findActionByPath(requestPath, httpMethod); if (action == null) { handlerNotFound(req, resp); return; } Bootstrap.invokeBeforePlugins(); handlerAction(action, req, resp); Bootstrap.invokeAfterPlugins(); } catch (StaticException e) { handlerStatic(req, resp, e.getSource()); } finally { Bootstrap.invokeFinalPlugins(); Request.clear(); Response.clear(); } }
/** * 初始化配置 * <br> * 使用默认地址进行加载,然后使用覆盖路径再次加载 */ public static void initConfig() { initConfig(Constants.CONFIG_PATHS); }
private void handlerError(HttpServletRequest req, HttpServletResponse resp, Exception e) { log.error("DispatcherServlet occurs an error for path [{}]", req.getServletPath(), e); Bootstrap.invokeOnExceptionPlugins(); Request.current().setException(e); WebPlugin.ERROR_HANDLERS.get(Constants.SERVER_ERROR).handle(req, resp); }
/** * 初始化executor */ public static void initExecutor() { Bootstrap.start(); // monitor BeanStore.putBean(TimeoutMonitorImpl.class.getName(), new TimeoutMonitorImpl()); // registry Registry registry = new RedisRegistry(); registry.register(); }
@PostConstruct public void initCenter() { Bootstrap.start(); RedissonClient redissonClient = BeanStore.getBean(RedissonClient.class); JobRepository jobRepository = BeanStore.getBean(JobRepository.class); // schedule BeanStore.putBean(RedisJobScheduleImpl.class.getName(), new RedisJobScheduleImpl()); // dispatcher BeanStore.putBean(RedisDispatcher.class.getName(), new RedisDispatcher(redissonClient, jobRepository)); redissonClient.getExecutorService(JobConfig.EVENT) .registerWorkers(ConfigFactory.load(SystemProperties.class).getWorkers()); BeanStore.putBean(EventListener.class.getName(), new EventListener(notifier)); } }