源码阅读笔记-JFourm

  记录在阅读JFourm源码过程中的一切笔记。

  1.JFourm连接为mysql,由于我的mysql在服务中,设置为手动,所以每次都需要进入服务界面,手动启动mysql,太麻烦了。

上网查找如何在cmd中启动mysql。经查找,有两种方法,net start MySQL55, sc start MySQL55 ,自己尝试了一下,由于权限不足,返回拒绝。

在查找,原来需要管理员权限,搜索cmd,右键,以管理员方式登录,在启动。= = OK 了啊!

还找到创建以管理员登录cmd的快捷方式设置。

     2.发布,启动之后,由于jfourm没有在启动过程中装载类,所以启动速度快,所有的初始化的动作,都放在登录的时候。

在浏览器中直接输入 http://localhost:8080/jfourm 其中8080为tomcat的默认端口,jfourm 为 Context root。

此时在console中输出了日志信息如下:

13:05:58,132  INFO [JForumBaseServlet   ] Starting JForum. Debug mode is true
13:05:58,132  INFO [ConfigLoader        ] Using cache engine: net.jforum.cache.DefaultCacheEngine
13:05:58,132  INFO [ConfigLoader        ] Creating an instance of net.jforum.repository.BBCodeRepository
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.RankingRepository
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.SmiliesRepository
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.ForumRepository
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.TopicRepository
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.SessionFacade
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.PostRepository
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.Tpl
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.RolesRepository
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.SecurityRepository
13:05:58,148  INFO [ConfigLoader        ] Creating an instance of  net.jforum.repository.BanlistRepository
13:05:58,210  INFO [FileMonitor         ] Watching D:\javatest\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\JForumSource/WEB-INF/config/languages/en_US.properties
13:05:58,210  INFO [FileMonitor         ] Watching D:\javatest\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\JForumSource/WEB-INF/config/languages/zh_CN.properties
13:05:58,241  INFO [ConfigLoader        ] Loading JDBC driver net.jforum.dao.mysql.MysqlDataAccessDriver
13:05:58,288  INFO [FileMonitor         ] Watching D:\javatest\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\JForumSource/WEB-INF/config/database/generic/generic_queries.sql
13:05:58,288  INFO [FileMonitor         ] Watching D:\javatest\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\JForumSource/WEB-INF/config/database/mysql/mysql.sql
13:05:58,288  INFO [FileMonitor         ] Watching D:\javatest\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\JForumSource/WEB-INF/config/SystemGlobals.properties
13:05:58,366  INFO [MLog                ] MLog clients using log4j logging.
13:05:58,382  INFO [C3P0Registry        ] Initializing c3p0-0.9.1-pre9 [built 23-September-2006 01:47:24; debug? true; trace: 10]
13:05:58,429  INFO [AbstractPoolBackedDataSource] Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 120000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 95da38, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 95da38, idleConnectionTestPeriod -> 3600, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/jforum?user=root&password=root&autoReconnect=true&useNewIO=false&zeroDateTimeBehavior=convertToNull&useServerPrepStmts=false&dumpQueriesOnException=true&jdbcCompliantTruncation=false, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, numHelperThreads -> 3, preferredTestQuery -> null, properties -> {}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 180, usesTraditionalReflectiveProxies -> false ]
13:05:58,929  INFO [ConfigLoader        ] Loading clickstream config from D:\javatest\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\JForumSource/WEB-INF/config/clickstream-jforum.xml

由日志可以看出,启动过程中的初始化的类,主要为三个:

JForumBaseServlet,ConfigLoader ,FileMonitor。接下来先分析 JForumBaseServlet

在web.xml 中,可以看到包含的配置信息

 <!-- JForum Controller -->
    <servlet>
  <servlet-name>jforum</servlet-name>
  <servlet-class>net.jforum.JForum</servlet-class>
  
  <init-param>
   <param-name>development</param-name>
   <param-value>true</param-value>
  </init-param>
    </servlet>

我们的程序的入口,映射的类为 JForum ,而JForum正是JForumBaseServlet的子类(JForumBaseServlet 是HttpServlet的子类),

由于JForum也是一个Servlet,因此根据Servlet的生命周期,会先执行初始化的init方法,JForum中的init方法如下

 1     public void init(ServletConfig config) throws ServletException
 2     {
 3         super.init(config);
 4         super.startApplication();
 5         
 6         // Start database
 7         isDatabaseUp = ForumStartup.startDatabase();
 8         
 9         try {
10             Connection conn = DBConnection.getImplementation().getConnection();
11             conn.setAutoCommit(!SystemGlobals.getBoolValue(ConfigKeys.DATABASE_USE_TRANSACTIONS));
12             
13             // Try to fix some MySQL problems
14             MySQLVersionWorkarounder dw = new MySQLVersionWorkarounder();
15             dw.handleWorkarounds(conn);
16             
17             // Continues loading the forum
18             JForumExecutionContext ex = JForumExecutionContext.get();
19             ex.setConnection(conn);
20             JForumExecutionContext.set(ex);
21             
22             // Init general forum stuff
23             ForumStartup.startForumRepository();
24             RankingRepository.loadRanks();
25             SmiliesRepository.loadSmilies();
26             BanlistRepository.loadBanlist();
27         }
28         catch (Throwable e) {
29             e.printStackTrace();
30             throw new ForumStartupException("Error while starting jforum", e);
31         }
32         finally {
33             JForumExecutionContext.finish();
34         }
35     }

此时会调用JForumBaseServlet的init方法,与StartApplication方法

protected void startApplication()
    {
        try {
            SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_GENERIC));
            SystemGlobals.loadQueries(SystemGlobals.getValue(ConfigKeys.SQL_QUERIES_DRIVER));
            
            String filename = SystemGlobals.getValue(ConfigKeys.QUARTZ_CONFIG);
            SystemGlobals.loadAdditionalDefaults(filename);

            ConfigLoader.createLoginAuthenticator();
            ConfigLoader.loadDaoImplementation();
            ConfigLoader.listenForChanges();
            ConfigLoader.startSearchIndexer();
            ConfigLoader.startSummaryJob();
        }
        catch (Exception e) {
            throw new ForumStartupException("Error while starting JForum", e);
        }
    }

    public void init(ServletConfig config) throws ServletException
    {
        super.init(config);

        try {
            String appPath = config.getServletContext().getRealPath("");
            debug = "true".equals(config.getInitParameter("development"));

            DOMConfigurator.configure(appPath + "/WEB-INF/log4j.xml");

            logger.info("Starting JForum. Debug mode is " + debug);

            ConfigLoader.startSystemglobals(appPath);
            ConfigLoader.startCacheEngine();

            // Configure the template engine
            Configuration templateCfg = new Configuration();
            templateCfg.setTemplateUpdateDelay(2);
            templateCfg.setSetting("number_format", "#");
            templateCfg.setSharedVariable("startupTime", new Long(new Date().getTime()));

            // Create the default template loader
            String defaultPath = SystemGlobals.getApplicationPath() + "/templates";
            FileTemplateLoader defaultLoader = new FileTemplateLoader(new File(defaultPath));

            String extraTemplatePath = SystemGlobals.getValue(ConfigKeys.FREEMARKER_EXTRA_TEMPLATE_PATH);
            
            if (StringUtils.isNotBlank(extraTemplatePath)) {
                // An extra template path is configured, we need a MultiTemplateLoader
                FileTemplateLoader extraLoader = new FileTemplateLoader(new File(extraTemplatePath));
                TemplateLoader[] loaders = new TemplateLoader[] { extraLoader, defaultLoader };
                MultiTemplateLoader multiLoader = new MultiTemplateLoader(loaders);
                templateCfg.setTemplateLoader(multiLoader);
            } 
            else {
                // An extra template path is not configured, we only need the default loader
                templateCfg.setTemplateLoader(defaultLoader);
            }

            ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR));

            this.loadConfigStuff();

            if (!this.debug) {
                templateCfg.setTemplateUpdateDelay(3600);
            }

            JForumExecutionContext.setTemplateConfig(templateCfg);
        }
        catch (Exception e) {
            throw new ForumStartupException("Error while starting JForum", e);
        }
    }

在init方法中,

ConfigLoader.startSystemglobals(appPath);
  ConfigLoader.startCacheEngine();
分别是装载全局变量,与启动CacheEngine。

待续

                                                         2012-06-27 0:31 不断更新中

转载于:https://www.cnblogs.com/NardoWong/archive/2012/06/27/2564555.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值