-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Handled retry flow for guarnteed delivery of logs for MQTT
- Loading branch information
1 parent
36b2014
commit fa5426c
Showing
9 changed files
with
159 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
plog/src/main/java/com/blackbox/plog/pLogs/workers/RetryWithDelay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.blackbox.plog.pLogs.workers; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import io.reactivex.Observable; | ||
import io.reactivex.functions.Function; | ||
|
||
/** | ||
* Created by Umair Adil on 13/03/2017. | ||
*/ | ||
public class RetryWithDelay implements Function<Observable<? extends Throwable>, Observable<?>> { | ||
|
||
private final int maxRetries; | ||
private final int retryDelayMillis; | ||
private String TAG = "RetryWithDelay"; | ||
private int retryCount; | ||
|
||
public RetryWithDelay(final int maxRetries, final int retryDelayMillis) { | ||
this.maxRetries = maxRetries; | ||
this.retryDelayMillis = retryDelayMillis; | ||
this.retryCount = 0; | ||
} | ||
|
||
@Override | ||
public Observable<?> apply(final Observable<? extends Throwable> attempts) { | ||
return attempts | ||
.flatMap((Function<Throwable, Observable<?>>) throwable -> { | ||
|
||
if (++retryCount < maxRetries) { | ||
return Observable.timer(retryDelayMillis, | ||
TimeUnit.MILLISECONDS); | ||
} | ||
|
||
// Max retries hit. Just pass the error along. | ||
return Observable.error(throwable); | ||
}); | ||
} | ||
} |