in archaius2-core/src/main/java/com/netflix/archaius/DefaultPropertyFactory.java [239:267]
public Subscription subscribe(Consumer<T> consumer) {
Runnable action = new Runnable() {
private T current = get();
@Override
public synchronized void run() {
try {
T newValue = get();
if (current == newValue && current == null) {
return;
} else if (current == null) {
current = newValue;
} else if (newValue == null) {
current = null;
} else if (current.equals(newValue)) {
return;
} else {
current = newValue;
}
consumer.accept(current);
} catch (RuntimeException e) {
LOG.error("Unable to notify subscriber about update to property '{}'. Subscriber: {}",
keyAndType, consumer, e);
}
}
};
listeners.add(action);
return () -> listeners.remove(action);
}