public class SessionManager<K,V>
extends java.lang.Object
Session.Callback
interface, and if it does, its
callback function is called before removal.Modifier and Type | Class and Description |
---|---|
static interface |
SessionManager.Callback
This interface is used by the SessionManager, which maintains objects which live a distinct time.
|
Constructor and Description |
---|
SessionManager(int timeoutMilli)
Deprecated.
use the constructor with long instead!
|
SessionManager(long timeoutMilli)
This class is used to maintain sessions, that are objects which live a distinct time.
|
SessionManager(long timeoutMilli,
int maxCountOfSessions)
This class is used to maintain sessions, that are objects which live a distinct time.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears this SessionManager so that it contains no sessions.
|
boolean |
contains(java.lang.Object session)
Tests if some key maps into the specified value in this SessionManager.
|
boolean |
containsKey(java.lang.Object key)
Tests whether the specified object is a key in this SessionManager.
|
java.util.Iterator<V> |
elements()
Returns an enumeration of the values in this SessionManager.
|
java.lang.Object |
get(java.lang.Object key)
Returns the value to which the specified key is mapped in this SessionManager.
|
long |
getCreationMillis(java.lang.Object key)
Returns the creation time for the given key.
|
long |
getDeathMillis(java.lang.Object key)
Returns the death time for the given key.
|
int |
getMaxCount()
Get current max count of sessions.
|
long |
getTimeout()
Get current default timout value.
|
boolean |
isEmpty()
Tests if this SessionManager maps no keys to values.
|
java.util.Iterator<K> |
keys()
Returns an enumeration of the keys in this SessionManager.
|
static java.lang.String |
newKey()
Create a new session key.
|
java.lang.Object |
put(K key,
V value)
Maps the specified key to the specified value in this SessionManager.
|
java.lang.Object |
put(K key,
V value,
int timeoutMilli)
Deprecated.
|
java.lang.Object |
put(K key,
V value,
long timeoutMilli)
Maps the specified key to the specified value in this SessionManager, using the SessionManager's timeout.
|
java.lang.Object |
remove(java.lang.Object key)
Removes the key (and its corresponding value) from this SessionManager.
|
java.lang.Object |
removeButAsk(K key)
Removes the key (and its corresponding value) from this SessionManager.
|
void |
setMaxCount(int max)
Set a new maximum size.
|
static void |
setRandom(java.util.Random rnd)
Set a new random generator for all SessionManagers.
|
void |
setTimeout(long timeoutMilli)
Set a new default timout value.
|
int |
size()
Returns the number of keys in this SessionManager.
|
java.lang.Object |
touch(K key)
Sets the new timeout for the given key with the default timeout.
|
java.lang.Object |
touch(K key,
long timeoutMilli)
Sets the new timeout for the given key.
|
public SessionManager(long timeoutMilli, int maxCountOfSessions)
timeoutMilli
- an int specifying the timeout in msmaxCountOfSessions
- limit the count of used sessions.public SessionManager(long timeoutMilli)
timeoutMilli
- an int specifying the timeout in ms@Deprecated public SessionManager(int timeoutMilli)
timeoutMilli
- an int specifying the timeout in mspublic static void setRandom(java.util.Random rnd)
rnd
- the new random generatorpublic void clear()
public boolean contains(java.lang.Object session)
session
- a sessin to search forpublic boolean containsKey(java.lang.Object key)
key
- possible key.public java.util.Iterator<V> elements()
public java.lang.Object get(java.lang.Object key)
key
- a key in the SessionManager.public int getMaxCount()
setMaxCount(int)
public long getTimeout()
setTimeout(long)
public boolean isEmpty()
public java.util.Iterator<K> keys()
public java.lang.Object put(K key, V value)
key
- the key or null, then a new key is created.value
- the value.@Deprecated public java.lang.Object put(K key, V value, int timeoutMilli)
key
- the key or null, then a new key is created.value
- the value.timeoutMilli
- a distinct timeout value for the given keypublic java.lang.Object put(K key, V value, long timeoutMilli)
key
- the key or null, then a new key is created.value
- the value.timeoutMilli
- a distinct timeout value for the given keypublic long getCreationMillis(java.lang.Object key)
key
- the keypublic long getDeathMillis(java.lang.Object key)
key
- the keypublic java.lang.Object removeButAsk(K key)
key
- the key that needs to be removed.public java.lang.Object remove(java.lang.Object key)
key
- the key that needs to be removed.public void setMaxCount(int max)
max
- the new max count of sessionsgetMaxCount()
public void setTimeout(long timeoutMilli)
timeoutMilli
- the new default timout valuegetTimeout()
public int size()
public java.lang.Object touch(K key)
key
- the keypublic java.lang.Object touch(K key, long timeoutMilli)
key
- the keytimeoutMilli
- the new timeout to setpublic static java.lang.String newKey()