com.gisgraphy.webapp.listener

## Class UserCounterListener

- java.lang.Object
- - com.gisgraphy.webapp.listener.UserCounterListener

- All Implemented Interfaces:
    EventListener, javax.servlet.http.HttpSessionAttributeListener, javax.servlet.ServletContextListener

      public class UserCounterListener
      extends Object
      implements javax.servlet.ServletContextListener, javax.servlet.http.HttpSessionAttributeListener

  UserCounterListener class used to count the current number of active users for the applications. Does this by counting how many user objects are stuffed into the session. It Also grabs these users and exposes them in the servlet context.
  Author:
    Matt Raible

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `COUNT_KEY` Name of user counter variable
    `static String` | `EVENT_KEY` The default event we're looking to trap.
    `static String` | `USERS_KEY` Name of users Set in the ServletContext

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `UserCounterListener()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `attributeAdded(javax.servlet.http.HttpSessionBindingEvent event)` This method is designed to catch when user's login and record their name
    `void` | `attributeRemoved(javax.servlet.http.HttpSessionBindingEvent event)` When user's logout, remove their name from the hashMap
    `void` | `attributeReplaced(javax.servlet.http.HttpSessionBindingEvent event)` Needed for Acegi Security 1.0, as it adds an anonymous user to the session and then replaces it after authentication.
    `void` | `contextDestroyed(javax.servlet.ServletContextEvent event)` Set the servletContext, users and counter to null
    `void` | `contextInitialized(javax.servlet.ServletContextEvent sce)` Initialize the context

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### COUNT_KEY

          public static final String COUNT_KEY

      Name of user counter variable
      See Also:
        Constant Field Values

    - #### USERS_KEY

          public static final String USERS_KEY

      Name of users Set in the ServletContext
      See Also:
        Constant Field Values

    - #### EVENT_KEY

          public static final String EVENT_KEY

      The default event we're looking to trap.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### UserCounterListener

          public UserCounterListener()

  - ### Method Detail

    - #### contextInitialized

          public void contextInitialized(javax.servlet.ServletContextEvent sce)

      Initialize the context
      Specified by:
        `contextInitialized` in interface `javax.servlet.ServletContextListener`
      Parameters:
        `sce` - the event

    - #### contextDestroyed

          public void contextDestroyed(javax.servlet.ServletContextEvent event)

      Set the servletContext, users and counter to null
      Specified by:
        `contextDestroyed` in interface `javax.servlet.ServletContextListener`
      Parameters:
        `event` - The servletContextEvent

    - #### attributeAdded

          public void attributeAdded(javax.servlet.http.HttpSessionBindingEvent event)

      This method is designed to catch when user's login and record their name
      Specified by:
        `attributeAdded` in interface `javax.servlet.http.HttpSessionAttributeListener`
      Parameters:
        `event` - the event to process
      See Also:
        `HttpSessionAttributeListener.attributeAdded(javax.servlet.http.HttpSessionBindingEvent)`

    - #### attributeRemoved

          public void attributeRemoved(javax.servlet.http.HttpSessionBindingEvent event)

      When user's logout, remove their name from the hashMap
      Specified by:
        `attributeRemoved` in interface `javax.servlet.http.HttpSessionAttributeListener`
      Parameters:
        `event` - the session binding event
      See Also:
        `HttpSessionAttributeListener.attributeRemoved(javax.servlet.http.HttpSessionBindingEvent)`

    - #### attributeReplaced

          public void attributeReplaced(javax.servlet.http.HttpSessionBindingEvent event)

      Needed for Acegi Security 1.0, as it adds an anonymous user to the session and then replaces it after authentication. http://forum.springframework.org/showthread.php?p=63593
      Specified by:
        `attributeReplaced` in interface `javax.servlet.http.HttpSessionAttributeListener`
      Parameters:
        `event` - the session binding event
      See Also:
        `HttpSessionAttributeListener.attributeReplaced(javax.servlet.http.HttpSessionBindingEvent)`

Copyright © 2015. All rights reserved.