Package com.spotify.dns
Class ChangeNotifiers
- java.lang.Object
-
- com.spotify.dns.ChangeNotifiers
-
public final class ChangeNotifiers extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> ChangeNotifier<T>aggregate(ChangeNotifier<T>... notifiers)Creates aChangeNotifierthat aggregates the records provided by a list of notifiers.static <T> ChangeNotifier<T>aggregate(Iterable<ChangeNotifier<T>> notifiers)static <T> ChangeNotifierFactory.RunnableChangeNotifier<T>direct(com.google.common.base.Supplier<Set<T>> recordsSupplier)Deprecated.Usedirect(java.util.function.Supplier)deprecated since version 3.2.0static <T> ChangeNotifierFactory.RunnableChangeNotifier<T>direct(AtomicReference<Set<T>> recordsHolder)static <T> ChangeNotifierFactory.RunnableChangeNotifier<T>direct(Supplier<Set<T>> recordsSupplier)Create aChangeNotifierFactory.RunnableChangeNotifierthat directly wraps a set of records given by aSupplier.static <T> booleanisInitialEmptyData(Set<T> set)Use this to determine if the data you get back from a notifier is the initial result of the result of a proper DNS lookup.static <T> ChangeNotifier<T>staticRecords(Set<T> records)static <T> ChangeNotifier<T>staticRecords(T... records)Create aChangeNotifierwith a static set of records.
-
-
-
Method Detail
-
isInitialEmptyData
public static <T> boolean isInitialEmptyData(Set<T> set)
Use this to determine if the data you get back from a notifier is the initial result of the result of a proper DNS lookup. This is useful for distinguishing a proper but empty DNS result from the case where a lookup has not completed yet.- Parameters:
set-- Returns:
- true if the input is an initially empty set.
-
aggregate
public static <T> ChangeNotifier<T> aggregate(ChangeNotifier<T>... notifiers)
Creates aChangeNotifierthat aggregates the records provided by a list of notifiers.A change event on any of the input notifiers will propagate up the the returned notifier. The set of previous and current records contained in the event will be the union of all records in the input notifiers, before and after the change event.
- Type Parameters:
T- The record type- Parameters:
notifiers- A list of notifiers to aggregate- Returns:
- A notifier with the described behaviour
-
aggregate
public static <T> ChangeNotifier<T> aggregate(Iterable<ChangeNotifier<T>> notifiers)
-
staticRecords
public static <T> ChangeNotifier<T> staticRecords(T... records)
Create aChangeNotifierwith a static set of records.This notifier will never generate any change events. Thus any attached
ChangeNotifier.Listenerwill at most get one initial call toChangeNotifier.Listener.onChange(ChangeNotifier.ChangeNotification)if they are attached with thefireargument set totrue.- Type Parameters:
T- The record type- Parameters:
records- The records that the notifier will contain- Returns:
- A notifier with a static set of records
-
staticRecords
public static <T> ChangeNotifier<T> staticRecords(Set<T> records)
-
direct
public static <T> ChangeNotifierFactory.RunnableChangeNotifier<T> direct(Supplier<Set<T>> recordsSupplier)
Create aChangeNotifierFactory.RunnableChangeNotifierthat directly wraps a set of records given by aSupplier.Each call to
Runnable.run()will cause the supplier to be polled and regular change notifications to be triggered.This implementation is useful for testing components that depend on a
ChangeNotifier.- Type Parameters:
T- The record type- Parameters:
recordsSupplier- The supplier of records- Returns:
- A runnable notifier
-
direct
public static <T> ChangeNotifierFactory.RunnableChangeNotifier<T> direct(com.google.common.base.Supplier<Set<T>> recordsSupplier)
Deprecated.Usedirect(java.util.function.Supplier)deprecated since version 3.2.0
-
direct
public static <T> ChangeNotifierFactory.RunnableChangeNotifier<T> direct(AtomicReference<Set<T>> recordsHolder)
-
-