org.apache.ignite.cache.websession

## Class WebSessionFilter

- java.lang.Object
- - org.apache.ignite.cache.websession.WebSessionFilter

- All Implemented Interfaces:
    javax.servlet.Filter

      public class WebSessionFilter
      extends Object
      implements javax.servlet.Filter

  Filter for web sessions caching.

  This is a request filter, that you need to specify in your `web.xml` along with `ServletContextListenerStartup` to enable web sessions caching:

       <listener>
           <listener-class>org.apache.ignite.startup.servlet.ServletContextListenerStartup</listener-class>
       </listener>

       <filter>
           <filter-name>WebSessionFilter</filter-name>
           <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class>
       </filter>

       <!-- You can also specify a custom URL pattern. -->
       <filter-mapping>
           <filter-name>IgniteWebSessionsFilter</filter-name>
           <url-pattern>/*</url-pattern>
       </filter-mapping>

  It is also possible to specify a servlet name in a filter mapping, and a servlet URL pattern will be used in this case:

       <filter>
           <filter-name>WebSessionFilter</filter-name>
           <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class>
       </filter>

       <filter-mapping>
           <filter-name>WebSessionFilter</filter-name>
           <servlet-name>YourServletName</servlet-name>
       </filter-mapping>

  The filter has the following optional configuration parameters:

  Name | Description | Default
  --- | --- | ---
  IgniteWebSessionsGridName | Name of the grid that contains cache for web session storage. | `null` (default grid)
  IgniteWebSessionsCacheName | Name of the cache for web session storage. | `null` (default cache)
  IgniteWebSessionsMaximumRetriesOnFail | Valid for `ATOMIC` caches only. Maximum number of retries for session updates in case node leaves topology and update fails. If retry is enabled, some updates can be applied more than once, otherwise some updates can be lost. To disable retries, set this parameter to `0`. | `3`
  IgniteWebSessionsRetriesTimeout | Retry timeout. Related to IgniteWebSessionsMaximumRetriesOnFail param. Further attempts will be cancelled in case timeout was exceeded. | `10000` (10 seconds)

  These parameters are taken from either filter init parameter list or servlet context parameters. You can specify filter init parameters as follows:

       <filter>
           <filter-name>WebSessionFilter</filter-name>
           <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class>
           <init-param>
               <param-name>IgniteWebSessionsGridName</param-name>
               <param-value>WebGrid</param-value>
           </init-param>
           <init-param>
               <param-name>IgniteWebSessionsCacheName</param-name>
               <param-value>WebCache</param-value>
           </init-param>

           <!-- Valid for ATOMIC caches only. -->
           <init-param>
               <param-name>IgniteWebSessionsMaximumRetriesOnFail</param-name>
               <param-value>10</param-value>
           </init-param>
       </filter>

  Note: filter init parameter has a priority over servlet context parameter; if you specify both, the servlet context parameter will be ignored.

  # Web sessions caching and concurrent requests

  If your web application can accept concurrent request for one session, consider using `CacheAtomicityMode.TRANSACTIONAL` cache instead of `CacheAtomicityMode.ATOMIC`. In this case each request be processed inside pessimistic transaction which will guarantee that all updates will be applied in correct order. This is important, for example, if you get some attribute from the session, update its value and set new value back to the session. In case of `CacheAtomicityMode.ATOMIC` cache concurrent requests can get equal value, but `CacheAtomicityMode.TRANSACTIONAL` cache will always process such updates one after another.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `DFLT_KEEP_BINARY_FLAG` Default keep binary flag.
    `static int` | `DFLT_MAX_RETRIES_ON_FAIL` Default retry on fail flag value.
    `static int` | `DFLT_RETRIES_ON_FAIL_TIMEOUT` Default retry on fail timeout flag value.
    `static String` | `WEB_SES_CACHE_NAME_PARAM` Web sessions caching cache name parameter name.
    `static String` | `WEB_SES_KEEP_BINARY_PARAM`
    `static String` | `WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM` Web sessions caching retry on fail parameter name (valid for ATOMIC cache only).
    `static String` | `WEB_SES_NAME_PARAM` Web sessions caching grid name parameter name.
    `static String` | `WEB_SES_RETRIES_TIMEOUT_NAME_PARAM` Web sessions caching retry on fail timeout parameter name.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WebSessionFilter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `destroy()`
    `void` | `destroySession(String sesId)`
    `void` | `doFilter(javax.servlet.ServletRequest req, javax.servlet.ServletResponse res, javax.servlet.FilterChain chain)`
    `void` | `init(javax.servlet.FilterConfig cfg)`
    `String` | `toString()`
    `void` | `updateAttributes(String sesId, Collection<org.apache.ignite.internal.util.typedef.T2<String,Object>> updates, int maxInactiveInterval)`
    `void` | `updateAttributesV2(String sesId, org.apache.ignite.cache.websession.WebSessionV2 ses)`

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

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

- - ### Field Detail

    - #### WEB_SES_NAME_PARAM

          public static final String WEB_SES_NAME_PARAM

      Web sessions caching grid name parameter name.
      See Also:
        Constant Field Values

    - #### WEB_SES_CACHE_NAME_PARAM

          public static final String WEB_SES_CACHE_NAME_PARAM

      Web sessions caching cache name parameter name.
      See Also:
        Constant Field Values

    - #### WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM

          public static final String WEB_SES_MAX_RETRIES_ON_FAIL_NAME_PARAM

      Web sessions caching retry on fail parameter name (valid for ATOMIC cache only).
      See Also:
        Constant Field Values

    - #### WEB_SES_RETRIES_TIMEOUT_NAME_PARAM

          public static final String WEB_SES_RETRIES_TIMEOUT_NAME_PARAM

      Web sessions caching retry on fail timeout parameter name.
      See Also:
        Constant Field Values

    - #### WEB_SES_KEEP_BINARY_PARAM

          public static final String WEB_SES_KEEP_BINARY_PARAM

      See Also:
        Constant Field Values

    - #### DFLT_MAX_RETRIES_ON_FAIL

          public static final int DFLT_MAX_RETRIES_ON_FAIL

      Default retry on fail flag value.
      See Also:
        Constant Field Values

    - #### DFLT_RETRIES_ON_FAIL_TIMEOUT

          public static final int DFLT_RETRIES_ON_FAIL_TIMEOUT

      Default retry on fail timeout flag value.
      See Also:
        Constant Field Values

    - #### DFLT_KEEP_BINARY_FLAG

          public static final boolean DFLT_KEEP_BINARY_FLAG

      Default keep binary flag.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### WebSessionFilter

          public WebSessionFilter()

  - ### Method Detail

    - #### init

          public void init(javax.servlet.FilterConfig cfg)
                    throws javax.servlet.ServletException

      Specified by:
        `init` in interface `javax.servlet.Filter`
      Throws:
        `javax.servlet.ServletException`

    - #### destroy

          public void destroy()

      Specified by:
        `destroy` in interface `javax.servlet.Filter`

    - #### doFilter

          public void doFilter(javax.servlet.ServletRequest req,
                               javax.servlet.ServletResponse res,
                               javax.servlet.FilterChain chain)
                        throws IOException,
                               javax.servlet.ServletException

      Specified by:
        `doFilter` in interface `javax.servlet.Filter`
      Throws:
        `IOException`
        `javax.servlet.ServletException`

    - #### destroySession

          public void destroySession(String sesId)

      Parameters:
        `sesId` - Session ID.

    - #### updateAttributes

          public void updateAttributes(String sesId,
                                       Collection<org.apache.ignite.internal.util.typedef.T2<String,Object>> updates,
                                       int maxInactiveInterval)

      Parameters:
        `sesId` - Session ID.
        `updates` - Updates list.
        `maxInactiveInterval` - Max session inactive interval.

    - #### updateAttributesV2

          public void updateAttributesV2(String sesId,
                                         org.apache.ignite.cache.websession.WebSessionV2 ses)
                                  throws IOException

      Parameters:
        `sesId` - Session ID.
        `ses` - Web session.
      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

2021 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.11.0
Release Date | : September 11 2021