From 32cee7f8b70dac66e8193fa36bdafe66c45ab30c Mon Sep 17 00:00:00 2001 From: Jonathan Lennox Date: Fri, 1 Mar 2024 11:30:55 -0500 Subject: [PATCH 1/3] Run health checks on the I/O pool. --- .../org/jitsi/jicofo/bridge/JvbDoctor.java | 54 +++++++++++++++---- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java b/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java index 80bbffc972..42ed57db00 100644 --- a/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java +++ b/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java @@ -61,7 +61,7 @@ public class JvbDoctor /** * Health check tasks map. */ - private final Map> tasks = new ConcurrentHashMap<>(); + private final Map tasks = new ConcurrentHashMap<>(); private final HealthCheckListener listener; @@ -95,7 +95,7 @@ synchronized public void shutdown() @Override public void bridgeRemoved(Bridge bridge) { - ScheduledFuture healthTask = tasks.remove(bridge); + PeriodicHealthCheckTask healthTask = tasks.remove(bridge); if (healthTask == null) { logger.warn("Trying to remove a bridge that does not exist anymore: " + bridge); @@ -104,7 +104,7 @@ public void bridgeRemoved(Bridge bridge) logger.info("Stopping health-check task for: " + bridge); - healthTask.cancel(true); + healthTask.cancel(); } @Override @@ -120,14 +120,10 @@ public void bridgeAdded(Bridge bridge) ? new HealthCheckPresenceTask(bridge) : new HealthCheckTask(bridge); - ScheduledFuture healthTask - = TaskPools.getScheduledPool().scheduleAtFixedRate( - task, - healthCheckInterval, - healthCheckInterval, - TimeUnit.MILLISECONDS); + PeriodicHealthCheckTask periodicTask + = new PeriodicHealthCheckTask(task, healthCheckInterval); - tasks.put(bridge, healthTask); + tasks.put(bridge, periodicTask); logger.info("Scheduled health-check task for: " + bridge); } @@ -137,6 +133,44 @@ public void bridgeIsShuttingDown(@NotNull Bridge bridge) { } + private static class PeriodicHealthCheckTask implements Runnable + { + private Runnable innerTask; + + private final ScheduledFuture future; + private Future innerFuture; + private final Object lock = new Object(); + + private PeriodicHealthCheckTask(Runnable task, long healthCheckInterval) + { + innerTask = task; + future = TaskPools.getScheduledPool().scheduleAtFixedRate( + this, + healthCheckInterval, + healthCheckInterval, + TimeUnit.MILLISECONDS); + } + + @Override + public void run() + { + innerFuture = TaskPools.getIoPool().submit(innerTaskRunnable); + } + + private final Runnable innerTaskRunnable = () -> { + synchronized (lock) { + innerTask.run(); + } + }; + + private void cancel() { + future.cancel(true); + if (innerFuture != null) { + innerFuture.cancel(true); + } + } + } + private class HealthCheckTask extends AbstractHealthCheckTask { private HealthCheckTask(Bridge bridge) From 70531e79388ef99f929c4b64a4ef2c26b2f31690 Mon Sep 17 00:00:00 2001 From: Jonathan Lennox Date: Fri, 1 Mar 2024 11:35:59 -0500 Subject: [PATCH 2/3] Squash: Use has-a rather than is-a. --- .../main/java/org/jitsi/jicofo/bridge/JvbDoctor.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java b/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java index 42ed57db00..3bd95f2302 100644 --- a/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java +++ b/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java @@ -133,7 +133,7 @@ public void bridgeIsShuttingDown(@NotNull Bridge bridge) { } - private static class PeriodicHealthCheckTask implements Runnable + private static class PeriodicHealthCheckTask { private Runnable innerTask; @@ -145,19 +145,13 @@ private PeriodicHealthCheckTask(Runnable task, long healthCheckInterval) { innerTask = task; future = TaskPools.getScheduledPool().scheduleAtFixedRate( - this, + () -> innerFuture = TaskPools.getIoPool().submit(runInner), healthCheckInterval, healthCheckInterval, TimeUnit.MILLISECONDS); } - @Override - public void run() - { - innerFuture = TaskPools.getIoPool().submit(innerTaskRunnable); - } - - private final Runnable innerTaskRunnable = () -> { + private final Runnable runInner = () -> { synchronized (lock) { innerTask.run(); } From fbb555f806bf24d98adb240ff661bdc0c1b8f8ea Mon Sep 17 00:00:00 2001 From: Jonathan Lennox Date: Fri, 1 Mar 2024 11:48:53 -0500 Subject: [PATCH 3/3] Checkstyle fixes. --- .../src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java b/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java index 3bd95f2302..f66808d32a 100644 --- a/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java +++ b/jicofo-selector/src/main/java/org/jitsi/jicofo/bridge/JvbDoctor.java @@ -152,14 +152,17 @@ private PeriodicHealthCheckTask(Runnable task, long healthCheckInterval) } private final Runnable runInner = () -> { - synchronized (lock) { + synchronized (lock) + { innerTask.run(); } }; - private void cancel() { + private void cancel() + { future.cancel(true); - if (innerFuture != null) { + if (innerFuture != null) + { innerFuture.cancel(true); } }