From 8bc663722e745ac53a2fcd6d46febcd5ab541f81 Mon Sep 17 00:00:00 2001 From: kvosper Date: Mon, 17 Sep 2018 15:42:52 +0100 Subject: [PATCH] Move Announcer from API to Styx-Common module (#285) --- .../api/extension/service/spi/AbstractRegistry.java | 13 +++++++------ .../com/hotels/styx/api/extension/Announcer.java | 0 .../hotels/styx/api/extension/AnnouncerTest.java | 0 3 files changed, 7 insertions(+), 6 deletions(-) rename components/{api => common}/src/main/java/com/hotels/styx/api/extension/Announcer.java (100%) rename components/{api => common}/src/test/java/com/hotels/styx/api/extension/AnnouncerTest.java (100%) diff --git a/components/api/src/main/java/com/hotels/styx/api/extension/service/spi/AbstractRegistry.java b/components/api/src/main/java/com/hotels/styx/api/extension/service/spi/AbstractRegistry.java index 83a149252e..17029aacc2 100644 --- a/components/api/src/main/java/com/hotels/styx/api/extension/service/spi/AbstractRegistry.java +++ b/components/api/src/main/java/com/hotels/styx/api/extension/service/spi/AbstractRegistry.java @@ -17,13 +17,14 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.MapDifference; -import com.hotels.styx.api.extension.Announcer; import com.hotels.styx.api.Id; import com.hotels.styx.api.Identifiable; import org.slf4j.Logger; import java.util.Collection; +import java.util.List; import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Predicate; @@ -45,7 +46,7 @@ public abstract class AbstractRegistry implements Registry { private static final Logger LOG = getLogger(AbstractRegistry.class); - private final Announcer announcer = Announcer.to(ChangeListener.class); + private final List> listeners = new CopyOnWriteArrayList<>(); private final AtomicReference> snapshot = new AtomicReference<>(emptyList()); private final Predicate> resourceConstraint; @@ -72,13 +73,13 @@ public Iterable get() { } protected void notifyListeners(Changes changes) { - LOG.info("notifying about services={} to listeners={}", changes, announcer.listeners()); - announcer.announce().onChange(changes); + LOG.info("notifying about services={} to listeners={}", changes, listeners); + listeners.forEach(listener -> listener.onChange(changes)); } @Override public Registry addListener(ChangeListener changeListener) { - announcer.addListener(changeListener); + listeners.add(changeListener); changeListener.onChange(added(snapshot.get())); return this; } @@ -109,7 +110,7 @@ private Changes added(Iterable ch) { @Override public Registry removeListener(ChangeListener changeListener) { - announcer.removeListener(changeListener); + listeners.remove(changeListener); return this; } diff --git a/components/api/src/main/java/com/hotels/styx/api/extension/Announcer.java b/components/common/src/main/java/com/hotels/styx/api/extension/Announcer.java similarity index 100% rename from components/api/src/main/java/com/hotels/styx/api/extension/Announcer.java rename to components/common/src/main/java/com/hotels/styx/api/extension/Announcer.java diff --git a/components/api/src/test/java/com/hotels/styx/api/extension/AnnouncerTest.java b/components/common/src/test/java/com/hotels/styx/api/extension/AnnouncerTest.java similarity index 100% rename from components/api/src/test/java/com/hotels/styx/api/extension/AnnouncerTest.java rename to components/common/src/test/java/com/hotels/styx/api/extension/AnnouncerTest.java