/** * Clear all of this session's attributes. */ public void clearAttributes() { for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } }
@Override public void removeAttribute(String name) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); Object value = this.attributes.remove(name); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } }
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
/** * Clear all of this session's attributes. */ public void clearAttributes() { for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } }
@Override public void setAttribute(String name, @Nullable Object value) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); if (value != null) { Object oldValue = this.attributes.put(name, value); if (value != oldValue) { if (oldValue instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } } else { removeAttribute(name); } }
protected void afterBound(String s, Object o) { if (o instanceof HttpSessionBindingListener) { HttpSessionBindingListener listener = (HttpSessionBindingListener) o; HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, s, o); listener.valueBound(event); } }
protected void afterUnbound(String s, Object o) { if (o instanceof HttpSessionBindingListener) { HttpSessionBindingListener listener = (HttpSessionBindingListener) o; HttpSessionBindingEvent event = new HttpSessionBindingEvent(this, s, o); listener.valueUnbound(event); } }
@Override public void removeAttribute(String name) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); Object value = this.attributes.remove(name); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } }
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
/** * Clear all of this session's attributes. */ public void clearAttributes() { for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } }
@Override public void setAttribute(String name, Object value) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); if (value != null) { this.attributes.put(name, value); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } else { removeAttribute(name); } }
@Override public void removeAttribute(String name) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); Object value = this.attributes.remove(name); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } }
/** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. * @return a representation of this session's serialized state */ public Serializable serializeState() { HashMap<String, Serializable> state = new HashMap<>(); for (Iterator<Map.Entry<String, Object>> it = this.attributes.entrySet().iterator(); it.hasNext();) { Map.Entry<String, Object> entry = it.next(); String name = entry.getKey(); Object value = entry.getValue(); it.remove(); if (value instanceof Serializable) { state.put(name, (Serializable) value); } else { // Not serializable... Servlet containers usually automatically // unbind the attribute in this case. if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueUnbound(new HttpSessionBindingEvent(this, name, value)); } } } return state; }
@Override public void setAttribute(String name, @Nullable Object value) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); if (value != null) { Object oldValue = this.attributes.put(name, value); if (value != oldValue) { if (oldValue instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) oldValue).valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value).valueBound(new HttpSessionBindingEvent(this, name, value)); } } } else { removeAttribute(name); } }
@Override public void setAttribute(String name, Object value) { checkState(); Object oldValue = this.session.getAttribute(name); this.session.setAttribute(name, value); if (value != oldValue) { if (oldValue instanceof HttpSessionBindingListener) { try { ((HttpSessionBindingListener) oldValue).valueUnbound( new HttpSessionBindingEvent(this, name, oldValue)); } catch (Throwable th) { logger.error("Error invoking session binding event listener", th); } } if (value instanceof HttpSessionBindingListener) { try { ((HttpSessionBindingListener) value) .valueBound(new HttpSessionBindingEvent(this, name, value)); } catch (Throwable th) { logger.error("Error invoking session binding event listener", th); } } } }
@Override public void removeAttribute(String name) { checkState(); Object oldValue = this.session.getAttribute(name); this.session.removeAttribute(name); if (oldValue instanceof HttpSessionBindingListener) { try { ((HttpSessionBindingListener) oldValue) .valueUnbound(new HttpSessionBindingEvent(this, name, oldValue)); } catch (Throwable th) { logger.error("Error invoking session binding event listener", th); } } }
@CacheEntryRemoved public void removed(CacheEntryRemovedEvent<SessionCreationMetaDataKey, ?> event) { if (event.isPre()) { String id = event.getKey().getValue(); InfinispanWebLogger.ROOT_LOGGER.tracef("Session %s will be removed", id); Map.Entry<MV, AV> value = this.factory.findValue(id); if (value != null) { ImmutableSession session = this.factory.createImmutableSession(id, value); ImmutableSessionAttributes attributes = session.getAttributes(); HttpSession httpSession = new ImmutableHttpSessionAdapter(session, this.context); for (String name: attributes.getAttributeNames()) { Object attribute = attributes.getAttribute(name); if (attribute instanceof HttpSessionBindingListener) { HttpSessionBindingListener listener = (HttpSessionBindingListener) attribute; listener.valueUnbound(new HttpSessionBindingEvent(httpSession, name, attribute)); } } if (this.recorder != null) { this.recorder.record(session); } } } }
protected HttpSessionBindingEvent getHttpSessionBindingEvent( HttpSessionBindingEvent httpSessionBindingEvent) { if (CompoundSessionIdSplitterUtil.hasSessionDelimiter()) { CompoundSessionIdHttpSession compoundSessionIdHttpSession = new CompoundSessionIdHttpSession( httpSessionBindingEvent.getSession()); httpSessionBindingEvent = new HttpSessionBindingEvent( compoundSessionIdHttpSession, httpSessionBindingEvent.getName(), httpSessionBindingEvent.getValue()); } return httpSessionBindingEvent; }
@Override public void removeAttribute(String name) { if (attributes != null) { Object value = attributes.get(name); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value) .valueUnbound(new HttpSessionBindingEvent(this, name, value)); } attributes.remove(name); } }
@Override public void setAttribute(String name, Object value) { if (attributes == null) { attributes = new ConcurrentHashMap<>(); } attributes.put(name, value); if (value instanceof HttpSessionBindingListener) { ((HttpSessionBindingListener) value) .valueBound(new HttpSessionBindingEvent(this, name, value)); } }