Merge "Bug 1029: Remove dead code: sal-schema-repository-api"
[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 import org.osgi.framework.BundleContext;
22
23 class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession {
24     private final Set<RpcRegistrationWrapper> registrations = new HashSet<>();
25     private final Provider provider;
26
27     public ProviderContextImpl(final Provider provider, final BundleContext ctx) {
28         super(null, ctx);
29         this.provider = provider;
30     }
31
32     @Override
33     public RpcRegistrationWrapper addRpcImplementation(final QName rpcType,
34             final RpcImplementation implementation) throws IllegalArgumentException {
35         final RpcRegistration origReg = getBroker().getRouter()
36                 .addRpcImplementation(rpcType, implementation);
37         final RpcRegistrationWrapper newReg = new RpcRegistrationWrapper(
38                 origReg);
39         registrations.add(newReg);
40         return newReg;
41     }
42
43     protected boolean removeRpcImplementation(final RpcRegistrationWrapper implToRemove) {
44         return registrations.remove(implToRemove);
45     }
46
47     @Override
48     public void close() {
49         for (final RpcRegistrationWrapper reg : registrations) {
50             reg.close();
51         }
52     }
53
54     @Override
55     public RoutedRpcRegistration addMountedRpcImplementation(
56             final QName rpcType, final RpcImplementation implementation) {
57         throw new UnsupportedOperationException(
58                 "TODO: auto-generated method stub");
59     }
60
61     @Override
62     public RoutedRpcRegistration addRoutedRpcImplementation(
63             final QName rpcType, final RpcImplementation implementation) {
64         throw new UnsupportedOperationException(
65                 "TODO: auto-generated method stub");
66     }
67
68     @Override
69     public Set<QName> getSupportedRpcs() {
70         return getBroker().getRouter().getSupportedRpcs();
71     }
72
73     @Override
74     public ListenerRegistration<RpcRegistrationListener> addRpcRegistrationListener(
75             final RpcRegistrationListener listener) {
76         return getBroker().getRouter().addRpcRegistrationListener(listener);
77     }
78
79     /**
80      * @return the provider
81      */
82     public Provider getProvider() {
83         return provider;
84     }
85
86     /**
87      * @param provider
88      *            the provider to set
89      */
90 }