Bug 488: Removed requirement for DOM providers to supply BundleContext.
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / ProviderContextImpl.java
1 /*
2  * Copyright (c) 2014 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.controller.sal.dom.broker;
9
10 import java.util.HashSet;
11 import java.util.Set;
12
13 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
14 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
15 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
16 import org.opendaylight.controller.sal.core.api.Provider;
17 import org.opendaylight.controller.sal.core.api.RpcImplementation;
18 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
19 import org.opendaylight.yangtools.concepts.ListenerRegistration;
20 import org.opendaylight.yangtools.yang.common.QName;
21
22 class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession {
23     private final Set<RpcRegistrationWrapper> registrations = new HashSet<>();
24     private final Provider provider;
25
26     public ProviderContextImpl(final Provider provider, final BrokerImpl broker) {
27         super(null, broker);
28         this.provider = provider;
29     }
30
31     @Override
32     public RpcRegistrationWrapper addRpcImplementation(final QName rpcType,
33             final RpcImplementation implementation) throws IllegalArgumentException {
34         final RpcRegistration origReg = getBrokerChecked().getRouter()
35                 .addRpcImplementation(rpcType, implementation);
36         final RpcRegistrationWrapper newReg = new RpcRegistrationWrapper(
37                 origReg);
38         registrations.add(newReg);
39         return newReg;
40     }
41
42     protected boolean removeRpcImplementation(final RpcRegistrationWrapper implToRemove) {
43         return registrations.remove(implToRemove);
44     }
45
46     @Override
47     public void close() {
48         for (final RpcRegistrationWrapper reg : registrations) {
49             reg.close();
50         }
51     }
52
53     @Override
54     public RoutedRpcRegistration addMountedRpcImplementation(
55             final QName rpcType, final RpcImplementation implementation) {
56         throw new UnsupportedOperationException(
57                 "TODO: auto-generated method stub");
58
59     }
60
61     @Override
62     public RoutedRpcRegistration addRoutedRpcImplementation(
63             final QName rpcType, final RpcImplementation implementation) {
64         return getBrokerChecked().getRouter().addRoutedRpcImplementation(rpcType, implementation);
65     }
66
67     @Override
68     public Set<QName> getSupportedRpcs() {
69         return getBrokerChecked().getRouter().getSupportedRpcs();
70     }
71
72     @Override
73     public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(
74             final RpcRegistrationListener listener) {
75         return getBrokerChecked().getRouter().addRpcRegistrationListener(listener);
76     }
77
78     /**
79      * @return the provider
80      */
81     public Provider getProvider() {
82         return provider;
83     }
84
85     /**
86      * @param provider
87      *            the provider to set
88      */
89 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.