diff options
Diffstat (limited to 'feature-distributed-locking/src/main')
2 files changed, 35 insertions, 4 deletions
diff --git a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java index cc7a7a12..3d19c873 100644 --- a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java +++ b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/DistributedLockingFeature.java @@ -65,9 +65,12 @@ public class DistributedLockingFeature implements PolicyEngineFeatureAPI, Policy */ private static final UUID uuid = UUID.randomUUID(); + /** - * Config directory + * Reference to Heartbeat */ + private static Heartbeat heartbeat = null; + @Override public int getSequenceNumber() { return 1000; @@ -116,7 +119,7 @@ public class DistributedLockingFeature implements PolicyEngineFeatureAPI, Policy long heartbeatInterval = this.lockProps.getHeartBeatIntervalProperty(); cleanLockTable(); - Heartbeat heartbeat = new Heartbeat(this.uuid, lockProps); + heartbeat = new Heartbeat(this.uuid, lockProps); this.scheduledExecutorService = Executors.newScheduledThreadPool(1); this.scheduledExecutorService.scheduleAtFixedRate(heartbeat, heartbeatInterval, heartbeatInterval, TimeUnit.MILLISECONDS); @@ -154,5 +157,9 @@ public class DistributedLockingFeature implements PolicyEngineFeatureAPI, Policy } } + + public static Heartbeat getHeartbeat() { + return heartbeat; + } } diff --git a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/Heartbeat.java b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/Heartbeat.java index c753dba9..edd0782e 100644 --- a/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/Heartbeat.java +++ b/feature-distributed-locking/src/main/java/org/onap/policy/distributed/locking/Heartbeat.java @@ -24,10 +24,9 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; -import java.util.Properties; import java.util.UUID; +import java.util.concurrent.CountDownLatch; -import org.onap.policy.drools.utils.NetworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,14 +51,34 @@ public class Heartbeat implements Runnable{ */ private UUID uuid; + /** + * Countdown latch for testing + */ + private volatile CountDownLatch latch; + + /** + * + * @param uuid + * @param lockProps + */ public Heartbeat(UUID uuid, DistributedLockingProperties lockProps) { this.lockProps = lockProps; this.uuid = uuid; + this.latch = new CountDownLatch(1); + } + /** + * + * @param latch + * Used for testing purposes + */ + protected void giveLatch(CountDownLatch latch) { + this.latch = latch; } @Override public void run() { + long expirationAge = lockProps.getAgingProperty(); try (Connection conn = DriverManager.getConnection(lockProps.getDbUrl(), lockProps.getDbUser(), @@ -70,9 +89,14 @@ public class Heartbeat implements Runnable{ statement.setLong(1, System.currentTimeMillis() + expirationAge); statement.setString(2, this.uuid.toString()); statement.executeUpdate(); + + latch.countDown(); + } catch (SQLException e) { logger.error("error in Heartbeat.run()", e); } } + + } |