Interface Session
-
- All Known Implementing Classes:
ClusteredSessionImpl,PageTesterSession,SessionImpl
public interface Session
Generic version ofHttpSession, used to bridge the gaps between the Servlet API and the Portlet API.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classSession.LockModeThe type of lock used to access atttributes in theSession.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancontainsAttribute(java.lang.String name)Checks if the a value is stored in the session with the specified name.booleancontainsAttribute(java.lang.String name, Session.LockMode lockMode)Checks if the a value is stored in the session with the specified name.java.lang.ObjectgetAttribute(java.lang.String name)Returns the value previously stored in the session.java.lang.ObjectgetAttribute(java.lang.String name, Session.LockMode lockMode)Returns the value previously stored in the session.java.util.List<java.lang.String>getAttributeNames()Returns a list of the names of all attributes stored in the session.java.util.List<java.lang.String>getAttributeNames(java.lang.String prefix)Returns a list of the names of all attributes stored in the session whose name has the provided prefix.java.util.List<java.lang.String>getAttributeNames(java.lang.String prefix, Session.LockMode lockMode)Returns a list of the names of all attributes stored in the session whose name has the provided prefix.java.util.List<java.lang.String>getAttributeNames(Session.LockMode lockMode)Returns a list of the names of all attributes stored in the session.intgetMaxInactiveInterval()Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.voidinvalidate()Invalidates this session then unbinds any objects bound to it.booleanisInvalidated()Checks to see if the session has been invalidated.voidrestoreDirtyObjects()Re-stores dirty objects back into the session.voidsetAttribute(java.lang.String name, java.lang.Object value)Sets the value of an attribute.voidsetMaxInactiveInterval(int seconds)Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.
-
-
-
Method Detail
-
getAttributeNames
java.util.List<java.lang.String> getAttributeNames()
Returns a list of the names of all attributes stored in the session.The names are returned sorted alphabetically.
By default, a
READlock is requested.
-
getAttributeNames
java.util.List<java.lang.String> getAttributeNames(Session.LockMode lockMode)
Returns a list of the names of all attributes stored in the session.Uses the requested
Session.LockModeto acquire an appropiate lock.- Parameters:
lockMode- The requested minimum lock mode. If null,READis used.- Returns:
- Alphabetically sorted list of all attributes
- Since:
- 5.9
-
getAttributeNames
java.util.List<java.lang.String> getAttributeNames(java.lang.String prefix)
Returns a list of the names of all attributes stored in the session whose name has the provided prefix.By default, a
READlock is requested.- Parameters:
prefix- The attribute prefix- Returns:
- Alphabetically sorted list of attributes matching the prefix
- Throws:
java.lang.NullPointerException- if prefix isnull
-
getAttributeNames
java.util.List<java.lang.String> getAttributeNames(java.lang.String prefix, Session.LockMode lockMode)
Returns a list of the names of all attributes stored in the session whose name has the provided prefix.Uses the requested
Session.LockModeto acquire an appropriate lock.- Parameters:
prefix- The attribute prefix- Returns:
- Alphabetically sorted list of attributes matching the prefix
- Throws:
java.lang.NullPointerException- if prefix isnull- Since:
- 5.9
-
getAttribute
java.lang.Object getAttribute(java.lang.String name)
Returns the value previously stored in the session.By default, a
WRITElock is requested.- Parameters:
name- The name of the attribute- Throws:
java.lang.NullPointerException- if name isnull
-
getAttribute
java.lang.Object getAttribute(java.lang.String name, Session.LockMode lockMode)
Returns the value previously stored in the session.Uses the requested
Session.LockModeto acquire an appropriate lock.- Parameters:
name- The name of the attribute- Throws:
java.lang.NullPointerException- if name isnull- Since:
- 5.9
-
setAttribute
void setAttribute(java.lang.String name, java.lang.Object value)
Sets the value of an attribute. If the value isnull, then the attribute is deleted.- Parameters:
name- The name of the attributevalue- The new value of the attribute;nulldeletes the attribute.- Throws:
java.lang.NullPointerException- if name isnull
-
containsAttribute
boolean containsAttribute(java.lang.String name)
Checks if the a value is stored in the session with the specified name.By default, a
READlock is requested.- Parameters:
name- The name of the attribute- Throws:
java.lang.NullPointerException- if name isnull- Since:
- 5.9
-
containsAttribute
boolean containsAttribute(java.lang.String name, Session.LockMode lockMode)
Checks if the a value is stored in the session with the specified name.Uses the requested
Session.LockModeto acquire an appropriate lock.- Parameters:
name- The name of the attribute- Throws:
java.lang.NullPointerException- if name isnull- Since:
- 5.9
-
getMaxInactiveInterval
int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. After this interval, the servlet container will invalidate the session.The maximum time interval can be set with the setMaxInactiveInterval method.
A negative time indicates the session should never timeout.
-
setMaxInactiveInterval
void setMaxInactiveInterval(int seconds)
Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.A negative time indicates the session should never timeout.
-
invalidate
void invalidate()
Invalidates this session then unbinds any objects bound to it.- Throws:
java.lang.IllegalStateException- if this method is called on an already invalidated session
-
isInvalidated
boolean isInvalidated()
Checks to see if the session has been invalidated. Note: since 5.3 this will also catch calls toHttpSession.invalidate().- Since:
- 5.1.0.0
-
restoreDirtyObjects
void restoreDirtyObjects()
Re-stores dirty objects back into the session. This is necessary to support clustering, because (in most application servers) session objects are only broadcast around the cluster from setAttribute(). If a mutable session object is read and changed, those changes will be limited to a single server in the cluster, which can cause confusing application failures in the event of a failover. Does nothing if there are no changes, or the session has been invalidated.- Since:
- 5.1.0.0
- See Also:
OptimizedSessionPersistedObject,OptimizedSessionPersistedObjectAnalyzer,ImmutableSessionPersistedObject
-
-