
pl.allegro.tech.hermes.client.HermesClientTermination Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-client Show documentation
Show all versions of hermes-client Show documentation
Fast and reliable message broker built on top of Kafka.
package pl.allegro.tech.hermes.client;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BooleanSupplier;
class HermesClientTermination {
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
private final long pollInterval;
HermesClientTermination(long pollInterval) {
this.pollInterval = pollInterval;
}
CompletableFuture observe(BooleanSupplier condition) {
final CompletableFuture result = new CompletableFuture<>();
executorService.submit(
() -> {
try {
while (!condition.getAsBoolean()) {
Thread.sleep(pollInterval);
}
result.complete(null);
} catch (InterruptedException e) {
result.completeExceptionally(e);
Thread.currentThread().interrupt();
} finally {
executorService.shutdown();
}
});
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy