Commit ccfedc45 authored by Liang Ding's avatar Liang Ding

🎨 秒表处理移到框架里

parent 50cf5144
......@@ -23,6 +23,8 @@ import org.b3log.latke.Latkes;
import org.b3log.latke.event.EventManager;
import org.b3log.latke.http.BaseServer;
import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.handler.StopwatchEndHandler;
import org.b3log.latke.http.handler.StopwatchStartHandler;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
......@@ -35,7 +37,10 @@ import org.b3log.solo.event.B3ArticleSender;
import org.b3log.solo.event.B3ArticleUpdater;
import org.b3log.solo.event.B3CommentSender;
import org.b3log.solo.event.PluginRefresher;
import org.b3log.solo.processor.*;
import org.b3log.solo.processor.ErrorProcessor;
import org.b3log.solo.processor.InitCheckHandler;
import org.b3log.solo.processor.PermalinkHandler;
import org.b3log.solo.processor.SkinHandler;
import org.b3log.solo.processor.console.*;
import org.b3log.solo.repository.OptionRepository;
import org.b3log.solo.service.*;
......@@ -67,6 +72,8 @@ public final class Server extends BaseServer {
* @param args the specified arguments
*/
public static void main(final String[] args) {
Stopwatchs.start("Booting");
final Options options = new Options();
final Option listenPortOpt = Option.builder("lp").longOpt("listen_port").argName("LISTEN_PORT").
hasArg().desc("listen port, default is 8080").build();
......@@ -184,7 +191,6 @@ public final class Server extends BaseServer {
Dispatcher.HANDLERS.add(3, new PermalinkHandler());
Dispatcher.HANDLERS.add(4, new StopwatchEndHandler());
routeConsoleProcessors();
Stopwatchs.start("Context Initialized");
final Latkes.RuntimeDatabase runtimeDatabase = Latkes.getRuntimeDatabase();
final String jdbcUsername = Latkes.getLocalProperty("jdbc.username");
......@@ -239,10 +245,6 @@ public final class Server extends BaseServer {
LOGGER.info("Solo is running");
}
Stopwatchs.end();
LOGGER.log(Level.DEBUG, "Stopwatch: {0}{1}", Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat());
Stopwatchs.release();
final CronMgmtService cronMgmtService = beanManager.getReference(CronMgmtService.class);
cronMgmtService.start();
......@@ -252,6 +254,11 @@ public final class Server extends BaseServer {
server.shutdown();
Latkes.shutdown();
}));
Stopwatchs.end();
LOGGER.log(Level.DEBUG, "Stopwatch: {0}{1}", Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat());
Stopwatchs.release();
server.start(Integer.valueOf(portArg));
}
......
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-present, b3log.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.processor;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.handler.Handler;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.util.Stopwatchs;
import org.b3log.latke.util.Strings;
/**
* Stopwatch end handler.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Nov 3, 2019
* @since 3.6.7
*/
public class StopwatchEndHandler implements Handler {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(StopwatchEndHandler.class);
@Override
public void handle(final RequestContext context) {
Stopwatchs.end();
LOGGER.log(Level.DEBUG, "Stopwatch: {0}{1}", Strings.LINE_SEPARATOR, Stopwatchs.getTimingStat());
Stopwatchs.release();
context.handle();
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-present, b3log.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.processor;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.handler.Handler;
import org.b3log.latke.util.Stopwatchs;
/**
* Stopwatch start handler.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Nov 3, 2019
* @since 3.6.7
*/
public class StopwatchStartHandler implements Handler {
@Override
public void handle(final RequestContext context) {
Stopwatchs.start("Request Initialized [requestURI=" + context.requestURI() + "]");
context.handle();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment