Narrow Notification.implementedInterface() return type
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / SingleBindingDOMNotificationAdapter.java
1 /*
2  * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.binding.dom.adapter;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Set;
13 import java.util.concurrent.Executor;
14 import org.opendaylight.mdsal.binding.api.NotificationService.Listener;
15 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.Notification;
18 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
19
20 final class SingleBindingDOMNotificationAdapter<N extends Notification<N> & DataObject>
21         extends AbstractDOMNotificationListenerAdapter {
22     private final Listener<N> delegate;
23     private final Executor executor;
24     private final Class<N> type;
25
26     SingleBindingDOMNotificationAdapter(final AdapterContext adapterContext, final Class<N> type,
27             final Listener<N> delegate, final Executor executor) {
28         super(adapterContext);
29         this.type = requireNonNull(type);
30         this.delegate = requireNonNull(delegate);
31         this.executor = requireNonNull(executor);
32     }
33
34     @Override
35     void onNotification(final Absolute domType, final Notification notification) {
36         executor.execute(() -> delegate.onNotification(type.cast(notification)));
37     }
38
39     @Override
40     Set<Absolute> getSupportedNotifications() {
41         return Set.of(Absolute.of(BindingReflections.findQName(type)));
42     }
43 }