Class Session
- java.lang.Object
-
- org.glassfish.grizzly.http.server.Session
-
public class Session extends Object
Simple session object.- Author:
- Jeanfrancois Arcand
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longaccess()Updates the "last accessed" timestamp with the current time.ConcurrentMap<String,Object>attributes()Return aConcurrentMapof attributes.ObjectgetAttribute(String key)Return an attribute.longgetCreationTime()Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.StringgetIdInternal()longgetSessionTimeout()Return a long representing the maximum idle time (in milliseconds) a session can be.longgetTimestamp()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?ObjectremoveAttribute(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 Detail
-
Session
public Session()
-
Session
public Session(String id)
Create a new session using a session identifier- Parameters:
id- session identifier
-
-
Method Detail
-
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
public String getIdInternal()
- Returns:
- the session identifier for this session.
-
setIdInternal
protected void setIdInternal(String id)
Sets the session identifier for this session.- Parameters:
id-
-
setAttribute
public void setAttribute(String key, Object value)
Add an attribute to this session.- Parameters:
key-value-
-
getAttribute
public Object getAttribute(String key)
Return an attribute.- Parameters:
key-- Returns:
- an attribute
-
removeAttribute
public Object removeAttribute(String key)
Remove an attribute.- Parameters:
key-- Returns:
- true if successful.
-
attributes
public ConcurrentMap<String,Object> 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.- 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
-
-