From 65413bd91c49f2cce37d9c104ab881fd61793b4b Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Sun, 15 Sep 2024 11:07:38 -0700 Subject: [PATCH] Return singleton no-op Listener in createBypassListener --- .../limits/limiter/AbstractLimiter.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limiter/AbstractLimiter.java b/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limiter/AbstractLimiter.java index e4cb9e0..374a537 100644 --- a/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limiter/AbstractLimiter.java +++ b/concurrency-limits-core/src/main/java/com/netflix/concurrency/limits/limiter/AbstractLimiter.java @@ -30,6 +30,21 @@ public abstract class AbstractLimiter implements Limiter { public static final String ID_TAG = "id"; public static final String STATUS_TAG = "status"; + private static final Listener NOOP_LISTENER = new Listener() { + @Override + public void onSuccess() { + } + @Override + public void onIgnore() { + } + @Override + public void onDropped() { + } + @Override + public String toString() { + return "{NoopListener}"; + } + }; public abstract static class Builder> { private static final AtomicInteger idCounter = new AtomicInteger(); @@ -128,23 +143,7 @@ protected Optional createRejectedListener() { protected Optional createBypassListener() { this.bypassCounter.increment(); - return Optional.of(new Listener() { - - @Override - public void onSuccess() { - // Do nothing - } - - @Override - public void onIgnore() { - // Do nothing - } - - @Override - public void onDropped() { - // Do nothing - } - }); + return Optional.of(NOOP_LISTENER); } protected Listener createListener() {