【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“CountListener.java”一文,供大家参考学习
package jaoso.count.
web.listener;
import jaoso.count.service.CountService;
import jaoso.framework.service.ServiceLocator;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
/**
* @author 边缘孤客
* 统计在线人数的监视器
*/
public class CountListener implements HttpSessionListener {
//~ Static fields/initializers =============================================
/** 在线人数 */
private static int onlineCount = 0;
//~ Instance fields ========================================================
/** 统计服务 */
private CountService countService = (CountService) ServiceLocator.getInstance()
.getService("countService");
//~ Methods ================================================================
/**
* (non-
Javadoc)
* @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
*/
public final void sessionCreated(final HttpSessionEvent arg0) {
countService.getCount(true);
onlineCount++;
}
/**
* (non-Javadoc)
* @see javax.servlet.http.HttpSessionListener#sessionDestroyed(javax.servlet.http.HttpSessionEvent)
*/
public final void sessionDestroyed(final HttpSessionEvent arg0) {
if (onlineCount > 0) {
onlineCount--;
}
}
/**
* @return Returns the onlineCount.
*/
public static int getOnlineCount() {
return onlineCount;
}
}