![JAR search and dependency download from the Maven repository](/logo.png)
de.otto.edison.status.indicator.CompositeStatusDetailIndicator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edison-status Show documentation
Show all versions of edison-status Show documentation
Status library of the edison-microservice project.
package de.otto.edison.status.indicator;
import de.otto.edison.status.domain.Status;
import de.otto.edison.status.domain.StatusDetail;
import java.util.Collection;
import java.util.List;
import static java.util.stream.Collectors.toList;
/**
* A StatusDetailIndicator that is a composite of multiple delegates.
*
* @author Guido Steinacker
* @since 04.09.15
*/
public class CompositeStatusDetailIndicator implements StatusDetailIndicator {
private final String name;
private final List delegates;
public CompositeStatusDetailIndicator(final String name,
final List delegates) {
this.name = name;
this.delegates = delegates;
if (delegates == null || delegates.isEmpty()) {
throw new IllegalArgumentException("CompositeStatusDetailIndicator " + name + " does not have any delegate indicators");
}
}
@Override
public StatusDetail statusDetail() {
if (delegates.size() == 1) {
return delegates.get(0).statusDetail();
} else {
return StatusDetail.statusDetail(
name,
delegates.stream()
.map(StatusDetailIndicator::statusDetails)
.flatMap(Collection::stream)
.map(StatusDetail::getStatus)
.reduce(Status.OK, Status::plus),
"Aggregated status of " + delegates.size() + " delegate indicators");
}
}
@Override
public List statusDetails() {
return delegates
.stream()
.map(StatusDetailIndicator::statusDetails)
.flatMap(Collection::stream)
.collect(toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy