Package io.tus.java.client
Class TusExecutor
java.lang.Object
io.tus.java.client.TusExecutor
TusExecutor is a wrapper class which you can build around your uploading mechanism and any
exception thrown by it will be caught and may result in a retry. This way you can easily add
retrying functionality to your application with defined delays between them.
This can be achieved by extending TusExecutor and implementing the abstract makeAttempt() method:
TusExecutor executor = new TusExecutor() {
{@literal @}Override
protected void makeAttempt() throws ProtocolException, IOException {
TusUploader uploader = client.resumeOrCreateUpload(upload);
while(uploader.uploadChunk() > -1) {}
uploader.finish();
}
};
executor.makeAttempts();
The retries are basically just calling the makeAttempt()
method which should then
retrieve an TusUploader
using TusClient.resumeOrCreateUpload(TusUpload)
and then
invoke TusUploader.uploadChunk()
as long as possible without catching
ProtocolException
s or IOException
s as this is taken over by this class.
The current attempt can be interrupted using Thread.interrupt()
which will cause the
makeAttempts()
method to return false
immediately.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint[]
Get the delays which will be used for waiting before attempting retries.protected abstract void
This method must be implemented by the specific caller.boolean
This method is basically just calling themakeAttempt()
method which should then retrieve anTusUploader
usingTusClient.resumeOrCreateUpload(TusUpload)
and then invokeTusUploader.uploadChunk()
as long as possible without catchingProtocolException
s orIOException
s as this is taken over by this class.void
setDelays
(int[] delays) Set the delays at which TusExecutor will issue a retry ifmakeAttempt()
throws an exception.
-
Constructor Details
-
TusExecutor
public TusExecutor()
-
-
Method Details
-
setDelays
public void setDelays(int[] delays) Set the delays at which TusExecutor will issue a retry ifmakeAttempt()
throws an exception. If the methods call fails for the first time it will waitdelays[0]
ms before calling it again. If this second calls also does not return normallydelays[1]
ms will be waited on so on. It totaldelays.length
retries may be issued, resulting in up todelays.length + 1
calls tomakeAttempt()
. The default delays are set to 500ms, 1s, 2s and 3s.- Parameters:
delays
- The desired delay values to be used- See Also:
-
getDelays
public int[] getDelays()Get the delays which will be used for waiting before attempting retries.- Returns:
- The dalys previously set
- See Also:
-
makeAttempts
This method is basically just calling themakeAttempt()
method which should then retrieve anTusUploader
usingTusClient.resumeOrCreateUpload(TusUpload)
and then invokeTusUploader.uploadChunk()
as long as possible without catchingProtocolException
s orIOException
s as this is taken over by this class. The current attempt can be interrupted usingThread.interrupt()
which will cause the method to returnfalse
immediately.- Returns:
true
if themakeAttempt()
method returned normally andfalse
if the thread was interrupted while sleeping until the next attempt.- Throws:
ProtocolException
IOException
-
makeAttempt
This method must be implemented by the specific caller. It will be invoked once or multiple times by themakeAttempts()
method. A proper implementation should retrieve anTusUploader
usingTusClient.resumeOrCreateUpload(TusUpload)
and then invokeTusUploader.uploadChunk()
as long as possible without catchingProtocolException
s orIOException
s as this is taken over by this class.- Throws:
ProtocolException
IOException
-