Package io.vertx.ext.web.sstore

## Class AbstractSession

- java.lang.Object
- - io.vertx.ext.web.sstore.AbstractSession

- All Implemented Interfaces:
    `Session`, `io.vertx.ext.web.sstore.impl.SessionInternal`

      public abstract class AbstractSession
      extends Object
      implements Session, io.vertx.ext.web.sstore.impl.SessionInternal

  The abstract session class provides a barebones implementation for session storage implementors. This class will contain all the related data required for a session plus a couple of helper methods to verify the integrity and versioning of the data. This checksum is important to reduce the amount of times data is pushed to be stored on a backend. As a Vert.x Web user, you should not have to deal with this class directly but with the public interface that it implements.
  Author:
    Paulo Lopes

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `AbstractSession()` | This constructor is mandatory (even though not referenced anywhere) is required for serialization purposes.
    `AbstractSession​(VertxContextPRNG random)` |
    `AbstractSession​(VertxContextPRNG random, long timeout, int length)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected int` | `checksum()` |
    `Session` | `computeIfAbsent​(String key, java.util.function.Function<String,​Object> mappingFunction)` | Put some data in a session if absent.
    `protected int` | `crc()` |
    `Map<String,​Object>` | `data()` |
    `void` | `destroy()` | Destroy the session
    `void` | `flushed​(boolean skipCrc)` | Mark this session as flushed, this gives the object a change to clear any state management flags.
    `<T> T` | `get​(String key)` | Get some data from the session
    `String` | `id()` |
    `void` | `incrementVersion()` |
    `boolean` | `isDestroyed()` |
    `boolean` | `isEmpty()` |
    `boolean` | `isRegenerated()` |
    `long` | `lastAccessed()` |
    `String` | `oldId()` |
    `Session` | `put​(String key, Object obj)` | Put some data in a session
    `Session` | `putIfAbsent​(String key, Object obj)` | Put some data in a session if absent
    `protected int` | `readDataFromBuffer​(int pos, Buffer buffer)` |
    `protected void` | `readDataFromBuffer​(Buffer buffer)` |
    `Session` | `regenerateId()` |
    `<T> T` | `remove​(String key)` | Remove some data from the session
    `void` | `setAccessed()` | Mark the session as being accessed.
    `protected void` | `setData​(JsonObject data)` |
    `protected void` | `setData​(Map<String,​Object> data)` |
    `protected void` | `setId​(String id)` |
    `protected void` | `setLastAccessed​(long lastAccessed)` |
    `void` | `setPRNG​(VertxContextPRNG prng)` |
    `protected void` | `setTimeout​(long timeout)` |
    `protected void` | `setVersion​(int version)` |
    `long` | `timeout()` |
    `int` | `version()` |
    `protected void` | `writeDataToBuffer​(Buffer buffer)` |

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

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

    - ### Methods inherited from interface io.vertx.ext.web.Session

      `value`

- - ### Constructor Detail

    - #### AbstractSession

          public AbstractSession()

      This constructor is mandatory (even though not referenced anywhere) is required for serialization purposes. Do not remove. It is required as part of the contract of the ClusterSerializable interface which some implementations might require.

    - #### AbstractSession

          public AbstractSession​(VertxContextPRNG random)

    - #### AbstractSession

          public AbstractSession​(VertxContextPRNG random,
                                 long timeout,
                                 int length)

  - ### Method Detail

    - #### setId

          protected void setId​(String id)

    - #### setTimeout

          protected void setTimeout​(long timeout)

    - #### setData

          protected void setData​(Map<String,​Object> data)

    - #### setData

          protected void setData​(JsonObject data)

    - #### setLastAccessed

          protected void setLastAccessed​(long lastAccessed)

    - #### setVersion

          protected void setVersion​(int version)

    - #### setPRNG

          public void setPRNG​(VertxContextPRNG prng)

    - #### flushed

          public void flushed​(boolean skipCrc)

      Description copied from interface: `io.vertx.ext.web.sstore.impl.SessionInternal`
      Mark this session as flushed, this gives the object a change to clear any state management flags.
      Specified by:
        `flushed` in interface `io.vertx.ext.web.sstore.impl.SessionInternal`
      Parameters:
        `skipCrc` - if the intention is NOT to keep using the session after this call, a small optimization can be performed (skip updating the internal CRC) which is unnecessary.

    - #### id

          public String id()

      Specified by:
        `id` in interface `Session`
      Returns:
        The unique ID of the session. This is generated using a random secure UUID.

    - #### regenerateId

          public Session regenerateId()

      Specified by:
        `regenerateId` in interface `Session`
      Returns:
        The new unique ID of the session.

    - #### timeout

          public long timeout()

      Specified by:
        `timeout` in interface `Session`
      Returns:
        the amount of time in ms, after which the session will expire, if not accessed.

    - #### get

          public <T> T get​(String key)

      Description copied from interface: `Session`
      Get some data from the session
      Specified by:
        `get` in interface `Session`
      Parameters:
        `key` - the key of the data
      Returns:
        the data

    - #### put

          public Session put​(String key,
                             Object obj)

      Description copied from interface: `Session`
      Put some data in a session
      Specified by:
        `put` in interface `Session`
      Parameters:
        `key` - the key for the data
        `obj` - the data
      Returns:
        a reference to this, so the API can be used fluently

    - #### putIfAbsent

          public Session putIfAbsent​(String key,
                                     Object obj)

      Description copied from interface: `Session`
      Put some data in a session if absent
      Specified by:
        `putIfAbsent` in interface `Session`
      Parameters:
        `key` - the key for the data
        `obj` - the data
      Returns:
        a reference to this, so the API can be used fluently

    - #### computeIfAbsent

          public Session computeIfAbsent​(String key,
                                         java.util.function.Function<String,​Object> mappingFunction)

      Description copied from interface: `Session`
      Put some data in a session if absent. If the specified key is not already associated with a value (or is mapped to `null`), attempts to compute its value using the given mapping function and enters it into this map unless `null`.
      Specified by:
        `computeIfAbsent` in interface `Session`
      Parameters:
        `key` - the key for the data
        `mappingFunction` - a mapping function
      Returns:
        a reference to this, so the API can be used fluently

    - #### remove

          public <T> T remove​(String key)

      Description copied from interface: `Session`
      Remove some data from the session
      Specified by:
        `remove` in interface `Session`
      Parameters:
        `key` - the key of the data
      Returns:
        the data that was there or null if none there

    - #### data

          public Map<String,​Object> data()

      Specified by:
        `data` in interface `Session`
      Returns:
        the session data as a map

    - #### isEmpty

          public boolean isEmpty()

      Specified by:
        `isEmpty` in interface `Session`
      Returns:
        true if the session has data

    - #### lastAccessed

          public long lastAccessed()

      Specified by:
        `lastAccessed` in interface `Session`
      Returns:
        the time the session was last accessed

    - #### setAccessed

          public void setAccessed()

      Description copied from interface: `Session`
      Mark the session as being accessed.
      Specified by:
        `setAccessed` in interface `Session`

    - #### destroy

          public void destroy()

      Description copied from interface: `Session`
      Destroy the session
      Specified by:
        `destroy` in interface `Session`

    - #### isDestroyed

          public boolean isDestroyed()

      Specified by:
        `isDestroyed` in interface `Session`
      Returns:
        has the session been destroyed?

    - #### isRegenerated

          public boolean isRegenerated()

      Specified by:
        `isRegenerated` in interface `Session`
      Returns:
        has the session been renewed?

    - #### oldId

          public String oldId()

      Specified by:
        `oldId` in interface `Session`
      Returns:
        old ID if renewed

    - #### version

          public int version()

    - #### incrementVersion

          public void incrementVersion()

    - #### crc

          protected int crc()

    - #### checksum

          protected int checksum()

    - #### writeDataToBuffer

          protected void writeDataToBuffer​(Buffer buffer)

    - #### readDataFromBuffer

          protected int readDataFromBuffer​(int pos,
                                           Buffer buffer)

    - #### readDataFromBuffer

          protected void readDataFromBuffer​(Buffer buffer)