Package ninja.session

Interface Session

  • All Known Implementing Classes:
    SessionImpl

    public interface Session
    • Method Detail

      • init

        void init​(Context context)
        Has to be called initially. => maybe in the future as assisted inject.
        Parameters:
        context - The context of this session.
      • getId

        String getId()
        Returns:
        id of a session.
      • getData

        Map<String,​String> getData()
        Returns:
        complete content of session as immutable copy.
      • getAuthenticityToken

        String getAuthenticityToken()
        Returns:
        a authenticity token (may generate a new one if the session currently does not contain the token).
      • save

        void save​(Context context)
        To finally send this session to the user this method has to be called. It basically serializes the session into the header of the response.
        Parameters:
        context - The context from where to deduct a potentially existing session.
      • put

        void put​(String key,
                 String value)
        Puts key / value into the session. PLEASE NOTICE: If value == null the key will be removed!
        Parameters:
        key - Name of the key to store in the session.
        value - The value to store in the session
      • get

        String get​(String key)
        Returns the value of the key or null.
        Parameters:
        key - Name of the key to retrieve.
        Returns:
        The value of the key or null.
      • remove

        String remove​(String key)
        Removes the value of the key and returns the value or null.
        Parameters:
        key - name of the key to remove
        Returns:
        original value of the key we just removed
      • clear

        void clear()
        Removes all values from the session.
      • isEmpty

        boolean isEmpty()
        Returns true if the session is empty, e.g. does not contain anything else than the timestamp key.
        Returns:
        true if session does not contain any values / false if it contains values.
      • setExpiryTime

        void setExpiryTime​(Long expiryTimeMs)
        Use an alternative expiry time, this can be used to implement a longer expiry time for 'remember me' style functionality. The expiry time is persisted in the session.
        Parameters:
        expiryTimeMs - the expiry time in milliseconds, set to null to remove the expiry time from the session and use the application default.