Class ContextCache


  • public class ContextCache
    extends Object
    Client-side, time-expiring singleton cache of the full Context tree, indexed by UUID and by path, used by client libraries to resolve Context identity without a server round-trip on every call. Populated/refreshed via a pluggable ContextCacheRenewal strategy and automatically renewed once expiringTimeout elapses.
    Author:
    Luca Frosini (ISTI - CNR)
    • Field Detail

      • DEFAULT_EXPIRING_TIMEOUT

        public static final long DEFAULT_EXPIRING_TIMEOUT
        Default cache validity period, in milliseconds: 6 hours.
      • expiringTimeout

        public static int expiringTimeout
        The currently configured cache validity period, in milliseconds; overridable via setExpiringTimeout(int).
      • singleton

        protected static ContextCache singleton
        The singleton.
      • contextCacheRenewal

        protected ContextCacheRenewal contextCacheRenewal
        The context cache renewal.
      • creationTime

        protected Calendar creationTime
        The creation time.
      • expiringTime

        protected Calendar expiringTime
        The expiring time.
      • contexts

        protected List<org.gcube.informationsystem.contexts.reference.entities.Context> contexts
        The contexts.
      • uuidToContext

        protected Map<UUID,​org.gcube.informationsystem.contexts.reference.entities.Context> uuidToContext
        The uuid to context.
      • uuidToContextPath

        protected Map<UUID,​String> uuidToContextPath
        The uuid to context path.
      • contextPathToUUID

        protected Map<String,​UUID> contextPathToUUID
        The context path to UUID.
      • contextsTree

        protected org.gcube.informationsystem.dag.Dag<org.gcube.informationsystem.contexts.reference.entities.Context> contextsTree
        The contexts tree.
      • initialized

        protected boolean initialized
        The initialized.
    • Constructor Detail

      • ContextCache

        public ContextCache()
        Instantiates a new context cache.
    • Method Detail

      • setExpiringTimeout

        public static void setExpiringTimeout​(int expiringTimeout)
        Sets the expiring timeout.
        Parameters:
        expiringTimeout - the new expiring timeout
      • getInstance

        public static ContextCache getInstance()
        Gets the single instance of ContextCache.
        Returns:
        single instance of ContextCache
      • cleanCache

        public void cleanCache()
        Clean cache.
      • cleanCache

        protected void cleanCache​(Calendar calendar)
        Clean cache.
        Parameters:
        calendar - the calendar
      • getContextCacheRenewal

        public ContextCacheRenewal getContextCacheRenewal()
        Gets the context cache renewal.
        Returns:
        the context cache renewal
      • setContextCacheRenewal

        public void setContextCacheRenewal​(ContextCacheRenewal contextCacheRenewal)
        Sets the context cache renewal.
        Parameters:
        contextCacheRenewal - the new context cache renewal
      • setContexts

        public void setContexts​(List<org.gcube.informationsystem.contexts.reference.entities.Context> contexts)
        Sets the contexts.
        Parameters:
        contexts - the new contexts
      • setContexts

        protected void setContexts​(Calendar calendar,
                                   List<org.gcube.informationsystem.contexts.reference.entities.Context> contexts)
        Sets the contexts.
        Parameters:
        calendar - the calendar
        contexts - the contexts
      • getContextPath

        protected String getContextPath​(org.gcube.informationsystem.contexts.reference.entities.Context context)
        Gets the context path.
        Parameters:
        context - the context
        Returns:
        the context path
      • getContextByUUID

        public org.gcube.informationsystem.contexts.reference.entities.Context getContextByUUID​(UUID uuid)
                                                                                         throws ResourceRegistryException
        Gets the context by UUID.
        Parameters:
        uuid - the uuid
        Returns:
        the context by UUID
        Throws:
        ResourceRegistryException - the resource registry exception
      • getContextByUUID

        public org.gcube.informationsystem.contexts.reference.entities.Context getContextByUUID​(String uuid)
                                                                                         throws ResourceRegistryException
        Gets the context by UUID.
        Parameters:
        uuid - the uuid
        Returns:
        the context by UUID
        Throws:
        ResourceRegistryException - the resource registry exception
      • getContextByPath

        public org.gcube.informationsystem.contexts.reference.entities.Context getContextByPath​(String contextPath)
                                                                                         throws ResourceRegistryException
        Gets the context by path.
        Parameters:
        contextPath - the context path
        Returns:
        the context by path
        Throws:
        ResourceRegistryException - the resource registry exception
      • getContextsTree

        public org.gcube.informationsystem.dag.Dag<org.gcube.informationsystem.contexts.reference.entities.Context> getContextsTree()
                                                                                                                             throws ResourceRegistryException
        Gets the contexts tree.
        Returns:
        the contexts tree
        Throws:
        ResourceRegistryException - the resource registry exception