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=7b2c9bdec6c3d91df281221f485bd11397b16dbf;hb=ae4206bbd7437adda91fc429efef03a13da2b702;hp=18a85a9143d66a3b9dbfdc1c09464fa0a3f11ab0;hpb=c3ed1a5199e3f5f539cc813b9a383dd156fed2e2;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 18a85a91..7b2c9bde 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 @@ -23,7 +23,10 @@ package org.oransc.policyagent.repository; import java.time.Duration; import java.time.Instant; +import lombok.Getter; + public class Service { + @Getter private final String name; private final Duration keepAliveInterval; private Instant lastPing; @@ -33,23 +36,19 @@ public class Service { this.name = name; this.keepAliveInterval = keepAliveInterval; this.callbackUrl = callbackUrl; - ping(); - } - - public synchronized String name() { - return this.name; + keepAlive(); } public synchronized Duration getKeepAliveInterval() { return this.keepAliveInterval; } - private synchronized void ping() { + public synchronized void keepAlive() { this.lastPing = Instant.now(); } public synchronized boolean isExpired() { - return timeSinceLastPing().compareTo(this.keepAliveInterval) > 0; + return this.keepAliveInterval.getSeconds() > 0 && timeSinceLastPing().compareTo(this.keepAliveInterval) > 0; } public synchronized Duration timeSinceLastPing() {