Updated implementation of internal RPC Router for Binding-Aware Broker and added...
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / impl / OsgiProviderContext.xtend
1 /*
2  * Copyright (c) 2013 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.binding.impl;
9
10 import java.util.HashMap;
11 import java.util.Hashtable;
12 import java.util.Map;
13
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
15 import org.opendaylight.yangtools.yang.binding.RpcService;
16 import org.osgi.framework.BundleContext;
17
18 import static org.opendaylight.controller.sal.binding.impl.osgi.Constants.*;
19 import static extension org.opendaylight.controller.sal.binding.impl.osgi.PropertiesUtils.*;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
22 import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality
23 import static com.google.common.base.Preconditions.*
24
25 class OsgiProviderContext extends OsgiConsumerContext implements ProviderContext {
26
27     @Property
28     val Map<Class<? extends RpcService>, RpcRegistration<? extends RpcService>> registeredServices
29
30     new(BundleContext ctx, BindingAwareBrokerImpl broker) {
31         super(ctx, broker);
32         _registeredServices = new HashMap();
33     }
34
35     override <T extends RpcService> addRpcImplementation(Class<T> type, T implementation) {
36
37         // TODO Auto-generated method stub
38         val properties = new Hashtable<String, String>();
39         properties.salServiceType = SAL_SERVICE_TYPE_PROVIDER
40
41         // Fill requirements
42         val salReg = broker.registerRpcImplementation(type, implementation, this, properties)
43         registeredServices.put(type, salReg)
44         return salReg;
45     }
46
47     override <T extends RpcService> addMountRpcImplementation(Class<T> type, InstanceIdentifier<?> mount, T implementation) throws IllegalStateException {
48         checkNotNull(type, "Service type should not be null")
49         checkNotNull(mount,"Path to the mount should not be null")
50         checkNotNull(implementation, "Service instance should not be null")
51
52         val properties = new Hashtable<String, String>();
53         properties.salServiceType = SAL_SERVICE_TYPE_PROVIDER
54
55         // Fill requirements
56         val salReg = broker.registerMountedRpcImplementation(type, implementation, mount, this)
57         registeredServices.put(type, salReg)
58         return salReg;
59     }
60
61     override <T extends RpcService> addRoutedRpcImplementation(Class<T> type, T implementation) throws IllegalStateException {
62         checkNotNull(type, "Service type should not be null")
63         checkNotNull(implementation, "Service type should not be null")
64         
65         val salReg = broker.registerRoutedRpcImplementation(type, implementation, this)
66         registeredServices.put(type, salReg)
67         return salReg;
68     }
69
70     override registerFunctionality(ProviderFunctionality functionality) {
71         // NOOP for now
72     }
73
74     override unregisterFunctionality(ProviderFunctionality functionality) {
75         // NOOP for now
76     }
77 }