X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Frepository%2FService.java;h=512d065ba5e4d48bc0ff339808025e165f6028f4;hb=ffe0c150f08205d73ee362f58f492aeb2703f295;hp=8efa54292e86f85ece352ca3f8ed8345b1f3e4a5;hpb=4a7dd457d5b179dd0f588663fc1476dacfca4f22;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java b/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java index 8efa5429..512d065b 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/repository/Service.java @@ -17,8 +17,42 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.repository; -public interface Service { +import java.time.Duration; +import java.time.Instant; + +public class Service { + private final String name; + private final Duration keepAliveInterval; + private Instant lastPing; + // private final String callbackUrl1; // TBD + + public Service(String name, Duration keepAliveInterval) { + this.name = name; + this.keepAliveInterval = keepAliveInterval; + ping(); + } + + public String getName() { + return this.name; + } + + public Duration getKeepAliveInterval() { + return this.keepAliveInterval; + } + + public synchronized void ping() { + this.lastPing = Instant.now(); + } + + public synchronized boolean isExpired() { + return timeSinceLastPing().compareTo(this.keepAliveInterval) > 0; + } + + public synchronized Duration timeSinceLastPing() { + return Duration.between(this.lastPing, Instant.now()); + } }