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

internal.sdmxdl.ri.web.monitors.UpptimeSummary Maven / Gradle / Ivy

There is a newer version: 3.0.0-beta.13
Show newest version
package internal.sdmxdl.ri.web.monitors;

import com.google.gson.Gson;
import internal.util.http.HttpClient;
import internal.util.http.HttpResponse;
import internal.util.http.MediaType;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.io.IOException;
import java.io.Reader;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static internal.sdmxdl.ri.web.RiHttpUtils.newRequest;
import static sdmxdl.LanguagePriorityList.ANY;

@lombok.Data
class UpptimeSummary {

    String name;
    String status;
    String uptime;
    long time;

    static @NonNull List parseAll(@NonNull Reader reader) {
        return Arrays.asList(new Gson().fromJson(reader, UpptimeSummary[].class));
    }

    static @NonNull List request(@NonNull HttpClient client, @NonNull UpptimeId id) throws IOException {
        try (HttpResponse response = client.requestGET(newRequest(id.toSummaryURL(), MEDIA_TYPES, ANY))) {
            try (Reader reader = response.getBodyAsReader()) {
                return parseAll(reader);
            }
        }
    }

    private static final List MEDIA_TYPES = Collections.singletonList(MediaType.ANY_TYPE);

    static @NonNull UpptimeSummary of(String name, String status, String uptime, long time) {
        UpptimeSummary result = new UpptimeSummary();
        result.setName(name);
        result.setStatus(status);
        result.setUptime(uptime);
        result.setTime(time);
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy