java.lang.Object
org.glassfish.grizzly.http.server.Session
Simple session object.
- Author:
- Jeanfrancois Arcand
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongaccess()Updates the "last accessed" timestamp with the current time.Return aConcurrentMapof attributes.getAttribute(String key) Return an attribute.longReturns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.longReturn a long representing the maximum idle time (in milliseconds) a session can be.longbooleanisExpired(long nowNanos) Returnstrueif this session has a positivetimeoutand has not been accessed for longer than that.booleanisNew()Returnstrueif the client does not yet know about the session or if the client chooses not to join the session.booleanisValid()Is the current Session valid?removeAttribute(String key) Remove an attribute.voidsetAttribute(String key, Object value) Add an attribute to this session.protected voidsetIdInternal(String id) Sets the session identifier for this session.voidsetSessionTimeout(long sessionTimeout) Set a long representing the maximum idle time (in milliseconds) a session can be.voidsetTimestamp(long timestamp) Set the timestamp when this session was accessed the last time.voidsetValid(boolean isValid) Set this object as validated.
-
Constructor Details
-
Session
public Session() -
Session
Create a new session using a session identifier- Parameters:
id- session identifier
-
-
Method Details
-
isValid
public boolean isValid()Is the current Session valid?- Returns:
- true if valid.
-
setValid
public void setValid(boolean isValid) Set this object as validated.- Parameters:
isValid-
-
isNew
public boolean isNew()Returnstrueif the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookie-based sessions, and the client had disabled the use of cookies, then a session would be new on each request.- Returns:
trueif the server has created a session, but the client has not yet joined
-
getIdInternal
- Returns:
- the session identifier for this session.
-
setIdInternal
Sets the session identifier for this session.- Parameters:
id-
-
setAttribute
Add an attribute to this session.- Parameters:
key-value-
-
getAttribute
Return an attribute.- Parameters:
key-- Returns:
- an attribute
-
removeAttribute
Remove an attribute.- Parameters:
key-- Returns:
- true if successful.
-
attributes
Return aConcurrentMapof attributes.- Returns:
- the attributes associated with this session.
-
getCreationTime
public long getCreationTime()Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.- Returns:
- a
longspecifying when this session was created, expressed in milliseconds since 1/1/1970 GMT
-
getSessionTimeout
public long getSessionTimeout()Return a long representing the maximum idle time (in milliseconds) a session can be.- Returns:
- a long representing the maximum idle time (in milliseconds) a session can be.
-
setSessionTimeout
public void setSessionTimeout(long sessionTimeout) Set a long representing the maximum idle time (in milliseconds) a session can be.- Parameters:
sessionTimeout- a long representing the maximum idle time (in milliseconds) a session can be.
-
getTimestamp
public long getTimestamp()- Returns:
- the timestamp when this session was accessed the last time
-
setTimestamp
public void setTimestamp(long timestamp) Set the timestamp when this session was accessed the last time. The idle time used for expiration is moved back by the same amount. A timestamp in the future is treated as the current time, so the session still expires at most onetimeoutfrom now.getTimestamp()returns the value as given.- Parameters:
timestamp- a long representing when the session was accessed the last time
-
access
public long access()Updates the "last accessed" timestamp with the current time.- Returns:
- the time stamp
-
isExpired
public boolean isExpired(long nowNanos) Returnstrueif this session has a positivetimeoutand has not been accessed for longer than that. The idle time is measured withSystem.nanoTime(), so system clock changes do not affect it.- Parameters:
nowNanos- the currentSystem.nanoTime()value- Returns:
trueif the session has expired
-