package com.zuoxiaolong.listener;

/*
 * Copyright 2002-2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import com.zuoxiaolong.config.Configuration;
import com.zuoxiaolong.generator.Generators;
import com.zuoxiaolong.search.LuceneHelper;
import com.zuoxiaolong.thread.BaiduPushTask;
import com.zuoxiaolong.thread.DirtyWordsFlushTask;
import com.zuoxiaolong.thread.Executor;
import com.zuoxiaolong.thread.FetchTask;

/**
 * @author 左潇龙
 * @since 5/7/2015 3:33 PM
 */
public class ConfigurationListener implements ServletContextListener {
	
	private static final Logger logger = Logger.getLogger(ConfigurationListener.class);

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
    	if (logger.isInfoEnabled()) {
			logger.info("will begin init configuration...");
		}
        Configuration.init(servletContextEvent.getServletContext());
        if (logger.isInfoEnabled()) {
			logger.info("init configuration success...");
		}
        if (logger.isInfoEnabled()) {
            logger.info("starting DirtyWordsFlush thread...");
        }
        Executor.executeTask(new DirtyWordsFlushTask());
        if (logger.isInfoEnabled()) {
            logger.info("DirtyWordsFlush thread has been started...");
        }
        if (!Configuration.isProductEnv()) {
//            ImageUtil.loadArticleImages();
//            try {
//				Cnblogs.fetchArticlesCommon();
//			} catch (IOException e) {
//				throw new RuntimeException(e);
//			}
//			LuceneHelper.generateIndex();
//            Generators.generate();
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("starting fetch and generate thread...");
            }
            Executor.executeTask(new FetchTask());
            if (logger.isInfoEnabled()) {
                logger.info("fetch and generate thread has been started...");
            }
            if (logger.isInfoEnabled()) {
                logger.info("starting baidu push thread...");
            }
            Executor.executeTask(new BaiduPushTask());
            if (logger.isInfoEnabled()) {
                logger.info("baidu push thread has been started...");
            }
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
    }

}

@@ -1938,9 +1938,8 @@
 if (
-!
 Conf
@@ -1970,274 +1970,8 @@
 ) %7B%0A
-//            ImageUtil.loadArticleImages();%0A//            try %7B%0A//%09%09%09%09Cnblogs.fetchArticlesCommon();%0A//%09%09%09%7D catch (IOException e) %7B%0A//%09%09%09%09throw new RuntimeException(e);%0A//%09%09%09%7D%0A//%09%09%09LuceneHelper.generateIndex();%0A//            Generators.generate();%0A        %7D else %7B%0A
     

add question.