Merge "Bug 1003: Restconf - remove whitespace on input"
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / MountPointManagerImpl.java
1 /**
2  * Copyright (c) 2014 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.dom.broker;
9
10 import static com.google.common.base.Preconditions.checkState;
11
12 import java.util.concurrent.ConcurrentHashMap;
13 import java.util.concurrent.ConcurrentMap;
14
15 import org.opendaylight.controller.sal.core.api.data.DataProviderService;
16 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
17 import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
20 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
21
22 public class MountPointManagerImpl implements MountProvisionService {
23
24     private final ListenerRegistry<MountProvisionListener> listeners =
25             ListenerRegistry.create();
26     private final ConcurrentMap<InstanceIdentifier, MountPointImpl> mounts =
27             new ConcurrentHashMap<>();
28     private DataProviderService dataBroker = null;
29
30     @Override
31     public MountProvisionInstance createMountPoint(final InstanceIdentifier path) {
32         checkState(!mounts.containsKey(path), "Mount already created");
33         final MountPointImpl mount = new MountPointImpl(path);
34         registerMountPoint(mount);
35         mounts.put(path, mount);
36         notifyMountCreated(path);
37         return mount;
38     }
39
40     public void notifyMountCreated(final InstanceIdentifier identifier) {
41         for (final ListenerRegistration<MountProvisionListener> listener : listeners
42                 .getListeners()) {
43             listener.getInstance().onMountPointCreated(identifier);
44         }
45     }
46
47     public Object registerMountPoint(final MountPointImpl impl) {
48         // FIXME: Why is thie commented out? Either we need it or we don't
49         // dataBroker?.registerConfigurationReader(impl.mountPath,impl.readWrapper);
50         // dataBroker?.registerOperationalReader(impl.mountPath,impl.readWrapper);
51         return null;
52     }
53
54     @Override
55     public MountProvisionInstance createOrGetMountPoint(
56             final InstanceIdentifier path) {
57         final MountPointImpl mount = mounts.get(path);
58         if (mount == null) {
59             return createMountPoint(path);
60         }
61         return mount;
62     }
63
64     @Override
65     public MountProvisionInstance getMountPoint(final InstanceIdentifier path) {
66         return mounts.get(path);
67     }
68
69     /**
70      * @return the dataBroker
71      */
72     public DataProviderService getDataBroker() {
73         return dataBroker;
74     }
75
76     /**
77      * @param dataBroker
78      *            the dataBroker to set
79      */
80     public void setDataBroker(final DataProviderService dataBroker) {
81         this.dataBroker = dataBroker;
82     }
83
84     @Override
85     public ListenerRegistration<MountProvisionListener> registerProvisionListener(
86             final MountProvisionListener listener) {
87         return listeners.register(listener);
88     }
89 }