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

org.tinystruct.http.MemorySession Maven / Gradle / Ivy

Go to download

A simple framework for Java development. Simple is hard, Complex is easy. Better thinking, better design.

There is a newer version: 1.5.1
Show newest version
package org.tinystruct.http;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MemorySession implements Session {

    private final Map storage = new ConcurrentHashMap<>();
    private final String sessionId;
    private long expiry;

    public MemorySession(String sessionId) {
        this.sessionId = sessionId;
        this.expiry = System.currentTimeMillis() + 1800000L;
    }

    @Override
    public String getId() {
        return this.sessionId;
    }

    @Override
    public void setAttribute(String key, Object value) {
        storage.put(key, value);
    }

    @Override
    public Object getAttribute(String key) {
        this.expiry = System.currentTimeMillis() + 1800000L;
        return storage.get(key);
    }

    @Override
    public void removeAttribute(String key) {
        storage.remove(key);
    }

    @Override
    public boolean isExpired() {
        return System.currentTimeMillis() > expiry;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy