Search in sources :

Example 6 with SessionListener

use of org.apache.catalina.SessionListener in project tomcat by apache.

the class StandardSessionContext method fireSessionEvent.

// ------------------------------------------------------ Protected Methods
/**
     * Notify all session event listeners that a particular event has
     * occurred for this Session.  The default implementation performs
     * this notification synchronously using the calling thread.
     *
     * @param type Event type
     * @param data Event data
     */
public void fireSessionEvent(String type, Object data) {
    if (listeners.size() < 1)
        return;
    SessionEvent event = new SessionEvent(this, type, data);
    SessionListener[] list = new SessionListener[0];
    synchronized (listeners) {
        list = listeners.toArray(list);
    }
    for (int i = 0; i < list.length; i++) {
        (list[i]).sessionEvent(event);
    }
}
Also used : HttpSessionEvent(javax.servlet.http.HttpSessionEvent) SessionEvent(org.apache.catalina.SessionEvent) HttpSessionListener(javax.servlet.http.HttpSessionListener) SessionListener(org.apache.catalina.SessionListener)

Example 7 with SessionListener

use of org.apache.catalina.SessionListener in project tomcat70 by apache.

the class DeltaSession method readObject.

private void readObject(ObjectInput stream) throws ClassNotFoundException, IOException {
    // Deserialize the scalar instance variables (except Manager)
    // Transient only
    authType = null;
    creationTime = ((Long) stream.readObject()).longValue();
    lastAccessedTime = ((Long) stream.readObject()).longValue();
    maxInactiveInterval = ((Integer) stream.readObject()).intValue();
    isNew = ((Boolean) stream.readObject()).booleanValue();
    isValid = ((Boolean) stream.readObject()).booleanValue();
    thisAccessedTime = ((Long) stream.readObject()).longValue();
    version = ((Long) stream.readObject()).longValue();
    boolean hasPrincipal = stream.readBoolean();
    principal = null;
    if (hasPrincipal) {
        principal = SerializablePrincipal.readPrincipal(stream);
    }
    // setId((String) stream.readObject());
    id = (String) stream.readObject();
    if (log.isDebugEnabled())
        log.debug(sm.getString("deltaSession.readSession", id));
    // Deserialize the attribute count and attribute values
    if (attributes == null)
        attributes = new ConcurrentHashMap<String, Object>();
    int n = ((Integer) stream.readObject()).intValue();
    boolean isValidSave = isValid;
    isValid = true;
    for (int i = 0; i < n; i++) {
        String name = (String) stream.readObject();
        final Object value;
        try {
            value = stream.readObject();
        } catch (WriteAbortedException wae) {
            if (wae.getCause() instanceof NotSerializableException) {
                // Skip non serializable attributes
                continue;
            }
            throw wae;
        }
        // the web application was stopped.
        if (exclude(name, value)) {
            continue;
        }
        attributes.put(name, value);
    }
    isValid = isValidSave;
    // Session listeners
    n = ((Integer) stream.readObject()).intValue();
    if (listeners == null || n > 0) {
        listeners = new ArrayList<SessionListener>();
    }
    for (int i = 0; i < n; i++) {
        SessionListener listener = (SessionListener) stream.readObject();
        listeners.add(listener);
    }
    if (notes == null) {
        notes = new Hashtable<String, Object>();
    }
    activate();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NotSerializableException(java.io.NotSerializableException) WriteAbortedException(java.io.WriteAbortedException) SessionListener(org.apache.catalina.SessionListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 8 with SessionListener

use of org.apache.catalina.SessionListener in project tomcat70 by apache.

the class DeltaSession method writeObject.

private void writeObject(ObjectOutput stream) throws IOException {
    // Write the scalar instance variables (except Manager)
    stream.writeObject(Long.valueOf(creationTime));
    stream.writeObject(Long.valueOf(lastAccessedTime));
    stream.writeObject(Integer.valueOf(maxInactiveInterval));
    stream.writeObject(Boolean.valueOf(isNew));
    stream.writeObject(Boolean.valueOf(isValid));
    stream.writeObject(Long.valueOf(thisAccessedTime));
    stream.writeObject(Long.valueOf(version));
    stream.writeBoolean(getPrincipal() != null);
    if (getPrincipal() != null) {
        SerializablePrincipal.writePrincipal((GenericPrincipal) principal, stream);
    }
    stream.writeObject(id);
    if (log.isDebugEnabled())
        log.debug(sm.getString("deltaSession.writeSession", id));
    // Accumulate the names of serializable and non-serializable attributes
    String[] keys = keys();
    ArrayList<String> saveNames = new ArrayList<String>();
    ArrayList<Object> saveValues = new ArrayList<Object>();
    for (int i = 0; i < keys.length; i++) {
        Object value = null;
        value = attributes.get(keys[i]);
        if (value != null && !exclude(keys[i], value) && isAttributeDistributable(keys[i], value)) {
            saveNames.add(keys[i]);
            saveValues.add(value);
        }
    }
    // Serialize the attribute count and the Serializable attributes
    int n = saveNames.size();
    stream.writeObject(Integer.valueOf(n));
    for (int i = 0; i < n; i++) {
        stream.writeObject(saveNames.get(i));
        try {
            stream.writeObject(saveValues.get(i));
        } catch (NotSerializableException e) {
            log.error(sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
        }
    }
    // Serializable listeners
    ArrayList<SessionListener> saveListeners = new ArrayList<SessionListener>();
    for (SessionListener listener : listeners) {
        if (listener instanceof ReplicatedSessionListener) {
            saveListeners.add(listener);
        }
    }
    stream.writeObject(Integer.valueOf(saveListeners.size()));
    for (SessionListener listener : saveListeners) {
        stream.writeObject(listener);
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) ArrayList(java.util.ArrayList) SessionListener(org.apache.catalina.SessionListener)

Example 9 with SessionListener

use of org.apache.catalina.SessionListener in project tomcat by apache.

the class StandardSession method fireSessionEvent.

// ------------------------------------------------------ Protected Methods
/**
 * Notify all session event listeners that a particular event has
 * occurred for this Session.  The default implementation performs
 * this notification synchronously using the calling thread.
 *
 * @param type Event type
 * @param data Event data
 */
public void fireSessionEvent(String type, Object data) {
    if (listeners.size() < 1) {
        return;
    }
    SessionEvent event = new SessionEvent(this, type, data);
    SessionListener[] list = new SessionListener[0];
    synchronized (listeners) {
        list = listeners.toArray(list);
    }
    for (SessionListener sessionListener : list) {
        sessionListener.sessionEvent(event);
    }
}
Also used : SessionEvent(org.apache.catalina.SessionEvent) HttpSessionEvent(jakarta.servlet.http.HttpSessionEvent) HttpSessionListener(jakarta.servlet.http.HttpSessionListener) SessionListener(org.apache.catalina.SessionListener)

Aggregations

SessionListener (org.apache.catalina.SessionListener)9 NotSerializableException (java.io.NotSerializableException)4 SessionEvent (org.apache.catalina.SessionEvent)3 WriteAbortedException (java.io.WriteAbortedException)2 Principal (java.security.Principal)2 ArrayList (java.util.ArrayList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 HttpSessionEvent (javax.servlet.http.HttpSessionEvent)2 HttpSessionListener (javax.servlet.http.HttpSessionListener)2 GenericPrincipal (org.apache.catalina.realm.GenericPrincipal)2 HttpSessionEvent (jakarta.servlet.http.HttpSessionEvent)1 HttpSessionListener (jakarta.servlet.http.HttpSessionListener)1 Serializable (java.io.Serializable)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1