Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / compat / CompositeRoutedRpcRegistration.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 package org.opendaylight.controller.md.sal.binding.compat;
9
10 import com.google.common.collect.ImmutableSet;
11 import java.util.HashMap;
12 import java.util.Map;
13 import org.opendaylight.controller.md.sal.binding.impl.BindingDOMRpcProviderServiceAdapter;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
15 import org.opendaylight.yangtools.concepts.ObjectRegistration;
16 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.opendaylight.yangtools.yang.binding.RpcService;
19
20 @Deprecated
21 final class CompositeRoutedRpcRegistration<T extends RpcService> implements RoutedRpcRegistration<T> {
22
23     private final Class<T> type;
24     private final T instance;
25     private final BindingDOMRpcProviderServiceAdapter adapter;
26     private final Map<InstanceIdentifier<?>, ObjectRegistration<T>> registrations = new HashMap<>(2);
27
28     CompositeRoutedRpcRegistration(final Class<T> type, final T impl,
29             final BindingDOMRpcProviderServiceAdapter providerAdapter) {
30         this.type = type;
31         this.instance = impl;
32         this.adapter = providerAdapter;
33     }
34
35     @Override
36     public Class<T> getServiceType() {
37         return type;
38     }
39
40     @Override
41     public T getInstance() {
42         return instance;
43     }
44
45     @Deprecated
46     @Override
47     public void registerInstance(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> path) {
48         registerPath(context, path);
49     }
50
51     @Override
52     public synchronized void registerPath(final Class<? extends BaseIdentity> context,
53             final InstanceIdentifier<?> path) {
54         if (!registrations.containsKey(path)) {
55             registrations.put(path,
56                     adapter.registerRpcImplementation(type, instance, ImmutableSet.<InstanceIdentifier<?>>of(path)));
57         }
58     }
59
60
61     @Override
62     @Deprecated
63     public void unregisterInstance(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> path) {
64         unregisterPath(context, path);
65     }
66
67     @Override
68     public synchronized  void unregisterPath(final Class<? extends BaseIdentity> context,
69             final InstanceIdentifier<?> path) {
70         final ObjectRegistration<T> reg = registrations.remove(path);
71         if (reg != null) {
72             reg.close();
73         }
74     }
75
76     @Override
77     public synchronized void close() {
78         for (final ObjectRegistration<T> reg : registrations.values()) {
79             reg.close();
80         }
81     }
82 }