2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.md.sal.binding.compat;
10 import com.google.common.collect.ImmutableSet;
11 import java.util.HashMap;
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;
20 final class CompositeRoutedRpcRegistration<T extends RpcService> implements RoutedRpcRegistration<T> {
22 private final Class<T> type;
23 private final T instance;
24 private final BindingDOMRpcProviderServiceAdapter adapter;
25 private final Map<InstanceIdentifier<?>, ObjectRegistration<T>> registrations = new HashMap<>(2);
27 CompositeRoutedRpcRegistration(final Class<T> type, final T impl,
28 final BindingDOMRpcProviderServiceAdapter providerAdapter) {
31 this.adapter = providerAdapter;
35 public Class<T> getServiceType() {
40 public T getInstance() {
46 public void registerInstance(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> path) {
47 registerPath(context, path);
51 public synchronized void registerPath(final Class<? extends BaseIdentity> context,
52 final InstanceIdentifier<?> path) {
53 if (!registrations.containsKey(path)) {
54 registrations.put(path,
55 adapter.registerRpcImplementation(type, instance, ImmutableSet.<InstanceIdentifier<?>>of(path)));
62 public void unregisterInstance(final Class<? extends BaseIdentity> context, final InstanceIdentifier<?> path) {
63 unregisterPath(context, path);
67 public synchronized void unregisterPath(final Class<? extends BaseIdentity> context,
68 final InstanceIdentifier<?> path) {
69 final ObjectRegistration<T> reg = registrations.remove(path);
76 public synchronized void close() {
77 for (final ObjectRegistration<T> reg : registrations.values()) {