Merge "Added STD sim 2.0.0 tests"
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / repository / Service.java
index 8efa542..7b2c9bd 100644 (file)
  * limitations under the License.
  * ========================LICENSE_END===================================
  */
+
 package org.oransc.policyagent.repository;
 
-public interface Service {
+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 callbackUrl;
+
+    public Service(String name, Duration keepAliveInterval, String callbackUrl) {
+        this.name = name;
+        this.keepAliveInterval = keepAliveInterval;
+        this.callbackUrl = callbackUrl;
+        keepAlive();
+    }
+
+    public synchronized Duration getKeepAliveInterval() {
+        return this.keepAliveInterval;
+    }
+
+    public synchronized void keepAlive() {
+        this.lastPing = Instant.now();
+    }
+
+    public synchronized boolean isExpired() {
+        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;
+    }
 
 }