All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.netty.protocol.servlet.Session Maven / Gradle / Ivy

package com.github.netty.protocol.servlet;

import java.io.Serializable;
import java.util.Map;

/**
 * Session entity class
 *
 * @author wangzihao
 * 2018/8/18/018
 */
public class Session implements Serializable {
    private static final long serialVersionUID = 1L;

    private String id;
    private Map attributeMap;
    private long creationTime;
    private long lastAccessedTime;
    /**
     * Unit seconds
     */
    private int maxInactiveInterval;
    private int accessCount;

    public Session() {
    }

    public Session(String id, int maxInactiveInterval) {
        this.id = id;
        long currTime = System.currentTimeMillis();
        this.creationTime = currTime;
        this.lastAccessedTime = currTime;
        this.maxInactiveInterval = maxInactiveInterval;
    }

    /**
     * The validity of
     *
     * @return True is valid, false is not
     */
    public boolean isValid() {
        return System.currentTimeMillis() < (creationTime + (maxInactiveInterval * 1000));
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Map getAttributeMap() {
        return attributeMap;
    }

    public void setAttributeMap(Map attributeMap) {
        this.attributeMap = attributeMap;
    }

    public long getCreationTime() {
        return creationTime;
    }

    public void setCreationTime(long creationTime) {
        this.creationTime = creationTime;
    }

    public long getLastAccessedTime() {
        return lastAccessedTime;
    }

    public void setLastAccessedTime(long lastAccessedTime) {
        this.lastAccessedTime = lastAccessedTime;
    }

    public int getMaxInactiveInterval() {
        return maxInactiveInterval;
    }

    public void setMaxInactiveInterval(int maxInactiveInterval) {
        this.maxInactiveInterval = maxInactiveInterval;
    }

    public int getAccessCount() {
        return accessCount;
    }

    public void setAccessCount(int accessCount) {
        this.accessCount = accessCount;
    }

    @Override
    public String toString() {
        return "Session{" +
                "id='" + id + '\'' +
                ", accessCount=" + accessCount +
                '}';
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy