Class SessionCache<K,S>

java.lang.Object
ecmwf.common.technical.SessionCache<K,S>
Type Parameters:
K - the key type
S - the generic type

public class SessionCache<K,S> extends Object
The Class SessionCache.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates a new session cache.
    Instantiates a new session cache.
    SessionCache(String name, long pause)
    Instantiates a new session cache.
  • Method Summary

    Modifier and Type
    Method
    Description
    computeIfAbsent(K key, Function<K,S> defaultValue)
    This method fetches a session from the cache associated with the given key.
    boolean
    delete(K key)
    Remove all sessions registered in the cache with the specified key.
    void
    disconnect(S session)
    Disconnect called when a session is removed.
    boolean
    exists(K key)
    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
    getKey(Object... parameters)
    This utility enables the creation of a key from a list of Objects.
    getMutex(K key)
    This method retrieves a mutex for the specified key.
    Return the name of the cache.
    boolean
    isConnected(S session)
    Checks if a session is still connected.
    boolean
    put(K key, S session, long timeout)
    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(K key, S session, long timeout, long updateFrequency)
    Put the session in the cache, recorded with the given key and a timeout, used by the management thread to expire the session.
    remove(K key)
    Removes one session object recorded with the specified key or return null.
    remove(K key, S defaultValue)
    This method removes one session object associated with the given key.
    retrieve(K key)
    This method retrieves a session from the cache that is registered with the specified key.
    retrieve(K key, S defaultValue)
    This method fetches a session from the cache associated with the given key.
    void
    setDebug(boolean debug)
    Sets the debug mode.
    void
    update(S session)
    If a session is set up to receive frequent updates, this method will be invoked to ensure that the session remains active.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SessionCache

      public SessionCache()
      Instantiates a new session cache. Default constructor for session like caching (multiple connections/host).
    • SessionCache

      public SessionCache(String name)
      Instantiates a new session cache. Default constructor for session like caching (multiple connections/host).
      Parameters:
      name - the name
    • SessionCache

      public SessionCache(String name, long pause)
      Instantiates a new session cache. Constructor for single entry caching (e.g. with database objects).
      Parameters:
      name - the name
      pause - the pause
  • Method Details

    • getName

      public String getName()
      Return the name of the cache.
      Returns:
      name
    • disconnect

      public void disconnect(S session)
      Disconnect called when a session is removed.
      Parameters:
      session - the session
    • isConnected

      public boolean isConnected(S session)
      Checks if a session is still connected.
      Parameters:
      session - the session
      Returns:
      true, if is connected
    • update

      public void update(S session) throws IOException
      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

      public static String getKey(Object... parameters)
      This utility enables the creation of a key from a list of Objects. It can be utilized to construct a distinctive key while registering a session.
      Parameters:
      parameters - the parameters
      Returns:
      the key
    • remove

      public S remove(K key)
      Removes one session object recorded with the specified key or return null.
      Parameters:
      key - the key
      Returns:
      the s
    • remove

      public S remove(K key, S defaultValue)
      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 key
      defaultValue - the default value returned if the key does not exists in the cache
      Returns:
      the s
    • getMutex

      public Mutex getMutex(K key)
      This method retrieves a mutex for the specified key.
      Parameters:
      key - the key
      Returns:
      the mutex
    • retrieve

      public S retrieve(K key)
      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

      public S retrieve(K key, S defaultValue)
      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 key
      defaultValue - the default value returned if the key does not exists in the cache
      Returns:
      the s
    • computeIfAbsent

      public S computeIfAbsent(K key, Function<K,S> defaultValue)
      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 key
      defaultValue - the function to call in order to get the default value if the key does not exists in the cache
      Returns:
      the s
    • delete

      public boolean delete(K key)
      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

      public boolean exists(K key, S session, Comparator<S> comparator)
      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 key
      session - the session
      comparator - the comparator
      Returns:
      true, if successful
    • exists

      public boolean exists(K key)
      Check if the cache contains the given key.
      Parameters:
      key - the key
      Returns:
      true, if successful
    • put

      public boolean put(K key, S session, long timeout)
      Put the session in the cache, recorded with the given key and a timeout, used by the management thread to expire the session.
      Parameters:
      key - the key
      session - the session
      timeout - the timeout
      Returns:
      true, if successful
    • put

      public boolean put(K key, S session, long timeout, long updateFrequency)
      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 key
      session - the session
      timeout - the timeout
      updateFrequency - the update frequency
      Returns:
      true, if successfully added to the cache