Package io.tus.java.client
Class TusExecutor
- java.lang.Object
-
- io.tus.java.client.TusExecutor
-
public abstract class TusExecutor extends java.lang.ObjectTusExecutor 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:
The retries are basically just calling theTusExecutor executor = new TusExecutor() { {@literal @}Override protected void makeAttempt() throws ProtocolException, IOException { TusUploader uploader = client.resumeOrCreateUpload(upload); while(uploader.uploadChunk() > -1) {} uploader.finish(); } }; executor.makeAttempts();makeAttempt()method which should then retrieve anTusUploaderusingTusClient.resumeOrCreateUpload(TusUpload)and then invokeTusUploader.uploadChunk()as long as possible without catchingProtocolExceptions orIOExceptions as this is taken over by this class. The current attempt can be interrupted usingThread.interrupt()which will cause themakeAttempts()method to returnfalseimmediately.
-
-
Constructor Summary
Constructors Constructor Description TusExecutor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int[]getDelays()Get the delays which will be used for waiting before attempting retries.protected abstract voidmakeAttempt()This method must be implemented by the specific caller.booleanmakeAttempts()This method is basically just calling themakeAttempt()method which should then retrieve anTusUploaderusingTusClient.resumeOrCreateUpload(TusUpload)and then invokeTusUploader.uploadChunk()as long as possible without catchingProtocolExceptions orIOExceptions as this is taken over by this class.voidsetDelays(int[] delays)Set the delays at which TusExecutor will issue a retry ifmakeAttempt()throws an exception.
-
-
-
Method Detail
-
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.lengthretries may be issued, resulting in up todelays.length + 1calls tomakeAttempt(). The default delays are set to 500ms, 1s, 2s and 3s.- Parameters:
delays- The desired delay values to be used- See Also:
getDelays()
-
getDelays
public int[] getDelays()
Get the delays which will be used for waiting before attempting retries.- Returns:
- The dalys previously set
- See Also:
setDelays(int[])
-
makeAttempts
public boolean makeAttempts() throws ProtocolException, java.io.IOExceptionThis method is basically just calling themakeAttempt()method which should then retrieve anTusUploaderusingTusClient.resumeOrCreateUpload(TusUpload)and then invokeTusUploader.uploadChunk()as long as possible without catchingProtocolExceptions orIOExceptions as this is taken over by this class. The current attempt can be interrupted usingThread.interrupt()which will cause the method to returnfalseimmediately.- Returns:
trueif themakeAttempt()method returned normally andfalseif the thread was interrupted while sleeping until the next attempt.- Throws:
ProtocolExceptionjava.io.IOException
-
makeAttempt
protected abstract void makeAttempt() throws ProtocolException, java.io.IOExceptionThis method must be implemented by the specific caller. It will be invoked once or multiple times by themakeAttempts()method. A proper implementation should retrieve anTusUploaderusingTusClient.resumeOrCreateUpload(TusUpload)and then invokeTusUploader.uploadChunk()as long as possible without catchingProtocolExceptions orIOExceptions as this is taken over by this class.- Throws:
ProtocolExceptionjava.io.IOException
-
-