3 public interface ISessionManager {
6 * Creates a new session id and stores the userId and session timeout under the given id in the session store.
8 * @param userId the user to create the session for
9 * @param timeToLive the session timeout after which the session expires in seconds
10 * @return the session id.
11 * @throws SessionCreationFailedException if the session couldn't be created, e.g., due to a failed transaction
13 String createSession(Long userId, int timeToLive) throws SessionCreationFailedException;
16 * Sets a key--value pair in the given session.
18 * @param sessionId the session to store the variable in
19 * @param key the name of the variable
20 * @param value the value
21 * @throws SessionNotFoundException if the session wasn't found
23 void setSessionVariable(String sessionId, String key, String value) throws SessionNotFoundException;
26 * Returns the value of the given session variable.
28 * @param sessionId the session id
29 * @param key the name of the variable
30 * @return the variable value, or null if it doesn't exist
31 * @throws SessionNotFoundException if the given session id has expired or doesn't exist
33 String getSessionVariable(String sessionId, String key) throws SessionNotFoundException;
36 * Returns the user to whom the given session belongs.
38 * @param sessionId the session id
40 * @throws SessionNotFoundException if the given session id has expired or doesn't exist
42 Long getUserId(String sessionId) throws SessionNotFoundException;
45 * Returns the current time-to-live for the given session.
47 * @param sessionId the session id
48 * @return the session ttl in seconds
49 * @throws SessionNotFoundException if the given session id has expired or doesn't exist
51 int getTimeToLive(String sessionId) throws SessionNotFoundException;
54 * Checks whether the given user has an open session, if so, the session id is returned (and the timeout
55 * parameter ignored), otherwise a new session is created with the given timeout and the newly generated id is
58 * @param userId the user to require the session for
59 * @param timeToLive the session timeout after which the session expires in seconds
60 * @return the session id.
61 * @throws SessionCreationFailedException if the session couldn't be created, e.g., due to a failed transaction
63 String requireSession(Long userId, int timeToLive) throws SessionCreationFailedException;
66 * Closes whatever underlying connection is required to maintain the session manager.