aboutsummaryrefslogtreecommitdiffstats
path: root/service-monitor/src/main/java/com/yahoo/vespa/service/health/StateV1HealthMonitor.java
blob: 0d94f7198249656f7bd84afe91733ea004a765f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.service.health;

import com.yahoo.vespa.applicationmodel.ServiceStatusInfo;
import com.yahoo.vespa.service.executor.Cancellable;
import com.yahoo.vespa.service.executor.RunletExecutor;

import java.time.Duration;

/**
 * Used to monitor the health of a single URL endpoint.
 *
 * @author hakon
 */
class StateV1HealthMonitor implements HealthMonitor {

    private final StateV1HealthUpdater updater;
    private final Cancellable periodicExecution;

    StateV1HealthMonitor(StateV1HealthUpdater updater, RunletExecutor executor, Duration delay) {
        this.updater = updater;
        this.periodicExecution = executor.scheduleWithFixedDelay(updater, delay);
    }

    @Override
    public ServiceStatusInfo getStatus() {
        return updater.getServiceStatusInfo();
    }

    @Override
    public void close() {
        periodicExecution.cancel();
        updater.close();
    }

}