Class BasicSession

  • All Implemented Interfaces:
    Session

    public class BasicSession
    extends java.lang.Object
    implements Session
    A basic Session implementation.

    Created: 2017. 6. 13.

    • Constructor Detail

    • Method Detail

      • getId

        public java.lang.String getId()
        Specified by:
        getId in interface Session
      • getAttribute

        public <T> T getAttribute​(java.lang.String name)
        Specified by:
        getAttribute in interface Session
      • setAttribute

        public java.lang.Object setAttribute​(java.lang.String name,
                                             java.lang.Object value)
        Specified by:
        setAttribute in interface Session
      • getAttributeNames

        public java.util.Set<java.lang.String> getAttributeNames()
        Specified by:
        getAttributeNames in interface Session
      • removeAttribute

        public java.lang.Object removeAttribute​(java.lang.String name)
        Specified by:
        removeAttribute in interface Session
      • access

        public boolean access()
        Description copied from interface: Session
        Called when a session is first accessed by a request.
        Specified by:
        access in interface Session
      • complete

        public void complete()
        Description copied from interface: Session
        Called when a session is last accessed by a request.
        Specified by:
        complete in interface Session
      • getRequests

        protected long getRequests()
        Returns the current number of requests that are active in the Session.
        Returns:
        the number of active requests for this session
      • invalidate

        public void invalidate()
        Called by users to invalidate a session, or called by the access method as a request enters the session if the session has expired, or called by manager as a result of scavenger expiring session.
        Specified by:
        invalidate in interface Session
      • beginInvalidate

        protected boolean beginInvalidate()
      • finishInvalidate

        protected void finishInvalidate()
      • isNew

        public boolean isNew()
        Specified by:
        isNew in interface Session
      • isValid

        public boolean isValid()
        Specified by:
        isValid in interface Session
      • isResident

        protected boolean isResident()
      • setResident

        protected void setResident​(boolean resident)
      • isExpiredAt

        protected boolean isExpiredAt​(long time)
        Check to see if session has expired as at the time given.
        Parameters:
        time - the time since the epoch in ms
        Returns:
        true if expired
      • isIdleLongerThan

        protected boolean isIdleLongerThan​(int sec)
        Check if the Session has been idle longer than a number of seconds.
        Parameters:
        sec - the number of seconds
        Returns:
        true if the session has been idle longer than the interval
      • fireSessionAttributeListeners

        protected void fireSessionAttributeListeners​(java.lang.String name,
                                                     java.lang.Object oldValue,
                                                     java.lang.Object newValue)
        Call binding and attribute listeners based on the new and old values of the attribute.
        Parameters:
        name - name of the attribute
        newValue - new value of the attribute
        oldValue - previous value of the attribute
        Throws:
        java.lang.IllegalStateException - if no session manager can be find
      • checkValidForWrite

        protected void checkValidForWrite()
        Check that the session can be modified.
        Throws:
        java.lang.IllegalStateException - if the session is invalid
      • checkValidForRead

        protected void checkValidForRead()
        Check that the session data can be read.
        Throws:
        java.lang.IllegalStateException - if the session is invalid
      • checkLocked

        protected void checkLocked()
      • lock

        protected Locker.Lock lock()
        Grab the lock on the session.
        Returns:
        the lock
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object