All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.actuate.health.AppHealthIndicatorReactiveAdapter Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.actuate.health;

import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.util.Assert;

import reactor.core.publisher.Mono;
import reactor.core.publisher.MonoSink;
import reactor.core.scheduler.Schedulers;

public class AppHealthIndicatorReactiveAdapter implements AppReactiveHealthIndicator {

    private final HealthIndicator delegate;

    public AppHealthIndicatorReactiveAdapter(HealthIndicator delegate) {
        Assert.notNull(delegate, "Delegate must not be null");
        this.delegate = delegate;
    }

    @Override
    public Mono health() {
        return Mono.create((sink) -> Schedulers.elastic().schedule(() -> invoke(sink)));
    }

    private void invoke(MonoSink sink) {
        try {
            Health health = this.delegate.health();
            sink.success(health);
        } catch (Exception ex) {
            sink.error(ex);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy