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.concepts.util.ListenerRegistry;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 public class BackwardsCompatibleMountPointManager implements MountProvisionService, MountProvisionListener {
26 private final ListenerRegistry<MountProvisionListener> listeners = ListenerRegistry.create();
27 private final ConcurrentMap<YangInstanceIdentifier, MountProvisionInstance> mounts = new ConcurrentHashMap<>();
29 private final DOMMountPointService domMountPointService;
31 public BackwardsCompatibleMountPointManager(final DOMMountPointService domMountPointService) {
32 this.domMountPointService = domMountPointService;
36 public MountProvisionInstance createMountPoint(final YangInstanceIdentifier path) {
37 checkState(!mounts.containsKey(path), "Mount already created");
38 // Create mount point instance, wrap instance of new API with BackwardsCompatibleMountPoint to preserve backwards comatibility
39 final BackwardsCompatibleMountPoint mount = new BackwardsCompatibleMountPoint(path, domMountPointService.createMountPoint(path));
40 mounts.put(path, mount);
44 public void notifyMountCreated(final YangInstanceIdentifier identifier) {
45 for (final ListenerRegistration<MountProvisionListener> listener : listeners.getListeners()) {
46 listener.getInstance().onMountPointCreated(identifier);
50 public void notifyMountRemoved(final YangInstanceIdentifier identifier) {
51 for (final ListenerRegistration<MountProvisionListener> listener : listeners.getListeners()) {
52 listener.getInstance().onMountPointRemoved(identifier);
57 public MountProvisionInstance createOrGetMountPoint(
58 final YangInstanceIdentifier path) {
59 final MountProvisionInstance mount = getMountPoint(path);
61 return createMountPoint(path);
67 public MountProvisionInstance getMountPoint(final YangInstanceIdentifier path) {
68 // If the mount point was created here, return directly
69 if(mounts.containsKey(path)) {
70 return mounts.get(path);
73 // If mount was created in underlying DOMMountService, wrap as MountProvisionInstance
74 final Optional<DOMMountPoint> mount = domMountPointService.getMountPoint(path);
75 if(mount.isPresent()) {
76 return new BackwardsCompatibleMountPoint(path, mount.get());
83 public ListenerRegistration<MountProvisionListener> registerProvisionListener(
84 final MountProvisionListener listener) {
85 return domMountPointService.registerProvisionListener(listener);
89 public void onMountPointCreated(final YangInstanceIdentifier path) {
90 notifyMountCreated(path);
94 public void onMountPointRemoved(final YangInstanceIdentifier path) {
95 notifyMountRemoved(path);