e641ed10397ef215d182f78d465853c37ebf2ff4
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / ProviderContextImpl.xtend
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 org.opendaylight.controller.sal.core.api.Broker.ProviderSession
11 import org.opendaylight.controller.sal.core.api.Provider
12 import org.opendaylight.controller.sal.core.api.RpcImplementation
13 import org.opendaylight.yangtools.yang.common.QName
14 import org.osgi.framework.BundleContext
15 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration
16 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener
17 import org.opendaylight.yangtools.concepts.Registration
18
19 import java.util.Set
20 import java.util.HashSet
21
22 class ProviderContextImpl extends ConsumerContextImpl implements ProviderSession {
23
24     @Property
25     private val Provider provider;
26
27     private val Set<Registration<?>> registrations = new HashSet();
28
29     new(Provider provider, BundleContext ctx) {
30         super(null, ctx);
31         this._provider = provider;
32     }
33
34     override addRpcImplementation(QName rpcType, RpcImplementation implementation) throws IllegalArgumentException {
35         val origReg = broker.router.addRpcImplementation(rpcType, implementation);
36         val newReg = new RpcRegistrationWrapper(origReg);
37         registrations.add(newReg);
38         return newReg;
39     }
40
41     protected def removeRpcImplementation(RpcRegistrationWrapper implToRemove) throws IllegalArgumentException {
42         registrations.remove(implToRemove);
43     }
44     
45     override close() {
46         
47         for (reg : registrations) {
48             reg.close()
49         }
50         super.close
51     }
52
53     override addMountedRpcImplementation(QName rpcType, RpcImplementation implementation) {
54         throw new UnsupportedOperationException("TODO: auto-generated method stub")
55     }
56
57     override addRoutedRpcImplementation(QName rpcType, RpcImplementation implementation) {
58         throw new UnsupportedOperationException("TODO: auto-generated method stub")
59     }
60
61     override getSupportedRpcs() {
62         broker.router.supportedRpcs;
63     }
64
65     override addRpcRegistrationListener(RpcRegistrationListener listener) {
66         broker.router.addRpcRegistrationListener(listener);
67     }
68 }
69
70 class RpcRegistrationWrapper implements RpcRegistration {
71
72
73     @Property
74     val RpcRegistration delegate
75
76     new(RpcRegistration delegate) {
77         _delegate = delegate
78     }
79
80     override getInstance() {
81         delegate.instance
82     }
83
84     override close() {
85         delegate.close
86     }
87
88     override getType() {
89         delegate.type
90     }
91 }
92