Add blueprint wiring to netconf-notification-impl
[netconf.git] / netconf / netconf-notifications-impl / src / main / java / org / opendaylight / controller / config / yang / netconf / northbound / notification / impl / NetconfNotificationManagerModule.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
9 package org.opendaylight.controller.config.yang.netconf.northbound.notification.impl;
10
11 import com.google.common.reflect.AbstractInvocationHandler;
12 import com.google.common.reflect.Reflection;
13 import java.lang.reflect.Method;
14 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
15 import org.opendaylight.netconf.notifications.NetconfNotificationCollector;
16 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry;
17 import org.osgi.framework.BundleContext;
18
19 /**
20  * @deprecated Replaced by blueprint wiring
21  */
22 @Deprecated
23 public class NetconfNotificationManagerModule extends AbstractNetconfNotificationManagerModule {
24
25     private BundleContext bundleContext;
26
27     public NetconfNotificationManagerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
28         super(identifier, dependencyResolver);
29     }
30
31     public NetconfNotificationManagerModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, org.opendaylight.controller.config.yang.netconf.northbound.notification.impl.NetconfNotificationManagerModule oldModule, java.lang.AutoCloseable oldInstance) {
32         super(identifier, dependencyResolver, oldModule, oldInstance);
33     }
34
35     @Override
36     public void customValidation() {
37         // add custom validation form module attributes here.
38     }
39
40     @Override
41     public java.lang.AutoCloseable createInstance() {
42
43         final WaitingServiceTracker<NetconfNotificationCollector> tracker =
44                 WaitingServiceTracker.create(NetconfNotificationCollector.class, bundleContext, "(type=netconf-notification-manager)");
45         final NetconfNotificationCollector service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
46
47         return Reflection.newProxy(AutoCloseableNetconfNotification.class, new AbstractInvocationHandler() {
48             @Override
49             protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
50                 if (method.getName().equals("close")) {
51                     tracker.close();
52                     return null;
53                 } else {
54                     return method.invoke(service, args);
55                 }
56             }
57         });
58     }
59
60     void setBundleContext(BundleContext bundleContext) {
61         this.bundleContext = bundleContext;
62     }
63
64     private static interface AutoCloseableNetconfNotification extends NetconfNotificationCollector, NetconfNotificationRegistry, AutoCloseable {
65     }
66
67 }