Class ContextCache
java.lang.Object
org.gcube.informationsystem.resourceregistry.api.contexts.ContextCache
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 Summary
FieldsModifier and TypeFieldDescriptionprotected ContextCacheRenewalThe context cache renewal.The context path to UUID.protected List<org.gcube.informationsystem.contexts.reference.entities.Context>The contexts.protected org.gcube.informationsystem.dag.Dag<org.gcube.informationsystem.contexts.reference.entities.Context>The contexts tree.protected CalendarThe creation time.static final longDefault cache validity period, in milliseconds: 6 hours.protected CalendarThe expiring time.static intThe currently configured cache validity period, in milliseconds; overridable viasetExpiringTimeout(int).protected booleanThe initialized.protected static ContextCacheThe singleton.The uuid to context.The uuid to context path. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClean cache.protected voidcleanCache(Calendar calendar) Clean cache.org.gcube.informationsystem.contexts.reference.entities.ContextgetContextByPath(String contextPath) Gets the context by path.org.gcube.informationsystem.contexts.reference.entities.ContextgetContextByUUID(String uuid) Gets the context by UUID.org.gcube.informationsystem.contexts.reference.entities.ContextgetContextByUUID(UUID uuid) Gets the context by UUID.Gets the context cache renewal.protected StringgetContextPath(org.gcube.informationsystem.contexts.reference.entities.Context context) Gets the context path.getContextPathByUUID(String uuid) Gets the context path by UUID.getContextPathByUUID(UUID uuid) Gets the context path by UUID.Gets the context path to UUID association.List<org.gcube.informationsystem.contexts.reference.entities.Context>Gets the contexts.org.gcube.informationsystem.dag.Dag<org.gcube.informationsystem.contexts.reference.entities.Context>Gets the contexts tree.static ContextCacheGets the single instance of ContextCache.getUUIDByPath(String contextPath) Gets the uuid by path.Gets the UUID to context path association.voidRefresh contexts if needed.voidrenew()Renew.voidsetContextCacheRenewal(ContextCacheRenewal contextCacheRenewal) Sets the context cache renewal.protected voidsetContexts(Calendar calendar, List<org.gcube.informationsystem.contexts.reference.entities.Context> contexts) Sets the contexts.voidsetContexts(List<org.gcube.informationsystem.contexts.reference.entities.Context> contexts) Sets the contexts.static voidsetExpiringTimeout(int expiringTimeout) Sets the expiring timeout.
-
Field Details
-
DEFAULT_EXPIRING_TIMEOUT
public static final long DEFAULT_EXPIRING_TIMEOUTDefault cache validity period, in milliseconds: 6 hours. -
expiringTimeout
public static int expiringTimeoutThe currently configured cache validity period, in milliseconds; overridable viasetExpiringTimeout(int). -
singleton
The singleton. -
contextCacheRenewal
The context cache renewal. -
creationTime
The creation time. -
expiringTime
The expiring time. -
contexts
The contexts. -
uuidToContext
The uuid to context. -
uuidToContextPath
The uuid to context path. -
contextPathToUUID
The context path to UUID. -
contextsTree
protected org.gcube.informationsystem.dag.Dag<org.gcube.informationsystem.contexts.reference.entities.Context> contextsTreeThe contexts tree. -
initialized
protected boolean initializedThe initialized.
-
-
Constructor Details
-
ContextCache
public ContextCache()Instantiates a new context cache.
-
-
Method Details
-
setExpiringTimeout
public static void setExpiringTimeout(int expiringTimeout) Sets the expiring timeout.- Parameters:
expiringTimeout- the new expiring timeout
-
getInstance
Gets the single instance of ContextCache.- Returns:
- single instance of ContextCache
-
cleanCache
public void cleanCache()Clean cache. -
cleanCache
Clean cache.- Parameters:
calendar- the calendar
-
renew
Renew.- Throws:
ResourceRegistryException- the resource registry exception
-
getContextCacheRenewal
Gets the context cache renewal.- Returns:
- the context cache renewal
-
setContextCacheRenewal
Sets the context cache renewal.- Parameters:
contextCacheRenewal- the new context cache renewal
-
refreshContextsIfNeeded
Refresh contexts if needed.- Throws:
ResourceRegistryException- the resource registry exception
-
getContexts
public List<org.gcube.informationsystem.contexts.reference.entities.Context> getContexts() throws ResourceRegistryExceptionGets the contexts.- Returns:
- the contexts
- Throws:
ResourceRegistryException- the resource registry exception
-
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 calendarcontexts- 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
-
getContextPathByUUID
Gets the context path by UUID.- Parameters:
uuid- the uuid- Returns:
- the context path by UUID
- Throws:
ResourceRegistryException- the resource registry exception
-
getContextPathByUUID
Gets the context path by UUID.- Parameters:
uuid- the uuid- Returns:
- the context path by UUID
- Throws:
ResourceRegistryException- the resource registry exception
-
getUUIDByPath
Gets the uuid by path.- Parameters:
contextPath- the context path- Returns:
- the uuid by path
- Throws:
ResourceRegistryException- the resource registry exception
-
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
-
getUUIDToContextPathAssociation
Gets the UUID to context path association.- Returns:
- an Map containing UUID to Context path association
- Throws:
ResourceRegistryException- the resource registry exception
-
getContextPathToUUIDAssociation
Gets the context path to UUID association.- Returns:
- an Map containing Context path to UUID association
- Throws:
ResourceRegistryException- the resource registry exception
-
getContextsTree
public org.gcube.informationsystem.dag.Dag<org.gcube.informationsystem.contexts.reference.entities.Context> getContextsTree() throws ResourceRegistryExceptionGets the contexts tree.- Returns:
- the contexts tree
- Throws:
ResourceRegistryException- the resource registry exception
-