光辉飞翔

导航

 

package org.c.base;

import java.util.Map; import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionBindingEvent; import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionListener;

import org.apache.log4j.Logger; import org.crm.modules.mycfs.CustomerUserBean;

/**  *  * @author *  */ public class OnlineUserListener implements HttpSessionListener, HttpSessionAttributeListener {

 private final static Logger logger = Logger.getLogger(OnlineUserListener.class);  private static ConcurrentHashMap<Long, CustomerUserBean> onlineUsers = new ConcurrentHashMap<Long, CustomerUserBean>();

 @Override  public void sessionCreated(HttpSessionEvent event) {  }

 @Override  public void sessionDestroyed(HttpSessionEvent event) {   CustomerUserBean user = (CustomerUserBean) event.getSession().getAttribute("User");   if (user != null) {    onlineUsers.remove(user.getUserId());   }  }

 @Override  public void attributeAdded(HttpSessionBindingEvent event) {   if (event.getName().equals("User")) {    CustomerUserBean user = (CustomerUserBean) event.getValue();    onlineUsers.put(user.getUserId(), user);   }  }

 @Override  public void attributeRemoved(HttpSessionBindingEvent event) {   if (event.getName().equals("User")) {    CustomerUserBean user = (CustomerUserBean) event.getValue();    onlineUsers.remove(user.getUserId());   }  }

 @Override  public void attributeReplaced(HttpSessionBindingEvent event) {

 }

 public static Map getOnlineUsers() {   return onlineUsers;  }

}

posted on 2012-09-05 16:04  光辉飞翔  阅读(309)  评论(0编辑  收藏  举报