org.apache.turbine.services.session

## Class TurbineSessionService

- java.lang.Object
- - org.apache.turbine.services.BaseInitable
  - - org.apache.turbine.services.BaseService
    - - org.apache.turbine.services.TurbineBaseService
      - - org.apache.turbine.services.session.TurbineSessionService

- All Implemented Interfaces:
    Initable, Service, SessionService

      public class TurbineSessionService
      extends TurbineBaseService
      implements SessionService

  The SessionService allows thread-safe access to the current sessions of the current context. The session objects that are cached by this service are obtained through a listener, which must be configured via your web application's `web.xml` deployement descriptor as follows:

  > `

  >      <listener>
  >        <listener-class>
  >          org.apache.turbine.session.SessionListener
  >        </listener-class>
  >      </listener>

  > `

  Since:
    2.3
  Version:
    $Id: TurbineSessionService.java 1066925 2011-02-03 19:44:37Z ludwig $
  Author:
    Quinton McCombs, Daniel Rall
  See Also:
    `TurbineSession`, `SessionListener`

- - ### Field Summary

    - ### Fields inherited from class org.apache.turbine.services.BaseService

      `configuration, name, serviceBroker`

    - ### Fields inherited from class org.apache.turbine.services.BaseInitable

      `initableBroker, isInitialized`

    - ### Fields inherited from interface org.apache.turbine.services.session.SessionService

      `SERVICE_NAME`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TurbineSessionService()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addSession(HttpSession session)` Adds a session to the current list.
    `Collection<HttpSession>` | `getActiveSessions()` Gets a list of the active sessions.
    `Collection<User>` | `getActiveUsers()` Gets a collection of all user objects representing the users currently logged in.
    `HttpSession` | `getSession(String sessionId)` Gets the HttpSession by the session identifier
    `Collection<HttpSession>` | `getSessionsForUser(User user)` Get a collection of all session on which the given user is logged in.
    `User` | `getUserFromSession(HttpSession session)` Gets the User object of the the specified HttpSession.
    `void` | `init()` Initializes the service
    `boolean` | `isUserLoggedIn(User user)` Determines if a given user is currently logged in.
    `void` | `removeSession(HttpSession session)` Removes a session from the current list.
    `void` | `shutdown()` Returns to uninitialized state.

    - ### Methods inherited from class org.apache.turbine.services.TurbineBaseService

      `init, init`

    - ### Methods inherited from class org.apache.turbine.services.BaseService

      `getConfiguration, getName, getProperties, getServiceBroker, setName, setServiceBroker`

    - ### Methods inherited from class org.apache.turbine.services.BaseInitable

      `getInit, getInitableBroker, setInit, setInitableBroker`

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

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

    - ### Methods inherited from interface org.apache.turbine.services.Service

      `getConfiguration, getName, getProperties, setName, setServiceBroker`

    - ### Methods inherited from interface org.apache.turbine.services.Initable

      `getInit, init, setInitableBroker`

- - ### Constructor Detail

    - #### TurbineSessionService

          public TurbineSessionService()

  - ### Method Detail

    - #### getActiveSessions

          public Collection<HttpSession> getActiveSessions()

      Gets a list of the active sessions.
      Specified by:
        `getActiveSessions` in interface `SessionService`
      Returns:
        A copy of the list of `HttpSession` objects.

    - #### addSession

          public void addSession(HttpSession session)

      Adds a session to the current list. This method should only be called by the listener.
      Specified by:
        `addSession` in interface `SessionService`
      Parameters:
        `session` - Session to add

    - #### removeSession

          public void removeSession(HttpSession session)

      Removes a session from the current list. This method should only be called by the listener.
      Specified by:
        `removeSession` in interface `SessionService`
      Parameters:
        `session` - Session to remove

    - #### isUserLoggedIn

          public boolean isUserLoggedIn(User user)

      Determines if a given user is currently logged in. The actual implementation of the User object must implement the equals() method. By default, Torque based objects (liek TurbineUser) have an implementation of equals() that will compare the result of getPrimaryKey().
      Specified by:
        `isUserLoggedIn` in interface `SessionService`
      Parameters:
        `user` - User to check for
      Returns:
        true if the user is logged in on one of the active sessions.

    - #### getActiveUsers

          public Collection<User> getActiveUsers()

      Gets a collection of all user objects representing the users currently logged in. This will exclude any instances of anonymous user that Turbine will use before the user actually logs on.
      Specified by:
        `getActiveUsers` in interface `SessionService`
      Returns:
        A set of `User` objects.

    - #### getUserFromSession

          public User getUserFromSession(HttpSession session)

      Gets the User object of the the specified HttpSession.
      Specified by:
        `getUserFromSession` in interface `SessionService`
      Parameters:
        `session` - The session from which to extract a user.
      Returns:
        The Turbine User object.

    - #### getSession

          public HttpSession getSession(String sessionId)

      Gets the HttpSession by the session identifier
      Specified by:
        `getSession` in interface `SessionService`
      Parameters:
        `sessionId` - The unique session identifier.
      Returns:
        The session keyed by the specified identifier.

    - #### getSessionsForUser

          public Collection<HttpSession> getSessionsForUser(User user)

      Get a collection of all session on which the given user is logged in.
      Specified by:
        `getSessionsForUser` in interface `SessionService`
      Parameters:
        `user` - the user
      Returns:
        Collection of HtttSession objects

    - #### init

          public void init()

      Initializes the service
      Specified by:
        `init` in interface `Initable`
      Overrides:
        `init` in class `TurbineBaseService`

    - #### shutdown

          public void shutdown()

      Returns to uninitialized state.
      Specified by:
        `shutdown` in interface `Initable`
      Overrides:
        `shutdown` in class `TurbineBaseService`

Copyright © 2000-2015 The Apache Software Foundation. All Rights Reserved.