?? contextlistener.java
字號:
/*
* Copyright 2005 Frank W. Zammetti
*
* 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.
*/
package org.apache.struts.apps.ajaxchat.listener;
import java.io.InputStream;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.apps.ajaxchat.daemon.UserClearerDaemonThread;
import org.apache.struts.apps.ajaxchat.dao.AjaxChatDAO;
/**
* This ContextListener performs some simple initialization of the application.
* Namely, it gets a stream on our rooms configuration file and passes it
* along to the DAO's init() method so it can be read in.
*
* @author <a href="mailto:fzammetti@omnytex.com">Frank W. Zammetti</a>.
*/
public class ContextListener implements ServletContextListener {
/**
* Log instance.
*/
private static Log log = LogFactory.getLog(ContextListener.class);
/**
* Name of the config file, including context-relarive path.
*/
private static final String CONFIG_FILE = "/WEB-INF/rooms-config.xml";
/**
* Execute at app startup.
*
* @param event ServletContextEvent.
*/
public void contextInitialized(ServletContextEvent event) {
log.debug("contextInitialized()...");
// Initialize DAO.
AjaxChatDAO dao = AjaxChatDAO.getInstance();
// Get a stream on the config file and initialize the DAO so we'll have
// some rooms to chat in.
ServletContext servletContext = event.getServletContext();
InputStream isConfigFile = servletContext.getResourceAsStream(CONFIG_FILE);
dao.init(isConfigFile);
// Lastly, start a background daemon thread that will periodically clear
// out inactive users from rooms. This was originally done via
// SessionListener, but because of some problems seem in some container
// implementations (Resin, I'm looking at you!), this had to be done
// instead.
Thread userClearerDaemonThread = new UserClearerDaemonThread();
userClearerDaemonThread.setPriority(Thread.MIN_PRIORITY);
userClearerDaemonThread.setDaemon(true);
userClearerDaemonThread.start();
log.info("AjaxChat configured and ready for use");
} // End contextInitialized();
/**
* Execute at app shutdown.
*
* @param event ServletContextEvent.
*/
public void contextDestroyed(ServletContextEvent event) {
} // End contextDestroyed().
} // Ebd class.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -