
ameba.http.session.AbstractSession Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ameba-session Show documentation
Show all versions of ameba-session Show documentation
A useful Java framework session!
package ameba.http.session;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
import java.util.UUID;
/**
* @author icode
*/
public abstract class AbstractSession {
protected long defaultTimeout;
protected boolean isNew;
protected String host;
protected String id;
protected AbstractSession(String id, String host, long defaultTimeout, boolean isNew) {
if (StringUtils.isBlank(id)) throw new SessionExcption("session id is invalid");
setId(id);
this.host = host;
this.defaultTimeout = defaultTimeout;
this.isNew = isNew;
}
protected AbstractSession(String host, long defaultTimeout, boolean isNew) {
setId(newSessionId());
this.host = host;
this.defaultTimeout = defaultTimeout;
this.isNew = isNew;
}
public static AbstractSession get(String id) {
return null;
}
public static String newSessionId() {
return Hashing.murmur3_32()
.hashString(
UUID.randomUUID().toString() + Math.random() + System.nanoTime(),
Charsets.UTF_8
)
.toString();
}
/**
* Add an attribute to this session.
*
* @param key key
* @param value value
*/
public abstract void setAttribute(Object key, Object value);
/**
* Return an attribute.
*
* @param key key
* @return an attribute
*/
public abstract V getAttribute(Object key);
/**
* Return all attributes.
*
* @return an attribute
*/
public abstract Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy