Package com.e1c.langtool.storage
Class CachedFileMediator
java.lang.Object
com.e1c.langtool.storage.CachedFileMediator
The cachable editing file mediator allows to load file if not exits in cache and save files form cache automatically
in separate job.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ConcurrentNavigableMap<String,IFileEditor<?>> List of evicted translation files.protected final com.google.common.cache.Cache<org.eclipse.core.resources.IFile,IFileEditor<?>> -
Constructor Summary
ConstructorsConstructorDescriptionCachedFileMediator(com.google.inject.Provider<ITranslationFileEditorFactory<?>> factoryProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoidThis implementation will postpone writing data to the disk until batch update end.voiddispose()Dispose the cache mediator and immediately evicts all holding files.voidThis implementation will start writing data to the disk right after lastendUpdate()called.<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.static CachedFileMediatorGets the single shared instance ofCachedFileMediator.voidjoinSave()Allows to join save job until it is done to write all modified files to disk.voidStart Job to save all storage files if auto-save enabled, not locked and not started yet.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).
-
Field Details
-
filesCache
protected final com.google.common.cache.Cache<org.eclipse.core.resources.IFile,IFileEditor<?>> filesCache -
evictedTranslationFiles
List of evicted translation files.
-
-
Constructor Details
-
CachedFileMediator
public CachedFileMediator(com.google.inject.Provider<ITranslationFileEditorFactory<?>> factoryProvider)
-
-
Method Details
-
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 benull.project- the translating project, cannot benull.language- the language of the loading file, cannot benull.- 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 lastendUpdate()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 benull- Returns:
- hash of a file. May be
nullin case if data are empty
-
joinSave
Allows to join save job until it is done to write all modified files to disk.- Throws:
InterruptedException- the interrupted exception