Package org.apache.tapestry5.http.internal.services

# Class SessionImpl

java.lang.Object
org.apache.tapestry5.http.internal.services.SessionImpl

All Implemented Interfaces:
  `Session`

Direct Known Subclasses:
  `ClusteredSessionImpl`

public class SessionImpl extends Object implements Session
A thin wrapper around `HttpSession`.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface org.apache.tapestry5.http.services.Session

  `Session.LockMode`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SessionImpl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session, SessionLock lock)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `containsAttribute(String name)`
  Checks if the a value is stored in the session with the specified name.
  `boolean`
  `containsAttribute(String name, Session.LockMode lockMode)`
  Checks if the a value is stored in the session with the specified name.
  `Object`
  `getAttribute(String name)`
  Returns the value previously stored in the session.
  `Object`
  `getAttribute(String name, Session.LockMode lockMode)`
  Returns the value previously stored in the session.
  `List<String>`
  `getAttributeNames()`
  Returns a list of the names of all attributes stored in the session.
  `List<String>`
  `getAttributeNames(String prefix)`
  Returns a list of the names of all attributes stored in the session whose name has the provided prefix.
  `List<String>`
  `getAttributeNames(String prefix, Session.LockMode lockMode)`
  Returns a list of the names of all attributes stored in the session whose name has the provided prefix.
  `List<String>`
  `getAttributeNames(Session.LockMode lockMode)`
  Returns a list of the names of all attributes stored in the session.
  `int`
  `getMaxInactiveInterval()`
  Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.
  `void`
  `invalidate()`
  Invalidates this session then unbinds any objects bound to it.
  `boolean`
  `isInvalidated()`
  Checks to see if the session has been invalidated.
  `void`
  `restoreDirtyObjects()`
  Re-stores dirty objects back into the session.
  `void`
  `setAttribute(String name, Object value)`
  Sets the value of an attribute.
  `void`
  `setMaxInactiveInterval(int seconds)`
  Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SessionImpl

    public SessionImpl(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpSession session, SessionLock lock)

- ## Method Details

  - ### getAttribute

    public Object getAttribute(String name)
    Description copied from interface: `Session`
    Returns the value previously stored in the session.

    By default, a `WRITE` lock is requested.

    Specified by:
      `getAttribute` in interface `Session`
    Parameters:
      `name` - The name of the attribute

  - ### getAttribute

    public Object getAttribute(String name, Session.LockMode lockMode)
    Description copied from interface: `Session`
    Returns the value previously stored in the session.

    Uses the requested `Session.LockMode` to acquire an appropriate lock.

    Specified by:
      `getAttribute` in interface `Session`
    Parameters:
      `name` - The name of the attribute

  - ### getAttributeNames

    public List<String> getAttributeNames()
    Description copied from interface: `Session`
    Returns a list of the names of all attributes stored in the session.

    The names are returned sorted alphabetically.

    By default, a `READ` lock is requested.

    Specified by:
      `getAttributeNames` in interface `Session`

  - ### getAttributeNames

    public List<String> getAttributeNames(Session.LockMode lockMode)
    Description copied from interface: `Session`
    Returns a list of the names of all attributes stored in the session.

    Uses the requested `Session.LockMode` to acquire an appropiate lock.

    Specified by:
      `getAttributeNames` in interface `Session`
    Parameters:
      `lockMode` - The requested minimum lock mode. If null, `READ` is used.
    Returns:
      Alphabetically sorted list of all attributes

  - ### setAttribute

    public void setAttribute(String name, Object value)
    Description copied from interface: `Session`
    Sets the value of an attribute. If the value is `null`, then the attribute is deleted.
    Specified by:
      `setAttribute` in interface `Session`
    Parameters:
      `name` - The name of the attribute
      `value` - The new value of the attribute; `null` deletes the attribute.

  - ### containsAttribute

    public boolean containsAttribute(String name)
    Description copied from interface: `Session`
    Checks if the a value is stored in the session with the specified name.

    By default, a `READ` lock is requested.

    Specified by:
      `containsAttribute` in interface `Session`
    Parameters:
      `name` - The name of the attribute

  - ### containsAttribute

    public boolean containsAttribute(String name, Session.LockMode lockMode)
    Description copied from interface: `Session`
    Checks if the a value is stored in the session with the specified name.

    Uses the requested `Session.LockMode` to acquire an appropriate lock.

    Specified by:
      `containsAttribute` in interface `Session`
    Parameters:
      `name` - The name of the attribute

  - ### getAttributeNames

    public List<String> getAttributeNames(String prefix)
    Description copied from interface: `Session`
    Returns a list of the names of all attributes stored in the session whose name has the provided prefix.

    By default, a `READ` lock is requested.

    Specified by:
      `getAttributeNames` in interface `Session`
    Parameters:
      `prefix` - The attribute prefix
    Returns:
      Alphabetically sorted list of attributes matching the prefix

  - ### getAttributeNames

    public List<String> getAttributeNames(String prefix, Session.LockMode lockMode)
    Description copied from interface: `Session`
    Returns a list of the names of all attributes stored in the session whose name has the provided prefix.

    Uses the requested `Session.LockMode` to acquire an appropriate lock.

    Specified by:
      `getAttributeNames` in interface `Session`
    Parameters:
      `prefix` - The attribute prefix
    Returns:
      Alphabetically sorted list of attributes matching the prefix

  - ### getMaxInactiveInterval

    public int getMaxInactiveInterval()
    Description copied from interface: `Session`
    Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. After this interval, the servlet container will invalidate the session.

    The maximum time interval can be set with the setMaxInactiveInterval method.

    A negative time indicates the session should never timeout.

    Specified by:
      `getMaxInactiveInterval` in interface `Session`

  - ### invalidate

    public void invalidate()
    Description copied from interface: `Session`
    Invalidates this session then unbinds any objects bound to it.
    Specified by:
      `invalidate` in interface `Session`

  - ### isInvalidated

    public boolean isInvalidated()
    Description copied from interface: `Session`
    Checks to see if the session has been invalidated. Note: since 5.3 this will also catch calls to `HttpSession.invalidate()`.
    Specified by:
      `isInvalidated` in interface `Session`

  - ### setMaxInactiveInterval

    public void setMaxInactiveInterval(int seconds)
    Description copied from interface: `Session`
    Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.

    A negative time indicates the session should never timeout.

    Specified by:
      `setMaxInactiveInterval` in interface `Session`

  - ### restoreDirtyObjects

    public void restoreDirtyObjects()
    Description copied from interface: `Session`
    Re-stores dirty objects back into the session. This is necessary to support clustering, because (in most application servers) session objects are only broadcast around the cluster from setAttribute(). If a mutable session object is read and changed, those changes will be limited to a single server in the cluster, which can cause confusing application failures in the event of a failover. Does nothing if there are no changes, or the session has been invalidated.
    Specified by:
      `restoreDirtyObjects` in interface `Session`
    See Also:
      - `OptimizedSessionPersistedObject`
      - `OptimizedSessionPersistedObjectAnalyzer`
      - `ImmutableSessionPersistedObject`