Package ch.rswk.meta.engine
Class FileService
java.lang.Object
com.google.common.util.concurrent.AbstractIdleService
ch.rswk.meta.engine.AbstractEngineIdleService<FileService.FileServiceConfig>
ch.rswk.meta.engine.FileService
- All Implemented Interfaces:
BackupService
,EngineServices.ConfigurableService<FileService.FileServiceConfig>
,EngineServices.InfoProvidingService
,com.google.common.util.concurrent.Service
@Singleton
public class FileService
extends AbstractEngineIdleService<FileService.FileServiceConfig>
implements BackupService
FileService to upload, download, search and delete files. Provides backup and restore functionality to other meta services. Uses a
LuceneService
instance to store file meta data.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
private static final record
static final record
static final record
static final record
private static final record
Nested classes/interfaces inherited from interface ch.rswk.meta.engine.BackupService
BackupService.AbstractBackupDelegate
Nested classes/interfaces inherited from interface com.google.common.util.concurrent.Service
com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Protocol.ErrorReplyFactory
private final Map
<String, BackupService.AbstractBackupDelegate> private com.codahale.metrics.Counter
private com.codahale.metrics.Timer
private static final Protocol.ErrorReplyFactory
private com.codahale.metrics.Meter
private static final Protocol.ErrorReplyFactory
private com.codahale.metrics.Meter
private com.codahale.metrics.Meter
private com.codahale.metrics.Timer
private static final String
private static final com.fasterxml.jackson.databind.ObjectReader
private static final Protocol.ErrorReplyFactory
private static final Protocol.ErrorReplyFactory
private static final org.slf4j.Logger
private com.codahale.metrics.Meter
private final LuceneService
private static final String
private static final Protocol.ErrorReplyFactory
private com.codahale.metrics.Counter
private com.codahale.metrics.Timer
private static final Protocol.ErrorReplyFactory
private com.codahale.metrics.Meter
private Path
private static final Protocol.ErrorReplyFactory
private static final Protocol.ErrorReplyFactory
private static final Duration
private com.github.benmanes.caffeine.cache.Cache
<String, FileService.PendingUpload> private com.codahale.metrics.Meter
private com.codahale.metrics.Meter
private final com.google.common.util.concurrent.Monitor
private com.codahale.metrics.Meter
private com.codahale.metrics.Timer
private static final Protocol.ErrorReplyFactory
Fields inherited from class ch.rswk.meta.engine.AbstractEngineIdleService
runtime
-
Constructor Summary
ConstructorsConstructorDescriptionFileService
(FileService.FileServiceConfig config, LuceneService luceneService, EngineRuntime runtime) -
Method Summary
Modifier and TypeMethodDescriptioncom.google.common.util.concurrent.ListenableFuture
<BackupReply> backup
(BackupRequest request) com.google.common.util.concurrent.ListenableFuture
<BackupRestoreReply> backupRestore
(BackupRestoreRequest request) private void
cancelUpload
(FileService.PendingUpload pendingUpload) private void
cleanupUpload
(FileService.PendingUpload pendingUpload) private com.google.common.util.concurrent.ListenableFuture
<Void> completeUpload
(FileService.PendingUpload pendingUpload) private com.google.common.util.concurrent.ListenableFuture
<Long> createFileInfo
(FileInfo fileInfo) static com.google.common.util.concurrent.ListenableFuture
<Integer> createFileInfos
(@Nullable Iterable<FileInfo> fileInfos, FileService fileService) private void
com.google.common.util.concurrent.ListenableFuture
<DownloadReply> download
(Executor executor, DownloadRequest request, Function<ByteBuffer, com.google.common.util.concurrent.ListenableFuture<Void>> sink) com.google.common.util.concurrent.ListenableFuture
<FileDeleteReply> fileDelete
(FileDeleteRequest request) com.google.common.util.concurrent.ListenableFuture
<FileSearchReply> fileSearch
(FileSearchRequest request) private com.google.common.util.concurrent.ListenableFuture
<FileSearchReply> fileSearchInternal
(FileSearchRequest request) static com.google.common.util.concurrent.ListenableFuture
<Void> fileSearchRecursive
(Executor executor, Function<FileSearchReply, com.google.common.util.concurrent.ListenableFuture<?>> replyConsumer, FileSearchRequest request, Function<FileSearchRequest, com.google.common.util.concurrent.ListenableFuture<FileSearchReply>> service) Optional
<com.fasterxml.jackson.databind.node.ObjectNode> private Path
getStoragePath
(String key) static Path
getStoragePath
(String key, Path storageDir) com.google.common.util.concurrent.ListenableFuture
<FileService.LocalDownload> localDownload
(DownloadRequest request) com.google.common.util.concurrent.ListenableFuture
<UploadReply> private com.google.common.util.concurrent.ListenableFuture
<Optional<FileService.FileLookup>> lookupFileInfo
(boolean checkFileExists, String key) private static FileInfo
newFileInfo
(String key, UploadRequest request) private com.google.common.util.concurrent.ListenableFuture
<Void> processUpload
(String channel, FileInfo fileInfo) com.google.common.util.concurrent.ListenableFuture
<Void> Register delegate to handle backing up and restoring data to/from a file.protected void
shutDown()
protected void
startUp()
com.google.common.util.concurrent.ListenableFuture
<UploadReply> upload
(UploadRequest request) void
uploadFilePart
(byte[] filePart, String key) Upload parts of a file.Methods inherited from class ch.rswk.meta.engine.AbstractEngineIdleService
configClass, configReference, onConfigWatcherNotification, serviceId, serviceName
Methods inherited from class com.google.common.util.concurrent.AbstractIdleService
addListener, awaitRunning, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, startAsync, state, stopAsync, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.rswk.meta.engine.EngineServices.ConfigurableService
config, handleConfigWatcherNotification, onConfigChanged
Methods inherited from interface com.google.common.util.concurrent.Service
addListener, awaitRunning, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, awaitTerminated, failureCause, isRunning, startAsync, state, stopAsync
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG -
BACKUP_ERROR
-
DELETE_ERROR
-
DOWNLOAD_ERROR
-
EXISTING_HASH_QUERY_FORMAT
- See Also:
-
FILE_INFO_READER
private static final com.fasterxml.jackson.databind.ObjectReader FILE_INFO_READER -
FILE_NOT_EXIST_ERROR
-
INVALID_UPLOAD_ERROR
-
PROGRESS_FILE_SUFFIX
- See Also:
-
RESTORE_ERROR
-
SEARCH_ERROR
-
UNKNOWN_SERVICE_ERROR
-
UPLOAD_ERROR
-
UPLOAD_EXPIRATION
-
WRITE_ERROR
-
backupDelegates
-
luceneService
-
uploadKeyByHash
-
uploadKeyByHashMonitor
private final com.google.common.util.concurrent.Monitor uploadKeyByHashMonitor -
backupErrorCounter
private com.codahale.metrics.Counter backupErrorCounter -
backupTimer
private com.codahale.metrics.Timer backupTimer -
deleteMeter
private com.codahale.metrics.Meter deleteMeter -
downloadErrorMeter
private com.codahale.metrics.Meter downloadErrorMeter -
downloadPartMeter
private com.codahale.metrics.Meter downloadPartMeter -
downloadTimer
private com.codahale.metrics.Timer downloadTimer -
lookupErrorMeter
private com.codahale.metrics.Meter lookupErrorMeter -
restoreErrorCounter
private com.codahale.metrics.Counter restoreErrorCounter -
restoreTimer
private com.codahale.metrics.Timer restoreTimer -
searchMeter
private com.codahale.metrics.Meter searchMeter -
storageDir
-
uploadCache
-
uploadDuplicateMeter
private com.codahale.metrics.Meter uploadDuplicateMeter -
uploadErrorMeter
private com.codahale.metrics.Meter uploadErrorMeter -
uploadPartMeter
private com.codahale.metrics.Meter uploadPartMeter -
uploadTimer
private com.codahale.metrics.Timer uploadTimer
-
-
Constructor Details
-
FileService
@Inject public FileService(FileService.FileServiceConfig config, @Named("File") LuceneService luceneService, EngineRuntime runtime)
-
-
Method Details
-
backup
public com.google.common.util.concurrent.ListenableFuture<BackupReply> backup(BackupRequest request) - Specified by:
backup
in interfaceBackupService
-
localUpload
public com.google.common.util.concurrent.ListenableFuture<UploadReply> localUpload(FileService.LocalUploadRequest request) -
upload
public com.google.common.util.concurrent.ListenableFuture<UploadReply> upload(UploadRequest request) -
fileSearchInternal
private com.google.common.util.concurrent.ListenableFuture<FileSearchReply> fileSearchInternal(FileSearchRequest request) -
completeUpload
private com.google.common.util.concurrent.ListenableFuture<Void> completeUpload(FileService.PendingUpload pendingUpload) throws IOException - Throws:
IOException
-
cleanupUpload
-
getStoragePath
-
getStoragePath
-
newFileInfo
-
processUpload
-
createFileInfo
-
backupRestore
public com.google.common.util.concurrent.ListenableFuture<BackupRestoreReply> backupRestore(BackupRestoreRequest request) - Specified by:
backupRestore
in interfaceBackupService
-
localDownload
public com.google.common.util.concurrent.ListenableFuture<FileService.LocalDownload> localDownload(DownloadRequest request) -
lookupFileInfo
private com.google.common.util.concurrent.ListenableFuture<Optional<FileService.FileLookup>> lookupFileInfo(boolean checkFileExists, String key) -
createFileInfos
public static com.google.common.util.concurrent.ListenableFuture<Integer> createFileInfos(@Nullable Iterable<FileInfo> fileInfos, FileService fileService) -
download
public com.google.common.util.concurrent.ListenableFuture<DownloadReply> download(Executor executor, DownloadRequest request, Function<ByteBuffer, com.google.common.util.concurrent.ListenableFuture<Void>> sink) -
fileSearch
public com.google.common.util.concurrent.ListenableFuture<FileSearchReply> fileSearch(FileSearchRequest request) -
fileSearchRecursive
public static com.google.common.util.concurrent.ListenableFuture<Void> fileSearchRecursive(Executor executor, Function<FileSearchReply, com.google.common.util.concurrent.ListenableFuture<?>> replyConsumer, FileSearchRequest request, Function<FileSearchRequest, com.google.common.util.concurrent.ListenableFuture<FileSearchReply>> service) -
getServiceInfo
- Specified by:
getServiceInfo
in interfaceEngineServices.InfoProvidingService
-
backupDelegateServiceNames
-
startUp
- Overrides:
startUp
in classAbstractEngineIdleService<FileService.FileServiceConfig>
- Throws:
Exception
-
registerBackupDelegate
public com.google.common.util.concurrent.ListenableFuture<Void> registerBackupDelegate(BackupService.AbstractBackupDelegate delegate) Description copied from interface:BackupService
Register delegate to handle backing up and restoring data to/from a file.- Specified by:
registerBackupDelegate
in interfaceBackupService
- Returns:
- future completes when registration is done
-
shutDown
- Overrides:
shutDown
in classAbstractEngineIdleService<FileService.FileServiceConfig>
- Throws:
Exception
-
cancelUpload
-
deleteExpiredFiles
private void deleteExpiredFiles() -
fileDelete
public com.google.common.util.concurrent.ListenableFuture<FileDeleteReply> fileDelete(FileDeleteRequest request) -
uploadFilePart
Upload parts of a file. Can be called 1-n times to provide chunks of arbitrary length (but in correct order) of the files content.
-