BUG-620: replace xtend version of classes with Java versions
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / sal / dom / broker / MountPointManagerImpl.java
diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.java
new file mode 100644 (file)
index 0000000..55a6ee7
--- /dev/null
@@ -0,0 +1,89 @@
+/**
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.sal.dom.broker;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.opendaylight.controller.sal.core.api.data.DataProviderService;
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.util.ListenerRegistry;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+
+public class MountPointManagerImpl implements MountProvisionService {
+
+    private final ListenerRegistry<MountProvisionListener> listeners =
+            ListenerRegistry.create();
+    private final ConcurrentMap<InstanceIdentifier, MountPointImpl> mounts =
+            new ConcurrentHashMap<>();
+    private DataProviderService dataBroker = null;
+
+    @Override
+    public MountProvisionInstance createMountPoint(final InstanceIdentifier path) {
+        checkState(!mounts.containsKey(path), "Mount already created");
+        final MountPointImpl mount = new MountPointImpl(path);
+        registerMountPoint(mount);
+        mounts.put(path, mount);
+        notifyMountCreated(path);
+        return mount;
+    }
+
+    public void notifyMountCreated(final InstanceIdentifier identifier) {
+        for (final ListenerRegistration<MountProvisionListener> listener : listeners
+                .getListeners()) {
+            listener.getInstance().onMountPointCreated(identifier);
+        }
+    }
+
+    public Object registerMountPoint(final MountPointImpl impl) {
+        // FIXME: Why is thie commented out? Either we need it or we don't
+        // dataBroker?.registerConfigurationReader(impl.mountPath,impl.readWrapper);
+        // dataBroker?.registerOperationalReader(impl.mountPath,impl.readWrapper);
+        return null;
+    }
+
+    @Override
+    public MountProvisionInstance createOrGetMountPoint(
+            final InstanceIdentifier path) {
+        final MountPointImpl mount = mounts.get(path);
+        if (mount == null) {
+            return createMountPoint(path);
+        }
+        return mount;
+    }
+
+    @Override
+    public MountProvisionInstance getMountPoint(final InstanceIdentifier path) {
+        return mounts.get(path);
+    }
+
+    /**
+     * @return the dataBroker
+     */
+    public DataProviderService getDataBroker() {
+        return dataBroker;
+    }
+
+    /**
+     * @param dataBroker
+     *            the dataBroker to set
+     */
+    public void setDataBroker(final DataProviderService dataBroker) {
+        this.dataBroker = dataBroker;
+    }
+
+    @Override
+    public ListenerRegistration<MountProvisionListener> registerProvisionListener(
+            final MountProvisionListener listener) {
+        return listeners.register(listener);
+    }
+}