Last active
November 15, 2019 08:02
-
-
Save kungfoo/497c3981462c798c382c04d81fae5f02 to your computer and use it in GitHub Desktop.
Taking up to n results with time based eviction
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
package io.beekeeper.sample; | |
import java.util.concurrent.TimeUnit; | |
import com.codahale.metrics.health.HealthCheck.Result; | |
import io.reactivex.Observable; | |
import io.reactivex.schedulers.Schedulers; | |
import io.reactivex.subjects.ReplaySubject; | |
import io.reactivex.subjects.Subject; | |
class Blub { | |
private final Subject<Result> lastResults = ReplaySubject.createWithTime(5, TimeUnit.MINUTES, | |
Schedulers.computation()); | |
public Observable<Result> lastResults(int n) { | |
return lastResults.takeLast(n); | |
} | |
public Observable<Result> lastFailures(int n) { | |
return lastResults | |
.filter(result -> !result.isHealthy()) | |
.takeLast(n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment