public final class MapSession extends java.lang.Object implements ExpiringSession, 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
setMaxInactiveIntervalInSeconds(int) (30 minutes). |
Constructor and Description |
---|
MapSession()
Creates a new instance with a secure randomly generated identifier.
|
MapSession(ExpiringSession 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 |
---|---|
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.
|
long |
getCreationTime()
Gets the time when this session was created in milliseconds since midnight of
1/1/1970 GMT.
|
java.lang.String |
getId()
Gets a unique string that identifies the
Session . |
long |
getLastAccessedTime()
Gets the last time this
Session was accessed expressed in milliseconds
since midnight of 1/1/1970 GMT. |
int |
getMaxInactiveIntervalInSeconds()
Gets the maximum inactive interval in seconds between requests before this session
will be invalidated.
|
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(long creationTime)
Sets the time that this
Session was created in milliseconds since midnight
of 1/1/1970 GMT. |
void |
setId(java.lang.String id)
Sets the identifier for this
Session . |
void |
setLastAccessedTime(long lastAccessedTime)
Sets the last accessed time in milliseconds since midnight of 1/1/1970 GMT.
|
void |
setMaxInactiveIntervalInSeconds(int interval)
Sets the maximum inactive interval in seconds between requests before this session
will be invalidated.
|
public static final int DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS
setMaxInactiveIntervalInSeconds(int)
(30 minutes).public MapSession()
public MapSession(java.lang.String id)
id
- the identifier to usepublic MapSession(ExpiringSession session)
Session
.public void setLastAccessedTime(long lastAccessedTime)
ExpiringSession
setLastAccessedTime
in interface ExpiringSession
lastAccessedTime
- the last accessed time in milliseconds since midnight of
1/1/1970 GMTpublic long getCreationTime()
ExpiringSession
getCreationTime
in interface ExpiringSession
public java.lang.String getId()
Session
Session
.public long getLastAccessedTime()
ExpiringSession
Session
was accessed expressed in milliseconds
since midnight of 1/1/1970 GMT.getLastAccessedTime
in interface ExpiringSession
public void setMaxInactiveIntervalInSeconds(int interval)
ExpiringSession
setMaxInactiveIntervalInSeconds
in interface ExpiringSession
interval
- the number of seconds that the Session
should be kept alive
between client requests.public int getMaxInactiveIntervalInSeconds()
ExpiringSession
getMaxInactiveIntervalInSeconds
in interface ExpiringSession
public boolean isExpired()
ExpiringSession
isExpired
in interface ExpiringSession
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(long creationTime)
Session
was created in milliseconds since midnight
of 1/1/1970 GMT. The default is when the Session
was instantiated.creationTime
- the time that this Session
was created in milliseconds
since midnight of 1/1/1970 GMT.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