public final class MapSession extends java.lang.Object implements Session, java.io.Serializable
A Session
implementation that is backed by a Map
. The
defaults for the properties are:
MapSession
was instantiatedMapSession
was instantiatedThis implementation has no synchronization, so it is best to use the copy constructor when working on multiple threads.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS
Default
setMaxInactiveInterval(Duration) (30 minutes). |
Constructor and Description |
---|
MapSession()
Creates a new instance with a secure randomly generated identifier.
|
MapSession(Session session)
Creates a new instance from the provided
Session . |
MapSession(java.lang.String id)
Creates a new instance with the specified id.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
changeSessionId()
Changes the session id.
|
boolean |
equals(java.lang.Object obj) |
<T> T |
getAttribute(java.lang.String attributeName)
Gets the Object associated with the specified name or null if no Object is
associated to that name.
|
java.util.Set<java.lang.String> |
getAttributeNames()
Gets the attribute names that have a value associated with it.
|
java.time.Instant |
getCreationTime()
Gets the time when this session was created.
|
java.lang.String |
getId()
Gets a unique string that identifies the
Session . |
java.time.Instant |
getLastAccessedTime()
Gets the last time this
Session was accessed. |
java.time.Duration |
getMaxInactiveInterval()
Gets the maximum inactive interval between requests before this session will be
invalidated.
|
java.lang.String |
getOriginalId()
Get the original session id.
|
int |
hashCode() |
boolean |
isExpired()
Returns true if the session is expired.
|
void |
removeAttribute(java.lang.String attributeName)
Removes the attribute with the provided attribute name.
|
void |
setAttribute(java.lang.String attributeName,
java.lang.Object attributeValue)
Sets the attribute value for the provided attribute name.
|
void |
setCreationTime(java.time.Instant creationTime)
Sets the time that this
Session was created. |
void |
setId(java.lang.String id)
Sets the identifier for this
Session . |
void |
setLastAccessedTime(java.time.Instant lastAccessedTime)
Sets the last accessed time.
|
void |
setMaxInactiveInterval(java.time.Duration interval)
Sets the maximum inactive interval between requests before this session will be
invalidated.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getAttributeOrDefault, getRequiredAttribute
public static final int DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS
setMaxInactiveInterval(Duration)
(30 minutes).public MapSession()
public MapSession(java.lang.String id)
id
- the identifier to usepublic void setLastAccessedTime(java.time.Instant lastAccessedTime)
Session
setLastAccessedTime
in interface Session
lastAccessedTime
- the last accessed timepublic java.time.Instant getCreationTime()
Session
getCreationTime
in interface Session
public java.lang.String getId()
Session
Session
.public java.lang.String getOriginalId()
changeSessionId()
public java.lang.String changeSessionId()
Session
Session.getId()
will return a new identifier.changeSessionId
in interface Session
Session.getId()
will now returnpublic java.time.Instant getLastAccessedTime()
Session
Session
was accessed.getLastAccessedTime
in interface Session
public void setMaxInactiveInterval(java.time.Duration interval)
Session
setMaxInactiveInterval
in interface Session
interval
- the amount of time that the Session
should be kept alive
between client requests.public java.time.Duration getMaxInactiveInterval()
Session
getMaxInactiveInterval
in interface Session
public boolean isExpired()
Session
public <T> T getAttribute(java.lang.String attributeName)
Session
getAttribute
in interface Session
T
- the return type of the attributeattributeName
- the name of the attribute to getpublic java.util.Set<java.lang.String> getAttributeNames()
Session
Session.getAttribute(String)
to
obtain the attribute value.getAttributeNames
in interface Session
Session.getAttribute(String)
public void setAttribute(java.lang.String attributeName, java.lang.Object attributeValue)
Session
Session.removeAttribute(String)
.setAttribute
in interface Session
attributeName
- the attribute name to setattributeValue
- the value of the attribute to set. If null, the attribute
will be removed.public void removeAttribute(java.lang.String attributeName)
Session
removeAttribute
in interface Session
attributeName
- the name of the attribute to removepublic void setCreationTime(java.time.Instant creationTime)
creationTime
- the time that this Session
was created.public void setId(java.lang.String id)
Session
. The id should be a secure random
generated value to prevent malicious users from guessing this value. The default is
a secure random generated identifier.id
- the identifier for this session.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object