001    // Copyright 2006, 2008 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry5.services;
016    
017    import javax.servlet.http.HttpSession;
018    import java.util.List;
019    
020    /**
021     * Generic version of {@link HttpSession}, used to bridge the gaps between the Servlet API and the Portlet API.
022     */
023    public interface Session
024    {
025        /**
026         * Returns a list of the names of all attributes stored in the session. The names are returned sorted
027         * alphabetically.
028         */
029        List<String> getAttributeNames();
030    
031        /**
032         * Returns a list of the names of all attributes stored in the session whose name has the provided prefix. The names
033         * are returned in alphabetical order.
034         */
035        List<String> getAttributeNames(String prefix);
036    
037        /**
038         * Returns the value previously stored in the session.
039         */
040        Object getAttribute(String name);
041    
042        /**
043         * Sets the value of an attribute. If the value is null, then the attribute is deleted.
044         */
045        void setAttribute(String name, Object value);
046    
047        /**
048         * Returns the maximum time interval, in seconds, that the servlet container will keep this session open between
049         * client accesses. After this interval, the servlet container will invalidate the session. The maximum time
050         * interval can be set with the setMaxInactiveInterval method. A negative time indicates the session should never
051         * timeout.
052         */
053        int getMaxInactiveInterval();
054    
055        /**
056         * Specifies the time, in seconds, between client requests before the servlet container will invalidate this
057         * session. A negative time indicates the session should never timeout.
058         */
059        void setMaxInactiveInterval(int seconds);
060    
061        /**
062         * Invalidates this session then unbinds any objects bound to it.
063         *
064         * @throws IllegalStateException if this method is called on an already invalidated session
065         */
066        void invalidate();
067    
068        /**
069         * Checks to see if the session has been invalidated.  Note: this only catches calls to {@link #invalidate()}, not
070         * calls to {@link javax.servlet.http.HttpSession#invalidate()}.
071         *
072         * @since 5.1.0.0
073         */
074        boolean isInvalidated();
075    
076        /**
077         * Re-stores dirty objects back into the session.  This is necessary to support clustering, because (in most
078         * application servers) session objects are only broadcast around the cluster from setAttribute().  If a mutable
079         * session object is read and changed, those changes will be limited to a single server in the cluster, which can
080         * cause confusing application failures in the event of a failover.      Does nothing if there are no changes, or
081         * the session has been invalidated.
082         *
083         * @see org.apache.tapestry5.OptimizedSessionPersistedObject
084         * @see org.apache.tapestry5.internal.services.OptimizedApplicationStateObjectAnalyzer
085         * @see org.apache.tapestry5.annotations.ImmutableSessionPersistedObject
086         * @since 5.1.0.0
087         */
088        void restoreDirtyObjects();
089    }