Class SessionManager

java.lang.Object
org.simpleframework.xml.core.SessionManager

class SessionManager extends Object
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 Classes
    Modifier and Type
    Class
    Description
    private static class 
    The Reference object is used to store sessions and count references to them.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    This is the thread local used to store the sessions objects.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor for the SessionManager object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This is used to close the session on the thread local.
    private Session
    create(boolean strict)
    This is used to create a new Session object.
    This is used to open a new Session object.
    open(boolean strict)
    This is used to open a new Session object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • SessionManager

      public SessionManager()
      Constructor for the SessionManager object. 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 the Persister object. 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

      public Session open() throws Exception
      This is used to open a new Session object. 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

      public Session open(boolean strict) throws Exception
      This is used to open a new Session object. 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

      private Session create(boolean strict) throws Exception
      This is used to create a new Session object. 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

      public void close() throws Exception
      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 the Persister and still use the same session object.
      Throws:
      Exception