* 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;
+ this.callbackUrl = callbackUrl;
ping();
}
- public String getName() {
- return this.name;
- }
-
- public Duration getKeepAliveInterval() {
+ public synchronized Duration getKeepAliveInterval() {
return this.keepAliveInterval;
}
}
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;
+ }
+
}