+ /**
+ * Swaps registered listeners and triggers notification update.
+ *
+ * @param newListeners listeners
+ */
+ private void replaceListeners(
+ final Multimap<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> newListeners) {
+ listeners = newListeners;
+ notifyListenerTypesChanged(newListeners.keySet());
+ }
+
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ private void notifyListenerTypesChanged(final Set<SchemaPath> typesAfter) {
+ final List<ListenerRegistration<DOMNotificationSubscriptionListener>> listenersAfter = ImmutableList
+ .copyOf(subscriptionListeners.getListeners());
+ executor.execute(() -> {
+ for (final ListenerRegistration<DOMNotificationSubscriptionListener> subListener : listenersAfter) {
+ try {
+ subListener.getInstance().onSubscriptionChanged(typesAfter);
+ } catch (final Exception e) {
+ LOG.warn("Uncaught exception during invoking listener {}", subListener.getInstance(), e);
+ }
+ }
+ });
+ }
+
+ @Override
+ public <L extends DOMNotificationSubscriptionListener> ListenerRegistration<L> registerSubscriptionListener(
+ final L listener) {
+ final Set<SchemaPath> initialTypes = listeners.keySet();
+ executor.execute(() -> listener.onSubscriptionChanged(initialTypes));
+ return subscriptionListeners.registerWithType(listener);
+ }
+
+ private ListenableFuture<Void> publish(final long seq, final DOMNotification notification,
+ final Collection<ListenerRegistration<? extends DOMNotificationListener>>
+ subscribers) {