countlistener.java

来自「Jaoso新闻文章发布系统 0.9.1final 程序架构: Struts」· Java 代码 · 共 57 行

JAVA
57
字号
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 {
    /** �������� */
    private static int onlineCount = 0;

    /** ͳ�Ʒ��� */
    private CountService countService;

    /**
     * (non-Javadoc)
     *
     * @see javax.servlet.http.HttpSessionListener#sessionCreated(javax.servlet.http.HttpSessionEvent)
     */
    public final void sessionCreated(final HttpSessionEvent arg0) {
        init();
        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;
    }

    private void init() {
        if (countService == null) {
            countService = (CountService) ServiceLocator.getInstance()
                                                        .getService("countService");
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?