package org.common.filter;

/**
 *
 * @author 1004242
 */
import Controller.LoginServlet;
import Dao.LogOutDao;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

public class SessionListener implements HttpSessionListener {

    @Override
    public void sessionCreated(HttpSessionEvent arg0) {
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent sessionEvent) {
        synchronized (this) {
            HttpSession session = sessionEvent.getSession();
            LogOutDao lDao = new LogOutDao();
            if (session != null) {
               // lDao.removeFromLoggedInUsers(session.getId(), null, 2);
                //clearing from sesssion map on any case of session inavlidation
                 if (LoginServlet.sesssionMap.containsKey(session.getId())) {
                        LoginServlet.sesssionMap.remove(session.getId());
                    }
            }
        }
    }
}
