Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2d3e123 authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

feat: Implement java.lang.AutoClosable

parent 6d8ec2f4
Loading
Loading
Loading
Loading
+11 −3
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@ import java.security.InvalidParameterException;




/** The implementation of exponential backoff with jitter applied. */
/** The implementation of exponential backoff with jitter applied. */
public class ExponentialBackoff {
public class ExponentialBackoff implements AutoCloseable {


    private static final String TAG = ExponentialBackoff.class.getCanonicalName();
    private static final String TAG = ExponentialBackoff.class.getCanonicalName();


@@ -105,10 +105,18 @@ public class ExponentialBackoff {
    }
    }


    /** Stops the backoff, all pending messages will be removed from the message queue. */
    /** Stops the backoff, all pending messages will be removed from the message queue. */
    public void stop() {
    @Override
    public void close() {
        mRetryCounter = 0;
        mRetryCounter = 0;
        mHandlerAdapter.removeCallbacks(mRunnable);
        mHandlerAdapter.removeCallbacks(mRunnable);
    }


    /**
     * @deprecated Use {@link #close()}.
     */
    @Deprecated(forRemoval = true)
    public void stop() {
        close();
    }
    }


    /** Should call when the retry action has failed and we want to retry after a longer delay. */
    /** Should call when the retry action has failed and we want to retry after a longer delay. */
@@ -116,7 +124,7 @@ public class ExponentialBackoff {
        Log.d(TAG, "[notifyFailed] Error: [" + ex.getMessage() + "]");
        Log.d(TAG, "[notifyFailed] Error: [" + ex.getMessage() + "]");
        if(mRetryCounter > mMaxRetries) {
        if(mRetryCounter > mMaxRetries) {
            Log.d(TAG, "[notifyFailed] Retries exceeded, ending now");
            Log.d(TAG, "[notifyFailed] Retries exceeded, ending now");
            stop();
            close();
            mFailedCallback.run();
            mFailedCallback.run();
        } else {
        } else {
            mRetryCounter++;
            mRetryCounter++;