Merge "Added STD sim 2.0.0 tests"
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / repository / Service.java
index 18a85a9..7b2c9bd 100644 (file)
@@ -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() {