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=0316038265be758ae8b1bce006b5fd017185c55d;hp=6a26b98e5302ab97b5b730fa7712756bfce916e9;hpb=7adad623a64bfbb96b3c73ed7c1d0d49aabff659;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 6a26b98e..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 @@ -17,41 +17,46 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + 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; - // private final String callbackUrl1; // TBD + private final String callbackUrl; - public Service(String name, Duration keepAliveInterval) { + public Service(String name, Duration keepAliveInterval, String callbackUrl) { this.name = name; this.keepAliveInterval = keepAliveInterval; - ping(); - } - - public String getName() { - return this.name; + this.callbackUrl = callbackUrl; + keepAlive(); } - public Duration getKeepAliveInterval() { + 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() { return Duration.between(this.lastPing, Instant.now()); } + public synchronized String getCallbackUrl() { + return this.callbackUrl; + } + }