package org.springblade.common.listener;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: Silent
 * @Description
 * @Date: Created in 16:53 2021/11/24
 * @Modified By:
 */
public class OnlinePeopleListener implements HttpSessionListener {

	public static AtomicInteger userCount = new AtomicInteger(0);

	/**
	 * 用户登录，创建session，用户数增加
	 * @param event
	 */
	@Override
	public void sessionCreated(HttpSessionEvent event) {
		userCount.getAndIncrement();
	}

	/**
	 * 用户下线，销毁session，用户数减少
	 * @param event
	 */
	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		userCount.getAndDecrement();
	}
}
