⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deltasession.java

📁 精通tomcat书籍原代码,希望大家共同学习
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    }    /**     * Return the session identifier for this session.     */    public String getIdInternal() {        return (this.id);    }    /**     * Set the session identifier for this session without notify listeners.     *     * @param id     *            The new session identifier     */    public void setIdInternal(String id) {        if ( (this.id != null) && (manager != null)) manager.remove(this);        this.id = id;        if (manager != null) manager.add(this);        if (deltaRequest == null) resetDeltaRequest();        else deltaRequest.setSessionId(id);    }    /**     * Set the session identifier for this session.     *     * @param id     *            The new session identifier     */    public void setId(String id) {        setIdInternal(id);        tellNew();    }    /**     * Inform the listeners about the new session.     *     */    public void tellNew() {        // Notify interested session event listeners        fireSessionEvent(Session.SESSION_CREATED_EVENT, null);        // Notify interested application event listeners        Context context = (Context) manager.getContainer();        //fix for standalone manager without container        if (context != null) {            Object listeners[] = context.getApplicationLifecycleListeners();            if (listeners != null) {                HttpSessionEvent event = new HttpSessionEvent(getSession());                for (int i = 0; i < listeners.length; i++) {                    if (! (listeners[i] instanceof HttpSessionListener))                        continue;                    HttpSessionListener listener = (HttpSessionListener) listeners[i];                    try {                        fireContainerEvent(context, "beforeSessionCreated",listener);                        listener.sessionCreated(event);                        fireContainerEvent(context, "afterSessionCreated",listener);                    } catch (Throwable t) {                        try {                            fireContainerEvent(context, "afterSessionCreated",listener);                        } catch (Exception e) {}                        // FIXME - should we do anything besides log these?                        log.error(sm.getString("standardSession.sessionEvent"),t);                    }                }            }        }    }    /**     * Return descriptive information about this Session implementation and the     * corresponding version number, in the format     * <code>&lt;description&gt;/&lt;version&gt;</code>.     */    public String getInfo() {        return (info);    }    /**     * Return the last time the client sent a request associated with this     * session, as the number of milliseconds since midnight, January 1, 1970     * GMT. Actions that your application takes, such as getting or setting a     * value associated with the session, do not affect the access time.     */    public long getLastAccessedTime() {        if (!isValid()) {            throw new IllegalStateException(sm.getString("standardSession.getId.ise"));        }        return (this.lastAccessedTime);    }    /**     * Return the last client access time without invalidation check     * @see #getLastAccessedTime().     */    public long getLastAccessedTimeInternal() {        return (this.lastAccessedTime);    }    /**     * Return the Manager within which this Session is valid.     */    public Manager getManager() {        return (this.manager);    }    /**     * Set the Manager within which this Session is valid.     *     * @param manager     *            The new Manager     */    public void setManager(Manager manager) {        this.manager = manager;    }    /**     * Return the maximum time interval, in seconds, between client requests     * before the servlet container will invalidate the session. A negative time     * indicates that the session should never time out.     */    public int getMaxInactiveInterval() {        return (this.maxInactiveInterval);    }    /**     * Set the maximum time interval, in seconds, between client requests before     * the servlet container will invalidate the session. A negative time     * indicates that the session should never time out.     *     * @param interval     *            The new maximum interval     */    public void setMaxInactiveInterval(int interval) {        setMaxInactiveInterval(interval, true);    }    public void setMaxInactiveInterval(int interval, boolean addDeltaRequest) {        this.maxInactiveInterval = interval;        if (isValid && interval == 0) {            expire();        } else {            if (addDeltaRequest && (deltaRequest != null))                deltaRequest.setMaxInactiveInterval(interval);        }    }    /**     * Set the <code>isNew</code> flag for this session.     *     * @param isNew     *            The new value for the <code>isNew</code> flag     */    public void setNew(boolean isNew) {        setNew(isNew, true);    }    public void setNew(boolean isNew, boolean addDeltaRequest) {        this.isNew = isNew;        if (addDeltaRequest && (deltaRequest != null))            deltaRequest.setNew(isNew);    }    /**     * Return the authenticated Principal that is associated with this Session.     * This provides an <code>Authenticator</code> with a means to cache a     * previously authenticated Principal, and avoid potentially expensive     * <code>Realm.authenticate()</code> calls on every request. If there is     * no current associated Principal, return <code>null</code>.     */    public Principal getPrincipal() {        return (this.principal);    }    /**     * Set the authenticated Principal that is associated with this Session.     * This provides an <code>Authenticator</code> with a means to cache a     * previously authenticated Principal, and avoid potentially expensive     * <code>Realm.authenticate()</code> calls on every request.     *     * @param principal     *            The new Principal, or <code>null</code> if none     */    public void setPrincipal(Principal principal) {        setPrincipal(principal, true);    }    public void setPrincipal(Principal principal, boolean addDeltaRequest) {        Principal oldPrincipal = this.principal;        this.principal = principal;        support.firePropertyChange("principal", oldPrincipal, this.principal);        if (addDeltaRequest && (deltaRequest != null))            deltaRequest.setPrincipal(principal);    }    /**     * Return the <code>HttpSession</code> for which this object is the     * facade.     */    public HttpSession getSession() {        if (facade == null) {            if (System.getSecurityManager() != null) {                final DeltaSession fsession = this;                facade = (DeltaSessionFacade) AccessController                         .doPrivileged(new PrivilegedAction() {                    public Object run() {                        return new DeltaSessionFacade(fsession);                    }                });            } else {                facade = new DeltaSessionFacade(this);            }        }        return (facade);    }    /**     * Return the <code>isValid</code> flag for this session.     */    public boolean isValid() {        if (this.expiring) {            return true;        }        if (!this.isValid) {            return false;        }        if (accessCount > 0) {            return true;        }        if (maxInactiveInterval >= 0) {            long timeNow = System.currentTimeMillis();            int timeIdle = (int) ( (timeNow - lastAccessedTime) / 1000L);            if (isPrimarySession()) {                if (timeIdle >= maxInactiveInterval) {                    expire(true);                }            } else {                if (timeIdle >= (2 * maxInactiveInterval)) {                    //if the session has been idle twice as long as allowed,                    //the primary session has probably crashed, and no other                    //requests are coming in. that is why we do this. otherwise                    //we would have a memory leak                    expire(true, false);                }            }        }        return (this.isValid);    }    /**     * Set the <code>isValid</code> flag for this session.     *     * @param isValid     *            The new value for the <code>isValid</code> flag     */    public void setValid(boolean isValid) {        this.isValid = isValid;    }    // ------------------------------------------------- Session Public Methods    /**     * Update the accessed time information for this session. This method should     * be called by the context when a request comes in for a particular     * session, even if the application does not reference it.     */    public void access() {        this.lastAccessedTime = this.thisAccessedTime;        this.thisAccessedTime = System.currentTimeMillis();        evaluateIfValid();        accessCount++;    }    public void endAccess() {        isNew = false;        accessCount--;        if (manager instanceof DeltaManager)            ( (DeltaManager) manager).registerSessionAtReplicationValve(this);    }    /**     * Add a session event listener to this component.     */    public void addSessionListener(SessionListener listener) {        synchronized (listeners) {            listeners.add(listener);        }    }    /**     * Perform the internal processing required to invalidate this session,     * without triggering an exception if the session has already expired.     */    public void expire() {        expire(true);    }    /**     * Perform the internal processing required to invalidate this session,     * without triggering an exception if the session has already expired.     *     * @param notify     *            Should we notify listeners about the demise of this session?     */    public void expire(boolean notify) {        expire(notify, true);    }    public void expire(boolean notify, boolean notifyCluster) {        // Mark this session as "being expired" if needed        if (expiring)            return;        String expiredId = getIdInternal();        synchronized (this) {            if (manager == null)                return;            expiring = true;            // Notify interested application event listeners            // FIXME - Assumes we call listeners in reverse order            Context context = (Context) manager.getContainer();            //fix for standalone manager without container            if (context != null) {                Object listeners[] = context.getApplicationLifecycleListeners();                if (notify && (listeners != null)) {                    HttpSessionEvent event = new HttpSessionEvent(getSession());                    for (int i = 0; i < listeners.length; i++) {                        int j = (listeners.length - 1) - i;                        if (! (listeners[j] instanceof HttpSessionListener))                            continue;                        HttpSessionListener listener = (HttpSessionListener) listeners[j];                        try {                            fireContainerEvent(context,"beforeSessionDestroyed", listener);                            listener.sessionDestroyed(event);                            fireContainerEvent(context,"afterSessionDestroyed", listener);                        } catch (Throwable t) {                            try {                                fireContainerEvent(context,"afterSessionDestroyed", listener);                            } catch (Exception e) {                                ;                            }                            // FIXME - should we do anything besides log these?                            log.error(sm.getString("standardSession.sessionEvent"),t);                        }                    }                }            } //end if            //end fix            accessCount = 0;            setValid(false);            // Remove this session from our manager's active sessions            if (manager != null)                manager.remove(this);            // Notify interested session event listeners            if (notify) {                fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);            }            // We have completed expire of this session            expiring = false;            // Unbind any objects associated with this session            String keys[] = keys();            for (int i = 0; i < keys.length; i++)                removeAttributeInternal(keys[i], notify, false);            if (notifyCluster) {                if (log.isDebugEnabled())                    log.debug(sm.getString("deltaSession.notifying",                                           ((DeltaManager)manager).getName(),                                            new Boolean(isPrimarySession()),                                            expiredId));                if ( manager instanceof DeltaManager ) {                    ( (DeltaManager) manager).sessionExpired(expiredId);                }            }        }    }    /**     * Return the object bound with the specified name to the internal notes for     * this session, or <code>null</code> if no such binding exists.     *     * @param name     *            Name of the note to be returned     */    public Object getNote(String name) {        return (notes.get(name));    }    /**     * Return an Iterator containing the String names of all notes bindings that     * exist for this session.     */    public Iterator getNoteNames() {        return (notes.keySet().iterator());    }    /**     * Release all object references, and initialize instance variables, in     * preparation for reuse of this object.     */    public void recycle() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -