public class ThreadLocalCachedStorageAndLockingService extends Object implements UploadLockingService, UploadStorageService
UploadStorageService and UploadLockingService.
Uses both of them as delegates but allowing to reduce disk operations during a request processing
by caching UploadInfo in the memory.
UploadLockingService service is used as a delegate to cleanup cached data on releasing a lock.| Constructor and Description |
|---|
ThreadLocalCachedStorageAndLockingService(UploadStorageService storageServiceDelegate,
UploadLockingService lockingServiceDelegate) |
| Modifier and Type | Method and Description |
|---|---|
UploadInfo |
append(UploadInfo upload,
InputStream inputStream)
Append the bytes in the give
InputStream to the upload with the given ID starting at the provided offset. |
void |
cleanupExpiredUploads(UploadLockingService uploadLockingService)
Clean up any upload data that is expired according to the configured expiration time
|
void |
cleanupStaleLocks()
Clean up any stale locks that are still present
|
void |
copyUploadTo(UploadInfo info,
OutputStream outputStream)
Copy the uploaded bytes to the given output stream
|
UploadInfo |
create(UploadInfo info,
String ownerKey)
Create an upload location with the given upload information
|
long |
getMaxUploadSize()
Get the maximum upload size configured on this storage service
|
UploadConcatenationService |
getUploadConcatenationService()
Return the
UploadConcatenationService implementation that this upload service is using |
InputStream |
getUploadedBytes(String uploadURI,
String ownerKey)
Get the uploaded bytes corresponding to the given upload URL as a stream
|
InputStream |
getUploadedBytes(UploadId id)
Get the uploaded bytes corresponding to the given upload ID as a stream
|
Long |
getUploadExpirationPeriod()
Get the expiration period of an upload in milliseconds
|
UploadInfo |
getUploadInfo(String uploadUrl,
String ownerKey)
Method to retrieve the upload info by its upload URL
|
UploadInfo |
getUploadInfo(UploadId id)
Method to retrieve the upload info by its ID
|
String |
getUploadURI()
The URI which is configured as the upload endpoint
|
boolean |
isLocked(UploadId id)
Check if the upload with the given ID is currently locked
|
UploadLock |
lockUploadByUri(String requestURI)
If the given URI represents a valid upload, lock that upload for processing
|
void |
removeLastNumberOfBytes(UploadInfo uploadInfo,
long byteCount)
Remove the given last amount of bytes from the uploaded data
|
void |
setIdFactory(UploadIdFactory idFactory)
Set an instance if IdFactory to be used for creating identities and extracting them from uploadURIs
|
void |
setMaxUploadSize(Long maxUploadSize)
Limit the maximum upload size to the given value
|
void |
setUploadConcatenationService(UploadConcatenationService concatenationService)
Set the
UploadConcatenationService that this upload storage service should use |
void |
setUploadExpirationPeriod(Long uploadExpirationPeriod)
Set the expiration period after which an in-progress upload expires
|
void |
terminateUpload(UploadInfo uploadInfo)
Terminate completed and unfinished uploads allowing the Server to free up used resources.
|
void |
update(UploadInfo uploadInfo)
Update the upload information for the provided ID.
|
public ThreadLocalCachedStorageAndLockingService(UploadStorageService storageServiceDelegate, UploadLockingService lockingServiceDelegate)
public UploadInfo getUploadInfo(UploadId id) throws IOException
UploadStorageServicegetUploadInfo in interface UploadStorageServiceid - The ID of the uploadIOException - When the service is not able to retrieve the upload informationpublic UploadInfo getUploadInfo(String uploadUrl, String ownerKey) throws IOException
UploadStorageServicegetUploadInfo in interface UploadStorageServiceuploadUrl - The URL corresponding to this upload. This parameter can be null.ownerKey - A key representing the owner of the uploadIOExceptionpublic void update(UploadInfo uploadInfo) throws IOException, UploadNotFoundException
UploadStorageServiceupdate in interface UploadStorageServiceuploadInfo - The upload info object containing the ID and information to updateIOExceptionUploadNotFoundExceptionpublic void setIdFactory(UploadIdFactory idFactory)
UploadLockingServicesetIdFactory in interface UploadLockingServicesetIdFactory in interface UploadStorageServiceidFactory - The UploadIdFactory to use within this locking servicepublic String getUploadURI()
UploadStorageServicegetUploadURI in interface UploadStorageServicepublic UploadInfo append(UploadInfo upload, InputStream inputStream) throws IOException, TusException
UploadStorageServiceInputStream to the upload with the given ID starting at the provided offset.
This method also updates the UploadInfo corresponding to this upload. The Upload Storage server should
not exceed its max upload size when writing bytes.append in interface UploadStorageServiceupload - The ID of the uploadinputStream - The input stream containing the bytes to appendUploadInfo for this uploadIOExceptionTusExceptionpublic void setMaxUploadSize(Long maxUploadSize)
UploadStorageServicesetMaxUploadSize in interface UploadStorageServicemaxUploadSize - The maximum upload limit to setpublic long getMaxUploadSize()
UploadStorageServicegetMaxUploadSize in interface UploadStorageServicepublic UploadInfo create(UploadInfo info, String ownerKey) throws IOException
UploadStorageServicecreate in interface UploadStorageServiceinfo - The Upload information to use to create the new uploadownerKey - A key representing the owner of the uploadUploadInfo object containing the information used to create the upload and its unique IDIOExceptionpublic InputStream getUploadedBytes(String uploadURI, String ownerKey) throws IOException, UploadNotFoundException
UploadStorageServicegetUploadedBytes in interface UploadStorageServiceuploadURI - The URIownerKey - The owner key of this uploadOutputStream containing the bytes of the uploadIOExceptionUploadNotFoundExceptionpublic InputStream getUploadedBytes(UploadId id) throws IOException, UploadNotFoundException
UploadStorageServicegetUploadedBytes in interface UploadStorageServiceid - the ID of the uploadOutputStream containing the bytes of the uploadIOException - When retrieving the bytes from the storage layer failsUploadNotFoundException - When the proved id is not linked to an uploadpublic void copyUploadTo(UploadInfo info, OutputStream outputStream) throws UploadNotFoundException, IOException
UploadStorageServicecopyUploadTo in interface UploadStorageServiceinfo - The upload of which we should copy the bytesoutputStream - The output stream where we have to copy the bytes toUploadNotFoundExceptionIOExceptionpublic void cleanupExpiredUploads(UploadLockingService uploadLockingService) throws IOException
UploadStorageServicecleanupExpiredUploads in interface UploadStorageServiceuploadLockingService - An UploadLockingService that can be used to check and lock uploadsIOExceptionpublic void removeLastNumberOfBytes(UploadInfo uploadInfo, long byteCount) throws UploadNotFoundException, IOException
UploadStorageServiceremoveLastNumberOfBytes in interface UploadStorageServiceuploadInfo - Upload of which to remove the bytesbyteCount - The number of bytes to remove at the endUploadNotFoundExceptionIOExceptionpublic void terminateUpload(UploadInfo uploadInfo) throws UploadNotFoundException, IOException
UploadStorageServiceterminateUpload in interface UploadStorageServiceuploadInfo - The upload to terminateUploadNotFoundExceptionIOExceptionpublic Long getUploadExpirationPeriod()
UploadStorageServicegetUploadExpirationPeriod in interface UploadStorageServicepublic void setUploadExpirationPeriod(Long uploadExpirationPeriod)
UploadStorageServicesetUploadExpirationPeriod in interface UploadStorageServiceuploadExpirationPeriod - The period in millisecondspublic void setUploadConcatenationService(UploadConcatenationService concatenationService)
UploadStorageServiceUploadConcatenationService that this upload storage service should usesetUploadConcatenationService in interface UploadStorageServiceconcatenationService - The UploadConcatenationService implementation to usepublic UploadConcatenationService getUploadConcatenationService()
UploadStorageServiceUploadConcatenationService implementation that this upload service is usinggetUploadConcatenationService in interface UploadStorageServicepublic UploadLock lockUploadByUri(String requestURI) throws TusException, IOException
UploadLockingServicelockUploadByUri in interface UploadLockingServicerequestURI - The URI that potentially represents an uploadTusException - If the upload is already lockedIOExceptionpublic void cleanupStaleLocks()
throws IOException
UploadLockingServicecleanupStaleLocks in interface UploadLockingServiceIOExceptionpublic boolean isLocked(UploadId id)
UploadLockingServiceisLocked in interface UploadLockingServiceid - The ID of the upload to checkCopyright © 2019. All rights reserved.