io.helidon.microprofile.health.HealthCheckResponseImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helidon-microprofile-health Show documentation
Show all versions of helidon-microprofile-health Show documentation
Microprofile health check implementation
The newest version!
/*
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.microprofile.health;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.TreeMap;
import org.eclipse.microprofile.health.HealthCheckResponse;
/**
* An implementation of HealthCheckResponse, created and returned by HealthCheckResponseProviderImpl.
*/
class HealthCheckResponseImpl extends HealthCheckResponse {
private final String name;
private final Status status;
private final TreeMap data;
HealthCheckResponseImpl(String name, Status status, Map data) {
// Since this constructor is internally called, I'm harsh on accepted values
Objects.requireNonNull(name);
Objects.requireNonNull(status);
Objects.requireNonNull(data);
// I wrap the "data" map in a TreeMap for two reasons. First, I very much
// prefer JSON documents to be "stable" in their structure. A HashMap has random
// ordering of keys, which would lead to random ordering of key/value pairs in
// the resulting JSON document. Instead, TreeMap will sort by key's natural ordering,
// so I can have a stable JSON document.
//
// Second, I need to return a copy of the original
// map because a builder can (technically) be reused to stamp out additional instances
// and previously created instances should not be impacted if the source map was updated
// subsequent to the previous instances being created!
this.name = name;
this.status = status;
this.data = new TreeMap<>(data);
}
@Override
public String getName() {
return name;
}
@Override
public Status getStatus() {
return status;
}
@Override
public Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy