Proxy MD-SAL interfaces in DOMMountPointServiceImpl
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / DOMNotificationServiceAdapter.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, 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.controller.sal.core.compat;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ForwardingObject;
13 import java.util.Arrays;
14 import java.util.Collection;
15 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
16 import org.opendaylight.mdsal.dom.api.DOMNotificationListener;
17 import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20
21 @Deprecated
22 public class DOMNotificationServiceAdapter extends ForwardingObject
23         implements org.opendaylight.mdsal.dom.api.DOMNotificationService {
24
25     private final DOMNotificationService delegate;
26
27     public DOMNotificationServiceAdapter(final DOMNotificationService delegate) {
28         this.delegate = requireNonNull(delegate);
29     }
30
31     @Override
32     public <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener,
33             final Collection<SchemaPath> types) {
34         // Controller events are sub-interfaces of MD-SAL events, hence direct routing is okay
35         final ListenerRegistration<?> reg = delegate().registerNotificationListener(listener::onNotification, types);
36
37         return new AbstractListenerRegistration<T>(listener) {
38             @Override
39             protected void removeRegistration() {
40                 reg.close();
41
42             }
43         };
44     }
45
46     @Override
47     public <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(final T listener,
48             final SchemaPath... types) {
49         return registerNotificationListener(listener, Arrays.asList(types));
50     }
51
52     @Override
53     protected DOMNotificationService delegate() {
54         return delegate;
55     }
56 }