]> git.somenet.org - pub/jan/dst18.git/blob - ass1-kv/src/main/java/dst/ass1/kv/ISessionManager.java
Add template for assignment 1
[pub/jan/dst18.git] / ass1-kv / src / main / java / dst / ass1 / kv / ISessionManager.java
1 package dst.ass1.kv;
2
3 public interface ISessionManager {
4
5     /**
6      * Creates a new session id and stores the userId and session timeout under the given id in the session store.
7      *
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
12      */
13     String createSession(Long userId, int timeToLive) throws SessionCreationFailedException;
14
15     /**
16      * Sets a key--value pair in the given session.
17      *
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
22      */
23     void setSessionVariable(String sessionId, String key, String value) throws SessionNotFoundException;
24
25     /**
26      * Returns the value of the given session variable.
27      *
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
32      */
33     String getSessionVariable(String sessionId, String key) throws SessionNotFoundException;
34
35     /**
36      * Returns the user to whom the given session belongs.
37      *
38      * @param sessionId the session id
39      * @return the user id
40      * @throws SessionNotFoundException if the given session id has expired or doesn't exist
41      */
42     Long getUserId(String sessionId) throws SessionNotFoundException;
43
44     /**
45      * Returns the current time-to-live for the given session.
46      *
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
50      */
51     int getTimeToLive(String sessionId) throws SessionNotFoundException;
52
53     /**
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
56      * returned.
57      *
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
62      */
63     String requireSession(Long userId, int timeToLive) throws SessionCreationFailedException;
64
65     /**
66      * Closes whatever underlying connection is required to maintain the session manager.
67      */
68     void close();
69 }