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=6458dbbafdcad21fb05a61789727fedbd4d2a441;hpb=fb4bc7967a4733d10775351440a3af14327d5f20;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 6458dbba..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 getName() { - return this.name; + keepAlive(); } public synchronized Duration getKeepAliveInterval() { return this.keepAliveInterval; } - public 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() {