Package edu.caltech.nanodb.server
Class SessionState
- java.lang.Object
-
- edu.caltech.nanodb.server.SessionState
-
public class SessionState extends java.lang.Object
This class holds all session state associated with a particular client accessing the database. This object can be stored in thread-local storage to ensure that it can be accessed throughout the database engine to determine current client settings.
-
-
Field Summary
Fields Modifier and Type Field Description private CommandState
cmdState
The command state of this session.private static java.util.concurrent.atomic.AtomicInteger
nextSessionID
This static variable holds the next session ID to assign to a client session.private java.io.PrintStream
outputStream
This is the output stream for the current client.private int
sessionID
The unique session ID assigned to this client session.private static java.lang.ThreadLocal<SessionState>
threadLocalState
private TransactionState
txnState
The transaction state of this session.
-
Constructor Summary
Constructors Modifier Constructor Description private
SessionState(int sessionID)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SessionState
get()
Returns the current session state, possibly initializing a new session with its own unique ID in the process.CommandState
getCommandState()
java.io.PrintStream
getOutputStream()
int
getSessionID()
Returns the unique session ID for this client.TransactionState
getTransactionState()
int
hashCode()
static void
remove()
Removes the session-state from the thread's thread-local storage.void
setOutputStream(java.io.PrintStream out)
-
-
-
Field Detail
-
nextSessionID
private static java.util.concurrent.atomic.AtomicInteger nextSessionID
This static variable holds the next session ID to assign to a client session. It must be accessed in a synchronized manner.
-
threadLocalState
private static java.lang.ThreadLocal<SessionState> threadLocalState
-
sessionID
private int sessionID
The unique session ID assigned to this client session.
-
outputStream
private java.io.PrintStream outputStream
This is the output stream for the current client. If there are multiple clients, writing to this stream will go to the client associated with this session.
-
txnState
private TransactionState txnState
The transaction state of this session.
-
cmdState
private CommandState cmdState
The command state of this session.
-
-
Method Detail
-
get
public static SessionState get()
Returns the current session state, possibly initializing a new session with its own unique ID in the process. This value is stored in thread-local storage, so no thread-safety is required when manipulating the returned object.- Returns:
- the session-state for this local thread.
-
remove
public static void remove()
Removes the session-state from the thread's thread-local storage.
-
getSessionID
public int getSessionID()
Returns the unique session ID for this client.- Returns:
- the unique session ID for this client.
-
getOutputStream
public java.io.PrintStream getOutputStream()
-
setOutputStream
public void setOutputStream(java.io.PrintStream out)
-
getTransactionState
public TransactionState getTransactionState()
-
getCommandState
public CommandState getCommandState()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-