システムレコード現在のオンラインユーザーリスト

1859 ワード


public class SessionListener implements HttpSessionListener,
	HttpSessionAttributeListener {

private static HashMap<String, SysUser> userMap = new HashMap<String, SysUser>();//  sessionID user 

private static HashMap<String, HttpSession> sessionMap = new HashMap<String, HttpSession>();//  sessionID

/**  HttpSessionListener * */
/*  session  */
public void sessionCreated(HttpSessionEvent se) {}

/* session ,  */
public void sessionDestroyed(HttpSessionEvent se) {
	userMap.remove(se.getSession().getId());
	sessionMap.remove(se.getSession().getId());
}

/**  HttpSessionAttributeListener * */
/*  session.setAttribute( "user", "**** ") ,  */
public void attributeAdded(HttpSessionBindingEvent se) {
	if (se.getName().equals("user")) {
		userMap.put(se.getSession().getId(), (SysUser) se.getValue());
	}
}

/*  session.removeAttribute( "user", "**** ") ,  */
public void attributeRemoved(HttpSessionBindingEvent se) {
	if (se.getName().equals("user")) {
		LoginServlet.userLogout(se.getSession());
		userMap.remove(se.getSession().getId());
	}
}

/*   "user "  */
@SuppressWarnings("unchecked")
public void attributeReplaced(HttpSessionBindingEvent se) {}

/*   */
public static HashMap getList() {
	return userMap;
}

public int getOnlineNumber() {
	return userMap.size();
}

public synchronized static HashMap<String, HttpSession> getSessionMap() {
	return sessionMap;
}

public static HashMap<String, SysUser> getUserMap() {
	return userMap;
}