/* * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.mdsal.binding.dom.adapter; import static java.util.Objects.requireNonNull; import com.google.common.collect.ClassToInstanceMap; import com.google.common.collect.ImmutableSet; import java.util.Set; import java.util.concurrent.Executor; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.mdsal.binding.api.InstanceNotificationService; import org.opendaylight.mdsal.binding.api.InstanceNotificationSpec; import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMAdapterBuilder.Factory; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier; import org.opendaylight.mdsal.dom.api.DOMInstanceNotificationListener; import org.opendaylight.mdsal.dom.api.DOMInstanceNotificationService; import org.opendaylight.mdsal.dom.api.DOMService; import org.opendaylight.yangtools.concepts.Registration; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.InstanceNotification; import org.opendaylight.yangtools.yang.binding.Key; import org.opendaylight.yangtools.yang.binding.KeyAware; import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; import org.opendaylight.yangtools.yang.binding.KeyedListNotification; final class InstanceNotificationServiceAdapter implements InstanceNotificationService { private static final class Builder extends BindingDOMAdapterBuilder { Builder(final AdapterContext adapterContext) { super(adapterContext); } @Override protected InstanceNotificationService createInstance(final ClassToInstanceMap delegates) { return new InstanceNotificationServiceAdapter(adapterContext(), delegates.getInstance(DOMInstanceNotificationService.class)); } @Override public Set> getRequiredDelegates() { return ImmutableSet.of(DOMInstanceNotificationService.class); } } static final Factory BUILDER_FACTORY = Builder::new; private final AdapterContext adapterContext; private final DOMInstanceNotificationService domNotifService; private InstanceNotificationServiceAdapter(final AdapterContext adapterContext, final DOMInstanceNotificationService domNotifService) { this.adapterContext = requireNonNull(adapterContext); this.domNotifService = requireNonNull(domNotifService); } @Override public

> Registration registerListener( final InstanceNotificationSpec spec, final InstanceIdentifier

path, final Listener listener, final Executor executor) { return registerListener(spec, path, new InstanceNotificationListenerAdapter<>(adapterContext, spec.type(), listener, executor)); } @Override public

, N extends KeyedListNotification, K extends Key

> Registration registerListener(final InstanceNotificationSpec spec, final KeyedInstanceIdentifier path, final KeyedListListener listener, final Executor executor) { return registerListener(spec, path, new KeyedInstanceNotificationListenerAdapter<>(adapterContext, spec.type(), listener, executor)); } private @NonNull Registration registerListener(final @NonNull InstanceNotificationSpec spec, final @NonNull InstanceIdentifier path, final @NonNull DOMInstanceNotificationListener listener) { final var serializer = adapterContext.currentSerializer(); return domNotifService.registerNotificationListener( new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, serializer.toYangInstanceIdentifier(path)), serializer.getNotificationPath(spec).lastNodeIdentifier(), listener); } }