Class CachedFileMediator

java.lang.Object
com.e1c.langtool.storage.CachedFileMediator

public class CachedFileMediator extends Object
The cachable editing file mediator allows to load file if not exits in cache and save files form cache automatically in separate job.
  • Field Details

    • filesCache

      protected final com.google.common.cache.Cache<org.eclipse.core.resources.IFile,IFileEditor<?>> filesCache
    • evictedTranslationFiles

      protected final ConcurrentNavigableMap<String,IFileEditor<?>> evictedTranslationFiles
      List of evicted translation files.
  • Constructor Details

  • Method Details

    • getSharedInstance

      public static CachedFileMediator getSharedInstance()
      Gets the single shared instance of CachedFileMediator.
      Returns:
      single shared instance of CachedFileMediator
    • dispose

      public void dispose()
      Dispose the cache mediator and immediately evicts all holding files.
    • getFileOrLoad

      public <T> IFileEditor<T> getFileOrLoad(org.eclipse.core.resources.IFile file, org.eclipse.core.resources.IProject project, TranslateLanguage language)
      Gets the file editor from cache or creates it by provider and put to cache if not exist yet.
      Type Parameters:
      T - type of editing file data model
      Parameters:
      file - the file, cannot be null.
      project - the translating project, cannot be null.
      language - the language of the loading file, cannot be null.
      Returns:
      the file editor, can return null.
    • beginBatchUpdate

      public void beginBatchUpdate()
      This implementation will postpone writing data to the disk until batch update end.
    • endBatchUpdate

      public void endBatchUpdate()
      This implementation will start writing data to the disk right after last endUpdate() called.
    • runAutoSaveOnDemand

      public void runAutoSaveOnDemand()
      Start Job to save all storage files if auto-save enabled, not locked and not started yet.
    • save

      public byte[] save(org.eclipse.core.resources.IFile file, com.google.common.hash.HashFunction hashFunction)
      Saves a specified file using data being cached in this mediator (if any).
      Parameters:
      file - A file to save. May not be null
      Returns:
      hash of a file. May be null in case if data are empty
    • joinSave

      public void joinSave() throws InterruptedException
      Allows to join save job until it is done to write all modified files to disk.
      Throws:
      InterruptedException - the interrupted exception