Package org.serviceconnector.cache
Class SCCache
java.lang.Object
org.serviceconnector.cache.SCCache
The Class SCCache. The cache is responsible for handling caching actions in the Service Connector. The AppContext gives access to the SC cache instance. It controls the life
cycles of caching. Loading and destroying procedure are important to be called.
The cache contains two physical cache modules (SC_CACHE_TYPE.DATA_CACHE_MODULE, SC_CACHE_TYPE.META_DATA_CACHE_MODULE). Whenever someone is interested to insert or load from cache the META_DATA_CACHE_MODULE gets accessed first. It contains a list of CacheMetaEntry instances, which holds information about the stored SCMPMessage in DATA_CACHE_MODULE. CacheMetaEntry are identified by the cacheKey cachedId, cached messages in DATA_CACHE_MODULE by the cacheKey cacheId/appendixNr/partNr. A meta cache entry gets created and cached when client request contains a cacheId. Other clients requesting the same cacheId later, return with "cache retry later" error. This error is returned as long as the first client is not finished with loading the message completely. Only the first client (session) is allowed to load the message. At the time the message is complete and all parts transfered, it is ready to be loaded from the cache. As long as the message is not completely loaded the meta entry has an expiration time of OTI given by the client. After completion it gets expiration time of the message given by the server. Control of the expiration is done by the ISCCacheModule implementation. Data entries never (0 means forever) have an expiration time. When a meta entry expires every data entry belonging to this meta entry will be deleted. Managed (loaded with cmt=initial) data with an empty expiration never expire. They stay as long as no remove is received.
Cache identifiers naming: cacheId/appendixNr/partNr |---baseDataCid---| |--------dataCid--------|
The cache identifier with appendix zero and part number zero (e.g. 700/0/0) is called initialDataCid.
There are several circumstances they can stop the loading process and clear the message: - Server returns a fault message. - Server returns no cacheId. - Server returns a different cacheId than the requested one. - Server returns no expirationDate. - Server returns expirationDate with wrong format. - Server returns expirationDate in the past. - Caching of message fails for some reason.
The cache contains two physical cache modules (SC_CACHE_TYPE.DATA_CACHE_MODULE, SC_CACHE_TYPE.META_DATA_CACHE_MODULE). Whenever someone is interested to insert or load from cache the META_DATA_CACHE_MODULE gets accessed first. It contains a list of CacheMetaEntry instances, which holds information about the stored SCMPMessage in DATA_CACHE_MODULE. CacheMetaEntry are identified by the cacheKey cachedId, cached messages in DATA_CACHE_MODULE by the cacheKey cacheId/appendixNr/partNr. A meta cache entry gets created and cached when client request contains a cacheId. Other clients requesting the same cacheId later, return with "cache retry later" error. This error is returned as long as the first client is not finished with loading the message completely. Only the first client (session) is allowed to load the message. At the time the message is complete and all parts transfered, it is ready to be loaded from the cache. As long as the message is not completely loaded the meta entry has an expiration time of OTI given by the client. After completion it gets expiration time of the message given by the server. Control of the expiration is done by the ISCCacheModule implementation. Data entries never (0 means forever) have an expiration time. When a meta entry expires every data entry belonging to this meta entry will be deleted. Managed (loaded with cmt=initial) data with an empty expiration never expire. They stay as long as no remove is received.
Cache identifiers naming: cacheId/appendixNr/partNr |---baseDataCid---| |--------dataCid--------|
The cache identifier with appendix zero and part number zero (e.g. 700/0/0) is called initialDataCid.
There are several circumstances they can stop the loading process and clear the message: - Server returns a fault message. - Server returns no cacheId. - Server returns a different cacheId than the requested one. - Server returns no expirationDate. - Server returns expirationDate with wrong format. - Server returns expirationDate in the past. - Caching of message fails for some reason.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcacheManagedData(SCMPMessage resMessage) Cache managed data.voidcacheMessage(SCMPMessage reqMessage, SCMPMessage resMessage) Cache message.voidclearAll()Clear all caches.voidclearLoading(String sessionId) Clear loading cache message for session.voiddestroy()Destroy all cache modules controlled by this cache.voiddump(XMLDumpWriter writer) Dump the cache into the xml writer.Gets the cache configuration.Gets the loading session ids.booleanChecks if is cache enabled.voidload(SCCacheConfiguration cacheConfiguration) Loads the SCCache.voidremoveDataEntriesByMetaEntry(SCCacheMetaEntry metaEntry, String removeReason) Removes the data entries by meta entry.voidremoveManagedDataForGuardian(String cacheGuardian) Removes the managed data for guardian.tryGetMessageFromCacheOrLoad(SCMPMessage reqMessage) Try get message from cache.
-
Constructor Details
-
SCCache
public SCCache()Instantiates a new SC cache.
-
-
Method Details
-
load
Loads the SCCache. Initializes the cache modules and removes old cache files.- Parameters:
cacheConfiguration- the cache configuration
-
tryGetMessageFromCacheOrLoad
Try get message from cache. Returns the requested message if already stored in cache. If requested message is in loaded state because it gets loaded by another client an SCMPCommandException is returned. Otherwise cache marks requested message to be in loaded state and returns null.- Parameters:
reqMessage- the request message- Returns:
- the SCMP message
- Throws:
SCMPCommandException- requested message in loading state, gets already loaded by another client
-
cacheMessage
Cache message. Tries to cache a message. If caching the message for some reason fails, the meta entry of specific cachId gets removed. Basically a clean up is done! Cache message is called in a polling procedure of a client. Published appendices are cached by the method "cacheManagedData".- Parameters:
reqMessage- the request messageresMessage- the response message
-
cacheManagedData
Cache managed data. Called for caching managed data. Never used in a polling procedure of a client.- Parameters:
resMessage- the res message- Throws:
ParseExceptionSCMPValidatorException
-
removeDataEntriesByMetaEntry
Removes the data entries by meta entry.- Parameters:
metaEntry- the meta entryremoveReason- the remove reason
-
removeManagedDataForGuardian
Removes the managed data for guardian. Any data assigned to the specific cache guardian will be deleted.- Parameters:
cacheGuardian- the cache guardian
-
isCacheEnabled
public boolean isCacheEnabled()Checks if is cache enabled.- Returns:
- true, if is cache enabled
-
getCacheConfiguration
Gets the cache configuration.- Returns:
- the cache configuration
-
getLoadingSessionIds
Gets the loading session ids.- Returns:
- the loading session ids
-
clearLoading
Clear loading cache message for session. Clears every cache message in loading state which is related to given sessionId. Useful when session times out and gets destroyed.- Parameters:
sessionId- the session id
-
clearAll
public void clearAll()Clear all caches. -
destroy
public void destroy()Destroy all cache modules controlled by this cache. Destroys the cache factory. -
dump
Dump the cache into the xml writer.- Parameters:
writer- the writer- Throws:
Exception- the exception
-