All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.web.session.SessionMonitor Maven / Gradle / Ivy

package com.alachisoft.ncache.web.session;

import java.util.HashMap;
//import java.util.Hashtable; - sajid
import org.apache.log4j.Logger;

public class SessionMonitor
{
    //private static Hashtable localCache = new Hashtable(); - sajid
    private static HashMap localCache = new HashMap(); // - sajid
    private static Logger logger = Logger.getLogger(SessionMonitor.class);

    //--------------------------------------------------------------------------------------------------------
    public static int getRequestCount(String key)
    {
        if (localCache.containsKey(key))
        {
            Integer count = (Integer) localCache.get(key);
            logger.debug("Request count is: " + count.intValue() + " for session (id = " + key + ")");
            return count.intValue();
        }
        logger.debug("No request (other than this) is currently using this session");
        return 0;
    }
    //--------------------------------------------------------------------------------------------------------
    public static void addRequest(String key)
    {
        localCache.put(key, new Integer(getRequestCount(key) + 1));
        logger.debug("Another request is using the same session (id = " + key + ")");
    }
    //--------------------------------------------------------------------------------------------------------
    public static void removeRequest(String key)
    {
        int count = getRequestCount(key) - 1;
        if (count <= 0)
        {
            localCache.remove(key);
        }
        else
        {
            localCache.put(key, new Integer(count));
        }
        logger.debug("A request completed for session (id = " + key + "), count is: " + count);
    }
    //--------------------------------------------------------------------------------------------------------
    public static void resetRequestCount(String key)
    {
        localCache.remove(key);
        logger.debug("Session (id = " + key + ") removed from local cache");
    }
    //--------------------------------------------------------------------------------------------------------
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy