Add InstanceNotification(Publish)ServiceAdapter
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / KeyedInstanceNotificationListenerAdapter.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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 com.google.common.base.Verify.verify;
11
12 import java.util.concurrent.Executor;
13 import org.opendaylight.mdsal.binding.api.InstanceNotificationService.KeyedListListener;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.Identifiable;
16 import org.opendaylight.yangtools.yang.binding.Identifier;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
19 import org.opendaylight.yangtools.yang.binding.KeyedListNotification;
20
21 final class KeyedInstanceNotificationListenerAdapter<P extends DataObject & Identifiable<K>, K extends Identifier<P>,
22             N extends KeyedListNotification<N, P, K>>
23         extends AbstractInstanceNotificationListenerAdapter<P, N, KeyedListListener<P, N, K>> {
24     KeyedInstanceNotificationListenerAdapter(final AdapterContext adapterContext, final Class<N> notificationClass,
25             final KeyedListListener<P, N, K> delegate, final Executor executor) {
26         super(adapterContext, notificationClass, delegate, executor);
27     }
28
29     @Override
30     @SuppressWarnings("unchecked")
31     void onNotification(final KeyedListListener<P, N, K> delegate, final InstanceIdentifier<?> path,
32             final N notification) {
33         verify(path instanceof KeyedInstanceIdentifier, "Unexpected path %s", path);
34         delegate.onNotification((KeyedInstanceIdentifier<P, K>) path, notification);
35     }
36 }