Class SCCache

java.lang.Object
org.serviceconnector.cache.SCCache

public class SCCache extends Object
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.
  • Constructor Details

    • SCCache

      public SCCache()
      Instantiates a new SC cache.
  • Method Details

    • load

      public void load(SCCacheConfiguration cacheConfiguration)
      Loads the SCCache. Initializes the cache modules and removes old cache files.
      Parameters:
      cacheConfiguration - the cache configuration
    • tryGetMessageFromCacheOrLoad

      public SCMPMessage tryGetMessageFromCacheOrLoad(SCMPMessage reqMessage) throws SCMPCommandException
      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

      public void cacheMessage(SCMPMessage reqMessage, SCMPMessage resMessage)
      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 message
      resMessage - the response message
    • cacheManagedData

      public void cacheManagedData(SCMPMessage resMessage) throws SCMPValidatorException, ParseException
      Cache managed data. Called for caching managed data. Never used in a polling procedure of a client.
      Parameters:
      resMessage - the res message
      Throws:
      ParseException
      SCMPValidatorException
    • removeDataEntriesByMetaEntry

      public void removeDataEntriesByMetaEntry(SCCacheMetaEntry metaEntry, String removeReason)
      Removes the data entries by meta entry.
      Parameters:
      metaEntry - the meta entry
      removeReason - the remove reason
    • removeManagedDataForGuardian

      public void removeManagedDataForGuardian(String cacheGuardian)
      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

      public SCCacheConfiguration getCacheConfiguration()
      Gets the cache configuration.
      Returns:
      the cache configuration
    • getLoadingSessionIds

      public HashMap<String,String> getLoadingSessionIds()
      Gets the loading session ids.
      Returns:
      the loading session ids
    • clearLoading

      public void clearLoading(String sessionId)
      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

      public void dump(XMLDumpWriter writer) throws Exception
      Dump the cache into the xml writer.
      Parameters:
      writer - the writer
      Throws:
      Exception - the exception