Example usage for javax.servlet.http HttpSessionAttributeListener attributeRemoved

List of usage examples for javax.servlet.http HttpSessionAttributeListener attributeRemoved

Introduction

In this page you can find the example usage for javax.servlet.http HttpSessionAttributeListener attributeRemoved.

Prototype

default public void attributeRemoved(HttpSessionBindingEvent event) 

Source Link

Document

Receives notification that an attribute has been removed from a session.

Usage

From source file:org.apache.catalina.cluster.session.DeltaSession.java

public void removeAttribute(String name, boolean notify, boolean addDeltaRequest) {

    // Validate our current state
    if (!isValid())
        throw new IllegalStateException(sm.getString("standardSession.removeAttribute.ise"));

    // Remove this attribute from our collection
    Object value = null;//  w w w  .ja  v  a 2 s.  c  o  m
    boolean found = false;
    synchronized (attributes) {
        found = attributes.containsKey(name);
        if (found) {
            value = attributes.get(name);
            attributes.remove(name);
        } else {
            return;
        }
    }

    if (addDeltaRequest && (deltaRequest != null))
        deltaRequest.removeAttribute(name);

    // Do we need to do valueUnbound() and attributeRemoved() notification?
    if (!notify) {
        return;
    }

    // Call the valueUnbound() method if necessary
    HttpSessionBindingEvent event = new HttpSessionBindingEvent((HttpSession) this, name, value);
    if ((value != null) && (value instanceof HttpSessionBindingListener))
        ((HttpSessionBindingListener) value).valueUnbound(event);

    // Notify interested application event listeners
    Context context = (Context) manager.getContainer();
    Object listeners[] = context.getApplicationEventListeners();
    if (listeners == null)
        return;
    for (int i = 0; i < listeners.length; i++) {
        if (!(listeners[i] instanceof HttpSessionAttributeListener))
            continue;
        HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners[i];
        try {
            fireContainerEvent(context, "beforeSessionAttributeRemoved", listener);
            listener.attributeRemoved(event);
            fireContainerEvent(context, "afterSessionAttributeRemoved", listener);
        } catch (Throwable t) {
            try {
                fireContainerEvent(context, "afterSessionAttributeRemoved", listener);
            } catch (Exception e) {
                ;
            }
            // FIXME - should we do anything besides log these?
            log.error(sm.getString("standardSession.attributeEvent"), t);
        }
    }

}