Class SessionCache<K,S>
java.lang.Object
ecmwf.common.technical.SessionCache<K,S>
- Type Parameters:
K
- the key typeS
- the generic type
The Class SessionCache.
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a new session cache.SessionCache
(String name) Instantiates a new session cache.SessionCache
(String name, long pause) Instantiates a new session cache. -
Method Summary
Modifier and TypeMethodDescriptioncomputeIfAbsent
(K key, Function<K, S> defaultValue) This method fetches a session from the cache associated with the given key.boolean
Remove all sessions registered in the cache with the specified key.void
disconnect
(S session) Disconnect called when a session is removed.boolean
Check if the cache contains the given key.boolean
exists
(K key, S session, Comparator<S> comparator) Checks if the given session S exists for the given key K in the cache.static String
This utility enables the creation of a key from a list of Objects.This method retrieves a mutex for the specified key.getName()
Return the name of the cache.boolean
isConnected
(S session) Checks if a session is still connected.boolean
Put the session in the cache, recorded with the given key and a timeout, used by the management thread to expire the session.boolean
Put the session in the cache, recorded with the given key and a timeout, used by the management thread to expire the session.Removes one session object recorded with the specified key or return null.This method removes one session object associated with the given key.This method retrieves a session from the cache that is registered with the specified key.This method fetches a session from the cache associated with the given key.void
setDebug
(boolean debug) Sets the debug mode.void
If a session is set up to receive frequent updates, this method will be invoked to ensure that the session remains active.
-
Constructor Details
-
SessionCache
public SessionCache()Instantiates a new session cache. Default constructor for session like caching (multiple connections/host). -
SessionCache
Instantiates a new session cache. Default constructor for session like caching (multiple connections/host).- Parameters:
name
- the name
-
SessionCache
Instantiates a new session cache. Constructor for single entry caching (e.g. with database objects).- Parameters:
name
- the namepause
- the pause
-
-
Method Details
-
getName
-
disconnect
Disconnect called when a session is removed.- Parameters:
session
- the session
-
isConnected
Checks if a session is still connected.- Parameters:
session
- the session- Returns:
- true, if is connected
-
update
If a session is set up to receive frequent updates, this method will be invoked to ensure that the session remains active. For example, in an FTP session, this might involve sending a NOOP command.- Parameters:
session
- the session- Throws:
IOException
- Signals that an I/O exception has occurred.
-
setDebug
public void setDebug(boolean debug) Sets the debug mode.- Parameters:
debug
- the new debug mode
-
getKey
-
remove
-
remove
This method removes one session object associated with the given key. If the specified key does not have any value mapped to it, the method returns the default value provided.- Parameters:
key
- the keydefaultValue
- the default value returned if the key does not exists in the cache- Returns:
- the s
-
getMutex
-
retrieve
This method retrieves a session from the cache that is registered with the specified key. If there is no session registered with this key, the method returns null. It's important to note that the session is not removed from the cache.- Parameters:
key
- the key- Returns:
- the s
-
retrieve
This method fetches a session from the cache associated with the given key. If no session is found with the specified key, the default value is returned. It's important to note that the session is not deleted from the cache.- Parameters:
key
- the keydefaultValue
- the default value returned if the key does not exists in the cache- Returns:
- the s
-
computeIfAbsent
This method fetches a session from the cache associated with the given key. If no session is found with the specified key, the default value is returned. It's important to note that the session is not deleted from the cache.- Parameters:
key
- the keydefaultValue
- the function to call in order to get the default value if the key does not exists in the cache- Returns:
- the s
-
delete
Remove all sessions registered in the cache with the specified key.- Parameters:
key
- the key- Returns:
- true, if the key exists and was removed
-
exists
Checks if the given session S exists for the given key K in the cache. The comparator is used to compare the session object with the sessions stored in the cache with the given key.- Parameters:
key
- the keysession
- the sessioncomparator
- the comparator- Returns:
- true, if successful
-
exists
Check if the cache contains the given key.- Parameters:
key
- the key- Returns:
- true, if successful
-
put
-
put
Put the session in the cache, recorded with the given key and a timeout, used by the management thread to expire the session. If the update frequency is positive it is used by the management thread to regularly update the session.- Parameters:
key
- the keysession
- the sessiontimeout
- the timeoutupdateFrequency
- the update frequency- Returns:
- true, if successfully added to the cache
-