Class ThreadLocalCachedStorageAndLockingService
java.lang.Object
me.desair.tus.server.upload.cache.ThreadLocalCachedStorageAndLockingService
- All Implemented Interfaces:
- UploadLockingService,- UploadStorageService
public class ThreadLocalCachedStorageAndLockingService
extends Object
implements UploadLockingService, UploadStorageService
Combined implementation of 
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 SummaryConstructorsConstructorDescriptionThreadLocalCachedStorageAndLockingService(UploadStorageService storageServiceDelegate, UploadLockingService lockingServiceDelegate) Constructor of ThreadLocalCachedStorageAndLockingService.
- 
Method SummaryModifier and TypeMethodDescriptionappend(UploadInfo upload, InputStream inputStream) Append the bytes in the giveInputStreamto the upload with the given ID starting at the provided offset.voidcleanupExpiredUploads(UploadLockingService uploadLockingService) Clean up any upload data that is expired according to the configured expiration time.voidClean up any stale locks that are still present.voidcopyUploadTo(UploadInfo info, OutputStream outputStream) Copy the uploaded bytes to the given output stream.create(UploadInfo info, String ownerKey) Create an upload location with the given upload information.longGet the maximum upload size configured on this storage service.Return theUploadConcatenationServiceimplementation that this upload service is using.getUploadedBytes(String uploadUri, String ownerKey) Get the uploaded bytes corresponding to the given upload URL as a stream.Get the uploaded bytes corresponding to the given upload ID as a stream.Get the expiration period of an upload in milliseconds.getUploadInfo(String uploadUrl, String ownerKey) Method to retrieve the upload info by its upload URL.Method to retrieve the upload info by its ID.The URI which is configured as the upload endpoint.booleanCheck if the upload with the given ID is currently locked.lockUploadByUri(String requestUri) If the given URI represents a valid upload, lock that upload for processing.voidremoveLastNumberOfBytes(UploadInfo uploadInfo, long byteCount) Remove the given last amount of bytes from the uploaded data.voidsetIdFactory(UploadIdFactory idFactory) Set an instance if IdFactory to be used for creating identities and extracting them from uploadUris.voidsetMaxUploadSize(Long maxUploadSize) Limit the maximum upload size to the given value.voidsetUploadConcatenationService(UploadConcatenationService concatenationService) Set theUploadConcatenationServicethat this upload storage service should use.voidsetUploadExpirationPeriod(Long uploadExpirationPeriod) Set the expiration period after which an in-progress upload expires.voidterminateUpload(UploadInfo uploadInfo) Terminate completed and unfinished uploads allowing the Server to free up used resources.voidupdate(UploadInfo uploadInfo) Update the upload information for the provided ID.
- 
Constructor Details- 
ThreadLocalCachedStorageAndLockingServicepublic ThreadLocalCachedStorageAndLockingService(UploadStorageService storageServiceDelegate, UploadLockingService lockingServiceDelegate) Constructor of ThreadLocalCachedStorageAndLockingService.
 
- 
- 
Method Details- 
getUploadInfoDescription copied from interface:UploadStorageServiceMethod to retrieve the upload info by its ID.- Specified by:
- getUploadInfoin interface- UploadStorageService
- Parameters:
- id- The ID of the upload
- Returns:
- The matching upload info
- Throws:
- IOException- When the service is not able to retrieve the upload information
 
- 
getUploadInfoDescription copied from interface:UploadStorageServiceMethod to retrieve the upload info by its upload URL.- Specified by:
- getUploadInfoin interface- UploadStorageService
- Parameters:
- uploadUrl- The URL corresponding to this upload. This parameter can be null.
- ownerKey- A key representing the owner of the upload
- Returns:
- The upload info matching the given URL, or null when not found.
- Throws:
- IOException
 
- 
updateDescription copied from interface:UploadStorageServiceUpdate the upload information for the provided ID.- Specified by:
- updatein interface- UploadStorageService
- Parameters:
- uploadInfo- The upload info object containing the ID and information to update
- Throws:
- IOException
- UploadNotFoundException
 
- 
setIdFactoryDescription copied from interface:UploadLockingServiceSet an instance if IdFactory to be used for creating identities and extracting them from uploadUris.- Specified by:
- setIdFactoryin interface- UploadLockingService
- Specified by:
- setIdFactoryin interface- UploadStorageService
- Parameters:
- idFactory- The- UploadIdFactoryto use within this locking service
 
- 
getUploadUriDescription copied from interface:UploadStorageServiceThe URI which is configured as the upload endpoint.- Specified by:
- getUploadUriin interface- UploadStorageService
- Returns:
- The URI
 
- 
appendpublic UploadInfo append(UploadInfo upload, InputStream inputStream) throws IOException, TusException Description copied from interface:UploadStorageServiceAppend the bytes in the giveInputStreamto the upload with the given ID starting at the provided offset. This method also updates theUploadInfocorresponding to this upload. The Upload Storage server should not exceed its max upload size when writing bytes.- Specified by:
- appendin interface- UploadStorageService
- Parameters:
- upload- The ID of the upload
- inputStream- The input stream containing the bytes to append
- Returns:
- The new UploadInfofor this upload
- Throws:
- IOException
- TusException
 
- 
setMaxUploadSizeDescription copied from interface:UploadStorageServiceLimit the maximum upload size to the given value.- Specified by:
- setMaxUploadSizein interface- UploadStorageService
- Parameters:
- maxUploadSize- The maximum upload limit to set
 
- 
getMaxUploadSizepublic long getMaxUploadSize()Description copied from interface:UploadStorageServiceGet the maximum upload size configured on this storage service.- Specified by:
- getMaxUploadSizein interface- UploadStorageService
- Returns:
- The maximum upload size or zero if no maximum
 
- 
createDescription copied from interface:UploadStorageServiceCreate an upload location with the given upload information.- Specified by:
- createin interface- UploadStorageService
- Parameters:
- info- The Upload information to use to create the new upload
- ownerKey- A key representing the owner of the upload
- Returns:
- An UploadInfoobject containing the information used to create the upload and its unique ID
- Throws:
- IOException
 
- 
getUploadedBytespublic InputStream getUploadedBytes(String uploadUri, String ownerKey) throws IOException, UploadNotFoundException Description copied from interface:UploadStorageServiceGet the uploaded bytes corresponding to the given upload URL as a stream.- Specified by:
- getUploadedBytesin interface- UploadStorageService
- Parameters:
- uploadUri- The URI
- ownerKey- The owner key of this upload
- Returns:
- an OutputStreamcontaining the bytes of the upload
- Throws:
- IOException
- UploadNotFoundException
 
- 
getUploadedBytesDescription copied from interface:UploadStorageServiceGet the uploaded bytes corresponding to the given upload ID as a stream.- Specified by:
- getUploadedBytesin interface- UploadStorageService
- Parameters:
- id- the ID of the upload
- Returns:
- an OutputStreamcontaining the bytes of the upload
- Throws:
- IOException- When retrieving the bytes from the storage layer fails
- UploadNotFoundException- When the proved id is not linked to an upload
 
- 
copyUploadTopublic void copyUploadTo(UploadInfo info, OutputStream outputStream) throws UploadNotFoundException, IOException Description copied from interface:UploadStorageServiceCopy the uploaded bytes to the given output stream.- Specified by:
- copyUploadToin interface- UploadStorageService
- Parameters:
- info- The upload of which we should copy the bytes
- outputStream- The output stream where we have to copy the bytes to
- Throws:
- UploadNotFoundException
- IOException
 
- 
cleanupExpiredUploadsDescription copied from interface:UploadStorageServiceClean up any upload data that is expired according to the configured expiration time.- Specified by:
- cleanupExpiredUploadsin interface- UploadStorageService
- Parameters:
- uploadLockingService- An- UploadLockingServicethat can be used to check and lock uploads
- Throws:
- IOException
 
- 
removeLastNumberOfBytespublic void removeLastNumberOfBytes(UploadInfo uploadInfo, long byteCount) throws UploadNotFoundException, IOException Description copied from interface:UploadStorageServiceRemove the given last amount of bytes from the uploaded data.- Specified by:
- removeLastNumberOfBytesin interface- UploadStorageService
- Parameters:
- uploadInfo- Upload of which to remove the bytes
- byteCount- The number of bytes to remove at the end
- Throws:
- UploadNotFoundException
- IOException
 
- 
terminateUploadDescription copied from interface:UploadStorageServiceTerminate completed and unfinished uploads allowing the Server to free up used resources.- Specified by:
- terminateUploadin interface- UploadStorageService
- Parameters:
- uploadInfo- The upload to terminate
- Throws:
- UploadNotFoundException
- IOException
 
- 
getUploadExpirationPeriodDescription copied from interface:UploadStorageServiceGet the expiration period of an upload in milliseconds.- Specified by:
- getUploadExpirationPeriodin interface- UploadStorageService
- Returns:
- The number of milliseconds before an upload expires, or null if it cannot expire
 
- 
setUploadExpirationPeriodDescription copied from interface:UploadStorageServiceSet the expiration period after which an in-progress upload expires.- Specified by:
- setUploadExpirationPeriodin interface- UploadStorageService
- Parameters:
- uploadExpirationPeriod- The period in milliseconds
 
- 
setUploadConcatenationServiceDescription copied from interface:UploadStorageServiceSet theUploadConcatenationServicethat this upload storage service should use.- Specified by:
- setUploadConcatenationServicein interface- UploadStorageService
- Parameters:
- concatenationService- The UploadConcatenationService implementation to use
 
- 
getUploadConcatenationServiceDescription copied from interface:UploadStorageServiceReturn theUploadConcatenationServiceimplementation that this upload service is using.- Specified by:
- getUploadConcatenationServicein interface- UploadStorageService
- Returns:
- The UploadConcatenationService that is being used
 
- 
lockUploadByUriDescription copied from interface:UploadLockingServiceIf the given URI represents a valid upload, lock that upload for processing.- Specified by:
- lockUploadByUriin interface- UploadLockingService
- Parameters:
- requestUri- The URI that potentially represents an upload
- Returns:
- The lock on the upload, or null if not lock was applied
- Throws:
- TusException- If the upload is already locked
- IOException
 
- 
cleanupStaleLocksDescription copied from interface:UploadLockingServiceClean up any stale locks that are still present.- Specified by:
- cleanupStaleLocksin interface- UploadLockingService
- Throws:
- IOException- When cleaning a stale lock fails
 
- 
isLockedDescription copied from interface:UploadLockingServiceCheck if the upload with the given ID is currently locked.- Specified by:
- isLockedin interface- UploadLockingService
- Parameters:
- id- The ID of the upload to check
- Returns:
- True if the upload is locked, false otherwise
 
 
-