public class KeyValueSessionStore<TKey extends java.lang.Comparable<TKey>,TValue> extends java.lang.Object implements ISessionStore<TKey>, IKeyValueStore<TKey,TValue>
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_EXPIRATION_MILLIS
The default expiration time for session objects is 30 minutes.
|
static int |
DEFAULT_POLLING_MILLIS
The default polling interval to determine expired objects is 1 minute.
|
Constructor and Description |
---|
KeyValueSessionStore(int expirationMillis,
int pollingIntervalMillis)
Overloaded constructor, initializes session with a session expiration time and polling interval in milliseconds.
|
KeyValueSessionStore(int expirationMillis,
int pollingIntervalMillis,
java.lang.Class<?> genericTypeParameterKey,
java.lang.Class<?> genericTypeParameterValue)
Overloaded constructor, initializes session with a session expiration time and polling interval in milliseconds.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(TKey key,
TValue value)
Adds an item to the collection Returns true if successful.
|
void |
clear()
Clears the collection.
|
boolean |
containsKey(TKey key)
Returns true if the given key is contained in the collection.
|
boolean |
expire(TKey key)
Expires the time of a session item, i.e.
|
TValue |
get(TKey key)
Returns the value associated with a key.
|
int |
getExpirationMillis()
Gets the duration of a session in milliseconds.
|
java.lang.Class<?> |
getGenericTypeParameterKey()
Returns the TKey generic type parameter's class.
|
java.lang.Class<?> |
getGenericTypeParameterValue()
Returns the TValue generic type parameter's class.
|
java.lang.Iterable<TKey> |
getKeys()
Returns all keys.
|
int |
getPollingIntervalMillis()
Gets the polling interval in milliseconds.
|
java.lang.Iterable<TValue> |
getValues()
Returns all values.
|
java.util.Iterator<KeyValuePair<TKey,TValue>> |
iterator() |
void |
lock()
Locks the object
|
boolean |
refresh(TKey key)
Renews the session expiration time for an item.
|
boolean |
remove(TKey key)
Removes an item from the collection.
|
boolean |
replace(TKey key,
TValue newValue)
Replaces a key's value with the given new value.
|
int |
size()
Returns the collection size, volatile value.
|
void |
unlock()
Unlocks the object.
|
public static final int DEFAULT_EXPIRATION_MILLIS
public static final int DEFAULT_POLLING_MILLIS
public KeyValueSessionStore(int expirationMillis, int pollingIntervalMillis)
java.lang.IllegalArgumentException
- When the values provided are out of range.SuperTypeTokenException
- When called without using anonymous class semantics.public KeyValueSessionStore(int expirationMillis, int pollingIntervalMillis, java.lang.Class<?> genericTypeParameterKey, java.lang.Class<?> genericTypeParameterValue)
java.lang.IllegalArgumentException
- When the values provided are out of range.java.lang.NullPointerException
- When a generic type parameter class is null.public boolean add(TKey key, TValue value)
add
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
key
- The key to add.value
- The value to add.java.lang.NullPointerException
- Key is nullpublic void clear()
clear
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
public boolean containsKey(TKey key)
containsKey
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
key
- The key to find.java.lang.NullPointerException
- Key is nullpublic boolean expire(TKey key)
expire
in interface ISessionStore<TKey extends java.lang.Comparable<TKey>>
java.lang.NullPointerException
- Key is nullpublic TValue get(TKey key)
get
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
java.lang.NullPointerException
- Key is nullKeyNotFoundException
- When the key is not foundpublic java.lang.Iterable<TKey> getKeys()
getKeys
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
public java.lang.Iterable<TValue> getValues()
getValues
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
public int getExpirationMillis()
getExpirationMillis
in interface ISessionStore<TKey extends java.lang.Comparable<TKey>>
public int getPollingIntervalMillis()
getPollingIntervalMillis
in interface ISessionStore<TKey extends java.lang.Comparable<TKey>>
public java.lang.Class<?> getGenericTypeParameterKey()
getGenericTypeParameterKey
in interface ReifiedMap<TKey extends java.lang.Comparable<TKey>,TValue>
public java.lang.Class<?> getGenericTypeParameterValue()
getGenericTypeParameterValue
in interface ReifiedMap<TKey extends java.lang.Comparable<TKey>,TValue>
public boolean refresh(TKey key)
refresh
in interface ISessionStore<TKey extends java.lang.Comparable<TKey>>
java.lang.NullPointerException
- Key is nullpublic boolean remove(TKey key)
remove
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
key
- The key to find.java.lang.NullPointerException
- Key is null.public boolean replace(TKey key, TValue newValue)
replace
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
key
- The key to find.java.lang.NullPointerException
- Key is nullpublic int size()
size
in interface IKeyValueStore<TKey extends java.lang.Comparable<TKey>,TValue>
size
in interface ReifiedMap<TKey extends java.lang.Comparable<TKey>,TValue>
public void unlock()
public java.util.Iterator<KeyValuePair<TKey,TValue>> iterator()
iterator
in interface java.lang.Iterable<KeyValuePair<TKey extends java.lang.Comparable<TKey>,TValue>>