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 recordprivate static final recordstatic final recordstatic final recordstatic final recordprivate static final recordNested classes/interfaces inherited from interface ch.rswk.meta.engine.BackupService
BackupService.AbstractBackupDelegateNested 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.ErrorReplyFactoryprivate final Map<String, BackupService.AbstractBackupDelegate> private com.codahale.metrics.Counterprivate com.codahale.metrics.Timerprivate static final Protocol.ErrorReplyFactoryprivate com.codahale.metrics.Meterprivate static final Protocol.ErrorReplyFactoryprivate com.codahale.metrics.Meterprivate com.codahale.metrics.Meterprivate com.codahale.metrics.Timerprivate static final Stringprivate static final com.fasterxml.jackson.databind.ObjectReaderprivate static final Protocol.ErrorReplyFactoryprivate static final Protocol.ErrorReplyFactoryprivate static final org.slf4j.Loggerprivate com.codahale.metrics.Meterprivate final LuceneServiceprivate static final Stringprivate static final Protocol.ErrorReplyFactoryprivate com.codahale.metrics.Counterprivate com.codahale.metrics.Timerprivate static final Protocol.ErrorReplyFactoryprivate com.codahale.metrics.Meterprivate Pathprivate static final Protocol.ErrorReplyFactoryprivate static final Protocol.ErrorReplyFactoryprivate static final Durationprivate com.github.benmanes.caffeine.cache.Cache<String, FileService.PendingUpload> private com.codahale.metrics.Meterprivate com.codahale.metrics.Meterprivate final com.google.common.util.concurrent.Monitorprivate com.codahale.metrics.Meterprivate com.codahale.metrics.Timerprivate static final Protocol.ErrorReplyFactoryFields 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 voidcancelUpload(FileService.PendingUpload pendingUpload) private voidcleanupUpload(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 voidcom.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 PathgetStoragePath(String key) static PathgetStoragePath(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 FileInfonewFileInfo(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 voidshutDown()protected voidstartUp()com.google.common.util.concurrent.ListenableFuture<UploadReply> upload(UploadRequest request) voiduploadFilePart(byte[] filePart, String key) Upload parts of a file.Methods inherited from class ch.rswk.meta.engine.AbstractEngineIdleService
configClass, configReference, onConfigWatcherNotification, serviceId, serviceNameMethods inherited from class com.google.common.util.concurrent.AbstractIdleService
addListener, awaitRunning, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, awaitTerminated, executor, failureCause, isRunning, startAsync, state, stopAsync, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ch.rswk.meta.engine.EngineServices.ConfigurableService
config, handleConfigWatcherNotification, onConfigChangedMethods 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:
backupin 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:
backupRestorein 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:
getServiceInfoin interfaceEngineServices.InfoProvidingService
-
backupDelegateServiceNames
-
startUp
- Overrides:
startUpin classAbstractEngineIdleService<FileService.FileServiceConfig>- Throws:
Exception
-
registerBackupDelegate
public com.google.common.util.concurrent.ListenableFuture<Void> registerBackupDelegate(BackupService.AbstractBackupDelegate delegate) Description copied from interface:BackupServiceRegister delegate to handle backing up and restoring data to/from a file.- Specified by:
registerBackupDelegatein interfaceBackupService- Returns:
- future completes when registration is done
-
shutDown
- Overrides:
shutDownin 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.
-