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