2 * Copyright (c) 2014 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.sal.dom.broker;
10 import static com.google.common.base.Preconditions.checkState;
12 import com.google.common.base.Optional;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.util.concurrent.ConcurrentMap;
15 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
16 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
17 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
18 import org.opendaylight.controller.sal.core.api.mount.MountProvisionListener;
19 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
20 import org.opendaylight.yangtools.concepts.ListenerRegistration;
21 import org.opendaylight.yangtools.util.ListenerRegistry;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 public class BackwardsCompatibleMountPointManager implements MountProvisionService, MountProvisionListener {
27 private final ListenerRegistry<MountProvisionListener> listeners = ListenerRegistry.create();
28 private final ConcurrentMap<YangInstanceIdentifier, MountProvisionInstance> mounts = new ConcurrentHashMap<>();
30 private final DOMMountPointService domMountPointService;
32 public BackwardsCompatibleMountPointManager(final DOMMountPointService domMountPointService) {
33 this.domMountPointService = domMountPointService;
37 public MountProvisionInstance createMountPoint(final YangInstanceIdentifier path) {
38 checkState(!mounts.containsKey(path), "Mount already created");
39 // Create mount point instance, wrap instance of new API with BackwardsCompatibleMountPoint to preserve backwards comatibility
40 final BackwardsCompatibleMountPoint mount = new BackwardsCompatibleMountPoint(path, domMountPointService.createMountPoint(path));
41 mounts.put(path, mount);
45 public void notifyMountCreated(final YangInstanceIdentifier identifier) {
46 for (final ListenerRegistration<MountProvisionListener> listener : listeners.getListeners()) {
47 listener.getInstance().onMountPointCreated(identifier);
51 public void notifyMountRemoved(final YangInstanceIdentifier identifier) {
52 for (final ListenerRegistration<MountProvisionListener> listener : listeners.getListeners()) {
53 listener.getInstance().onMountPointRemoved(identifier);
58 public MountProvisionInstance createOrGetMountPoint(
59 final YangInstanceIdentifier path) {
60 final MountProvisionInstance mount = getMountPoint(path);
62 return createMountPoint(path);
68 public MountProvisionInstance getMountPoint(final YangInstanceIdentifier path) {
69 // If the mount point was created here, return directly
70 if(mounts.containsKey(path)) {
71 return mounts.get(path);
74 // If mount was created in underlying DOMMountService, wrap as MountProvisionInstance
75 final Optional<DOMMountPoint> mount = domMountPointService.getMountPoint(path);
76 if(mount.isPresent()) {
77 return new BackwardsCompatibleMountPoint(path, mount.get());
84 public ListenerRegistration<MountProvisionListener> registerProvisionListener(
85 final MountProvisionListener listener) {
86 return domMountPointService.registerProvisionListener(listener);
90 public void onMountPointCreated(final YangInstanceIdentifier path) {
91 notifyMountCreated(path);
95 public void onMountPointRemoved(final YangInstanceIdentifier path) {
96 notifyMountRemoved(path);