Class SessionState
- java.lang.Object
-
- org.apache.jackrabbit.core.session.SessionState
-
public class SessionState extends Object
Internal session state. This class keeps track of the lifecycle of a session and controls concurrent access to the session internals.The session lifecycle is pretty simple: there are only two lifecycle states, "alive" and "closed", and only one possible state transition, from "alive" to "closed".
Concurrent access to session internals is controlled by the
perform(SessionOperation)
method that guarantees that no twooperations
are performed concurrently on the same session.- See Also:
- JCR-890
-
-
Constructor Summary
Constructors Constructor Description SessionState(SessionContext context)
Creates a state instance for a session.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkAlive()
Throws an exception if this session is not alive.boolean
close()
Closes this session.boolean
isAlive()
Checks whether this session is alive.<T> T
perform(SessionOperation<T> operation)
Performs the given operation within a synchronized block.
-
-
-
Constructor Detail
-
SessionState
public SessionState(SessionContext context)
Creates a state instance for a session.- Parameters:
context
- component context of this session
-
-
Method Detail
-
isAlive
public boolean isAlive()
Checks whether this session is alive. This method should generally only be called from within a performedSessionOperation
, as otherwise there's no guarantee against another thread closing the session right after this method has returned.- Returns:
true
if the session is alive,false
otherwise- See Also:
Session.isLive()
-
checkAlive
public void checkAlive() throws RepositoryException
Throws an exception if this session is not alive.- Throws:
RepositoryException
- throw if this session is not alive
-
perform
public <T> T perform(SessionOperation<T> operation) throws RepositoryException
Performs the given operation within a synchronized block. Special care is made to detect attempts to access the session concurrently and to log detailed warnings in such cases.- Parameters:
operation
- session operation- Returns:
- the return value of the executed operation
- Throws:
RepositoryException
- if the operation fails or if the session has already been closed
-
close
public boolean close()
Closes this session. Special care is made to detect attempts to access the session concurrently or to close it more than once, and to log detailed warnings in such cases.- Returns:
true
if the session was closed, orfalse
if the session had already been closed
-
-