Package org.simpleframework.xml.core
Class SessionManager
java.lang.Object
org.simpleframework.xml.core.SessionManager
The
SessionManager is used to manage the sessions that
are used during the serialization process. Sessions are stored in
thread locals so that should a Converter delegate 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 the CycleStrategy and also
ensures there is no overhead creating new session objects.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classTheReferenceobject is used to store sessions and count references to them. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ThreadLocal<SessionManager.Reference> This is the thread local used to store the sessions objects. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This is used to close the session on the thread local.private Sessioncreate(boolean strict) This is used to create a newSessionobject.open()This is used to open a newSessionobject.open(boolean strict) This is used to open a newSessionobject.
-
Field Details
-
local
This is the thread local used to store the sessions objects.
-
-
Constructor Details
-
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 Details
-
open
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:
Exception
-
open
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:
Exception
-
create
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:
Exception
-
close
This 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:
Exception
-