0a7ead1061ebfa11474450472fc9f76e5f601b7e
[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.Notification;
17 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
18
19 final class SingleBindingDOMNotificationAdapter<N extends Notification> extends AbstractDOMNotificationListenerAdapter {
20     private final Listener<N> delegate;
21     private final Executor executor;
22     private final Class<N> type;
23
24     SingleBindingDOMNotificationAdapter(final AdapterContext adapterContext, final Class<N> type,
25             final Listener<N> delegate, final Executor executor) {
26         super(adapterContext);
27         this.type = requireNonNull(type);
28         this.delegate = requireNonNull(delegate);
29         this.executor = requireNonNull(executor);
30     }
31
32     @Override
33     void onNotification(final Absolute domType, final Notification notification) {
34         executor.execute(() -> delegate.onNotification(type.cast(notification)));
35     }
36
37     @Override
38     Set<Absolute> getSupportedNotifications() {
39         return Set.of(Absolute.of(BindingReflections.findQName(type)));
40     }
41 }