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

org.zodiac.actuate.context.ApplicationRefreshScopeHealthIndicator Maven / Gradle / Ivy

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

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health.Builder;
import org.zodiac.core.context.properties.AppConfigurationPropertiesRebinder;
import org.zodiac.core.context.scope.refresh.AppRefreshScope;

public class ApplicationRefreshScopeHealthIndicator extends AbstractHealthIndicator {

    private ObjectProvider scope;

    private AppConfigurationPropertiesRebinder rebinder;

    public ApplicationRefreshScopeHealthIndicator(ObjectProvider scope,
        AppConfigurationPropertiesRebinder rebinder) {
        this.scope = scope;
        this.rebinder = rebinder;
    }

    @Override
    protected void doHealthCheck(Builder builder) throws Exception {
        AppRefreshScope refreshScope = this.scope.getIfAvailable();
        if (refreshScope != null) {
            Map errors = new HashMap<>(refreshScope.getErrors());
            errors.putAll(this.rebinder.getErrors());
            if (errors.isEmpty()) {
                builder.up();
            } else {
                builder.down();
                if (errors.size() == 1) {
                    builder.withException(errors.values().iterator().next());
                } else {
                    for (String name : errors.keySet()) {
                        builder.withDetail(name, errors.get(name));
                    }
                }
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy