Package org.simpleframework.xml.core
Class SessionManager
- java.lang.Object
-
- org.simpleframework.xml.core.SessionManager
-
class SessionManager extends java.lang.ObjectTheSessionManageris used to manage the sessions that are used during the serialization process. Sessions are stored in thread locals so that should aConverterdelegate back in to the same persister instance, it will acquire the same session object. This ensures that converters can be used to resolve cycles in the object graph with theCycleStrategyand also ensures there is no overhead creating new session objects.- See Also:
Session
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSessionManager.ReferenceTheReferenceobject is used to store sessions and count references to them.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.ThreadLocal<SessionManager.Reference>localThis is the thread local used to store the sessions objects.
-
Constructor Summary
Constructors Constructor Description SessionManager()Constructor for theSessionManagerobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()This is used to close the session on the thread local.private Sessioncreate(boolean strict)This is used to create a newSessionobject.Sessionopen()This is used to open a newSessionobject.Sessionopen(boolean strict)This is used to open a newSessionobject.
-
-
-
Field Detail
-
local
private java.lang.ThreadLocal<SessionManager.Reference> local
This is the thread local used to store the sessions objects.
-
-
Constructor Detail
-
SessionManager
public SessionManager()
Constructor for theSessionManagerobject. This is used to create a session manager that stores sessions in a thread local so that it can be reused on multiple invocations to thePersisterobject. References are maintained to each session created so that it is closed when there are no longer any more references to the session.
-
-
Method Detail
-
open
public Session open() throws java.lang.Exception
This is used to open a newSessionobject. If the session exists within the thread local it is returned and a reference count to the session is increased. This ensures that the session is not disposed of until all references to it are closed. By default this creates a strict session.- Returns:
- this returns a strict session from the manager
- Throws:
java.lang.Exception
-
open
public Session open(boolean strict) throws java.lang.Exception
This is used to open a newSessionobject. If the session exists within the thread local it is returned and a reference count to the session is increased. This ensures that the session is not disposed of until all references to it are closed. The strictness of the session can be specified.- Parameters:
strict- this determines if the session is strict- Returns:
- this returns a session from the manager
- Throws:
java.lang.Exception
-
create
private Session create(boolean strict) throws java.lang.Exception
This is used to create a newSessionobject. On creation of the session it is placed on a thread local so that it can be acquired by the current thread when required.- Parameters:
strict- this determines if the session is strict- Returns:
- this returns a new session from the manager
- Throws:
java.lang.Exception
-
close
public void close() throws java.lang.ExceptionThis is used to close the session on the thread local. If the session still has references to it then the reference count is decreased and the session remains open. This ensures that we can make recursive calls in to thePersisterand still use the same session object.- Throws:
java.lang.Exception
-
-