📄 abstractsessionmanager.java
字号:
_values=newAttributeMap(); } /* ------------------------------------------------------------ */ public synchronized Object getAttribute(String name) { if (_invalid) throw new IllegalStateException(); if (null == _values) return null; return _values.get(name); } /* ------------------------------------------------------------ */ public synchronized Enumeration getAttributeNames() { if (_invalid) throw new IllegalStateException(); List names=_values==null?Collections.EMPTY_LIST:new ArrayList(_values.keySet()); return Collections.enumeration(names); } /* ------------------------------------------------------------- */ public long getCookieSetTime() { return _cookieSet; } /* ------------------------------------------------------------- */ public long getCreationTime() throws IllegalStateException { if (_invalid) throw new IllegalStateException(); return _created; } /* ------------------------------------------------------------ */ public String getId() throws IllegalStateException { return _nodeIdInSessionId?_nodeId:_clusterId; } /* ------------------------------------------------------------- */ protected String getNodeId() { return _nodeId; } /* ------------------------------------------------------------- */ protected String getClusterId() { return _clusterId; } /* ------------------------------------------------------------- */ public long getLastAccessedTime() throws IllegalStateException { if (_invalid) throw new IllegalStateException(); return _lastAccessed; } /* ------------------------------------------------------------- */ public int getMaxInactiveInterval() { if (_invalid) throw new IllegalStateException(); return (int)(_maxIdleMs/1000); } /* ------------------------------------------------------------ */ /* * @see javax.servlet.http.HttpSession#getServletContext() */ public ServletContext getServletContext() { return _context; } /* ------------------------------------------------------------- */ /** * @deprecated */ public HttpSessionContext getSessionContext() throws IllegalStateException { if (_invalid) throw new IllegalStateException(); return __nullSessionContext; } /* ------------------------------------------------------------- */ /** * @deprecated As of Version 2.2, this method is replaced by * {@link #getAttribute} */ public Object getValue(String name) throws IllegalStateException { return getAttribute(name); } /* ------------------------------------------------------------- */ /** * @deprecated As of Version 2.2, this method is replaced by * {@link #getAttributeNames} */ public synchronized String[] getValueNames() throws IllegalStateException { if (_invalid) throw new IllegalStateException(); if (_values==null) return new String[0]; String[] a=new String[_values.size()]; return (String[])_values.keySet().toArray(a); } /* ------------------------------------------------------------ */ protected void access(long time) { synchronized(this) { _newSession=false; _lastAccessed=_accessed; _accessed=time; _requests++; } } /* ------------------------------------------------------------ */ protected void complete() { synchronized(this) { _requests--; if (_doInvalidate && _requests<=0 ) doInvalidate(); } } /* ------------------------------------------------------------- */ protected void timeout() throws IllegalStateException { // remove session from context and invalidate other sessions with same ID. removeSession(this,true); // Notify listeners and unbind values synchronized (this) { if (_requests<=0) doInvalidate(); else _doInvalidate=true; } } /* ------------------------------------------------------------- */ public void invalidate() throws IllegalStateException { // remove session from context and invalidate other sessions with same ID. removeSession(this,true); doInvalidate(); } /* ------------------------------------------------------------- */ protected void doInvalidate() throws IllegalStateException { try { // Notify listeners and unbind values if (_invalid) throw new IllegalStateException(); while (_values!=null && _values.size()>0) { ArrayList keys; synchronized (this) { keys=new ArrayList(_values.keySet()); } Iterator iter=keys.iterator(); while (iter.hasNext()) { String key=(String)iter.next(); Object value; synchronized (this) { value=_values.remove(key); } unbindValue(key,value); if (_sessionAttributeListeners!=null) { HttpSessionBindingEvent event=new HttpSessionBindingEvent(this,key,value); for (int i=0; i<LazyList.size(_sessionAttributeListeners); i++) ((HttpSessionAttributeListener)LazyList.get(_sessionAttributeListeners,i)).attributeRemoved(event); } } } } finally { // mark as invalid _invalid=true; } } /* ------------------------------------------------------------- */ public boolean isIdChanged() { return _idChanged; } /* ------------------------------------------------------------- */ public boolean isNew() throws IllegalStateException { if (_invalid) throw new IllegalStateException(); return _newSession; } /* ------------------------------------------------------------- */ /** * @deprecated As of Version 2.2, this method is replaced by * {@link #setAttribute} */ public void putValue(java.lang.String name, java.lang.Object value) throws IllegalStateException { setAttribute(name,value); } /* ------------------------------------------------------------ */ public synchronized void removeAttribute(String name) { if (_invalid) throw new IllegalStateException(); if (_values==null) return; Object old=_values.remove(name); if (old!=null) { unbindValue(name,old); if (_sessionAttributeListeners!=null) { HttpSessionBindingEvent event=new HttpSessionBindingEvent(this,name,old); for (int i=0; i<LazyList.size(_sessionAttributeListeners); i++) ((HttpSessionAttributeListener)LazyList.get(_sessionAttributeListeners,i)).attributeRemoved(event); } } } /* ------------------------------------------------------------- */ /** * @deprecated As of Version 2.2, this method is replaced by * {@link #removeAttribute} */ public void removeValue(java.lang.String name) throws IllegalStateException { removeAttribute(name); } /* ------------------------------------------------------------ */ public synchronized void setAttribute(String name, Object value) { if (value==null) { removeAttribute(name); return; } if (_invalid) throw new IllegalStateException(); if (_values==null) _values=newAttributeMap(); Object oldValue=_values.put(name,value); if (oldValue==null || !value.equals(oldValue)) { unbindValue(name,oldValue); bindValue(name,value); if (_sessionAttributeListeners!=null) { HttpSessionBindingEvent event=new HttpSessionBindingEvent(this,name,oldValue==null?value:oldValue); for (int i=0; i<LazyList.size(_sessionAttributeListeners); i++) { HttpSessionAttributeListener l=(HttpSessionAttributeListener)LazyList.get(_sessionAttributeListeners,i); if (oldValue==null) l.attributeAdded(event); else if (value==null) l.attributeRemoved(event); else l.attributeReplaced(event); } } } } /* ------------------------------------------------------------- */ public void setIdChanged(boolean changed) { _idChanged=changed; } /* ------------------------------------------------------------- */ public void setMaxInactiveInterval(int secs) { _maxIdleMs=(long)secs*1000; } /* ------------------------------------------------------------- */ public String toString() { return this.getClass().getName()+":"+getId()+"@"+hashCode(); } /* ------------------------------------------------------------- */ /** If value implements HttpSessionBindingListener, call valueBound() */ protected void bindValue(java.lang.String name, Object value) { if (value!=null&&value instanceof HttpSessionBindingListener) ((HttpSessionBindingListener)value).valueBound(new HttpSessionBindingEvent(this,name)); } /* ------------------------------------------------------------ */ protected boolean isValid() { return !_invalid; } /* ------------------------------------------------------------ */ protected abstract Map newAttributeMap(); /* ------------------------------------------------------------- */ protected void cookieSet() { _cookieSet=_accessed; } /* ------------------------------------------------------------- */ /** If value implements HttpSessionBindingListener, call valueUnbound() */ protected void unbindValue(java.lang.String name, Object value) { if (value!=null&&value instanceof HttpSessionBindingListener) ((HttpSessionBindingListener)value).valueUnbound(new HttpSessionBindingEvent(this,name)); } /* ------------------------------------------------------------- */ protected synchronized void willPassivate() { HttpSessionEvent event = new HttpSessionEvent(this); for (Iterator iter = _values.values().iterator(); iter.hasNext();) { Object value = iter.next(); if (value instanceof HttpSessionActivationListener) { HttpSessionActivationListener listener = (HttpSessionActivationListener) value; listener.sessionWillPassivate(event); } } } /* ------------------------------------------------------------- */ protected synchronized void didActivate() { HttpSessionEvent event = new HttpSessionEvent(this); for (Iterator iter = _values.values().iterator(); iter.hasNext();) { Object value = iter.next(); if (value instanceof HttpSessionActivationListener) { HttpSessionActivationListener listener = (HttpSessionActivationListener) value; listener.sessionDidActivate(event); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -